Skip to content

Commit a33f898

Browse files
Update README.md
1 parent fa9748d commit a33f898

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

README.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -435,20 +435,26 @@ In order to normalise the data, we need to scale it between 0 and 1 so we talk o
435435

436436
### 3.3) Adding Timesteps
437437

438-
LSTM network needs the data imported as a 3D array. To translate this 2D array into a 3D one, we use a short [timestep](http://colah.github.io/posts/2015-08-Understanding-LSTMs/) to loop through the data and create smaller partitions and feed them into the model. The final array is then reshaped into training samples, x number of timesteps, and 1 feature per step. The code below represents this concept:
438+
To implement the LSTM network for time series forecasting, we have used a [time step](http://colah.github.io/posts/2015-08-Understanding-LSTMs/) of 3 days. This technique allows the network to look back at the previous 3 days of data to predict the subsequent day. The figure below illustrates how this concept is used in our implementation, where the first 3 samples for Close price generate the 4th sample and so on. This generates a matrix of shape (3,1), with 3 representing the time steps and 1 representing the number of features (Close price).
439439

440-
```python
441-
time_steps = 3
442-
for i in range(time_steps, train_scaled.shape[0]):
443-
x_train.append(train_scaled[i - time_steps:i])
444-
y_train.append(train_scaled[i, 0])
445-
```
440+
![](https://github.com/JordiCorbilla/stock-prediction-deep-neural-learning/blob/master/timesteps.png)
446441

447442
![](https://github.com/JordiCorbilla/stock-prediction-deep-neural-learning/blob/master/3dmatrix.png)
448443

449-
We have implemented a time step of 3 days. Using this technique, we allow our network to look back 3 days on our data to predict the subsequent day). The figure below represents how our implementation uses this concept and how the first 3 samples for Close price would generate the 4th sample and so on.This will generate a matrix of shape (3,1), 3 being the time steps and 1 the number of features (Close price).
444+
```python
445+
# Define the number of time steps
446+
time_steps = 3
447+
448+
# Loop through the data to create partitions
449+
for i in range(time_steps, train_scaled.shape[0]):
450+
# Create a partition of the previous 3 days' data
451+
x_train.append(train_scaled[i - time_steps:i])
450452

451-
![](https://github.com/JordiCorbilla/stock-prediction-deep-neural-learning/blob/master/timesteps.png)
453+
# Append the next day's Close price to the label array
454+
y_train.append(train_scaled[i, 0])
455+
```
456+
457+
Using a time step of 3 days allows the LSTM network to identify patterns in the data and make predictions based on those patterns. By using a sliding window approach, we can train the network to predict future stock prices based on historical data.
452458

453459
### 3.4) Creation of the deep learning model LSTM
454460

0 commit comments

Comments
 (0)