Skip to content

Commit 71fb55c

Browse files
committed
fixed some issues in stock price prediction tutorial
1 parent 83c4743 commit 71fb55c

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

machine-learning/stock-prediction/stock_prediction.ipynb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,10 @@
159159
" sequence_data.append([np.array(sequences), target])\n",
160160
"\n",
161161
" # get the last sequence by appending the last `n_step` sequence with `lookup_step` sequence\n",
162-
" # for instance, if n_steps=50 and lookup_step=10, last_sequence should be of 59 (that is 50+10-1) length\n",
163-
" # this last_sequence will be used to predict in future dates that are not available in the dataset\n",
162+
" # for instance, if n_steps=50 and lookup_step=10, last_sequence should be of 60 (that is 50+10) length\n",
163+
" # this last_sequence will be used to predict future stock prices not available in the dataset\n",
164164
" last_sequence = list(sequences) + list(last_sequence)\n",
165-
" # shift the last sequence by -1\n",
166-
" last_sequence = np.array(pd.DataFrame(last_sequence).shift(-1).dropna())\n",
165+
" last_sequence = np.array(last_sequence)\n",
167166
" # add to result\n",
168167
" result['last_sequence'] = last_sequence\n",
169168
" \n",
@@ -1053,9 +1052,9 @@
10531052
" return accuracy_score(y_test, y_pred)\n",
10541053
"\n",
10551054
"\n",
1056-
"def predict(model, data, classification=False):\n",
1055+
"def predict(model, data):\n",
10571056
" # retrieve the last sequence from data\n",
1058-
" last_sequence = data[\"last_sequence\"][:N_STEPS]\n",
1057+
" last_sequence = data[\"last_sequence\"][-N_STEPS:]\n",
10591058
" # retrieve the column scalers\n",
10601059
" column_scaler = data[\"column_scaler\"]\n",
10611060
" # reshape the last sequence\n",

machine-learning/stock-prediction/stock_prediction.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,10 @@ def load_data(ticker, n_steps=50, scale=True, shuffle=True, lookup_step=1,
7878
sequence_data.append([np.array(sequences), target])
7979

8080
# get the last sequence by appending the last `n_step` sequence with `lookup_step` sequence
81-
# for instance, if n_steps=50 and lookup_step=10, last_sequence should be of 59 (that is 50+10-1) length
82-
# this last_sequence will be used to predict in future dates that are not available in the dataset
81+
# for instance, if n_steps=50 and lookup_step=10, last_sequence should be of 60 (that is 50+10) length
82+
# this last_sequence will be used to predict future stock prices not available in the dataset
8383
last_sequence = list(sequences) + list(last_sequence)
84-
# shift the last sequence by -1
85-
last_sequence = np.array(pd.DataFrame(last_sequence).shift(-1).dropna())
84+
last_sequence = np.array(last_sequence)
8685
# add to result
8786
result['last_sequence'] = last_sequence
8887

machine-learning/stock-prediction/test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ def get_accuracy(model, data):
2828
return accuracy_score(y_test, y_pred)
2929

3030

31-
def predict(model, data, classification=False):
31+
def predict(model, data):
3232
# retrieve the last sequence from data
33-
last_sequence = data["last_sequence"][:N_STEPS]
33+
last_sequence = data["last_sequence"][-N_STEPS:]
3434
# retrieve the column scalers
3535
column_scaler = data["column_scaler"]
3636
# reshape the last sequence

0 commit comments

Comments
 (0)