Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit34c0a41

Browse files
authored
Merge pull requestx4nth055#61 from MikeNotInTheFlesh/master
Fix order of pred_future and true_future in stock price prediction code
2 parentse59575e +2563a68 commit34c0a41

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
lines changed

‎.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
machine-learning/stock-prediction/.ipynb_checkpoints/stock_prediction-checkpoint.ipynb

‎machine-learning/stock-prediction/stock_prediction.ipynb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -346,10 +346,10 @@
346346
"\"\"\"\n",
347347
" # if predicted future price is higher than the current,\n",
348348
" # then calculate the true future price minus the current price, to get the buy profit\n",
349-
" buy_profit = lambda current,true_future, pred_future: true_future - current if pred_future > current else 0\n",
349+
" buy_profit = lambda current,pred_future, true_future: true_future - current if pred_future > current else 0\n",
350350
" # if the predicted future price is lower than the current price,\n",
351351
" # then subtract the true future price from the current price\n",
352-
" sell_profit = lambda current,true_future, pred_future: current - true_future if pred_future < current else 0\n",
352+
" sell_profit = lambda current,pred_future, true_future: current - true_future if pred_future < current else 0\n",
353353
" X_test = data[\"X_test\"]\n",
354354
" y_test = data[\"y_test\"]\n",
355355
" # perform prediction and get prices\n",
@@ -528,9 +528,9 @@
528528
],
529529
"metadata": {
530530
"kernelspec": {
531-
"display_name":"Python 3.6.6 64-bit",
531+
"display_name":"Python 3",
532532
"language":"python",
533-
"name":"python36664bitea6884f10f474b21a2a2f022451e0d09"
533+
"name":"python3"
534534
},
535535
"language_info": {
536536
"codemirror_mode": {
@@ -542,9 +542,9 @@
542542
"name":"python",
543543
"nbconvert_exporter":"python",
544544
"pygments_lexer":"ipython3",
545-
"version":"3.6.6"
545+
"version":"3.8.0"
546546
}
547547
},
548548
"nbformat":4,
549549
"nbformat_minor":4
550-
}
550+
}

‎machine-learning/stock-prediction/test.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ def plot_graph(test_df):
2121

2222
defget_final_df(model,data):
2323
"""
24-
This function takes the `model` and `data` dict to
25-
construct a final dataframe that includes the features along
24+
This function takes the `model` and `data` dict to
25+
construct a final dataframe that includes the features along
2626
with true and predicted prices of the testing dataset
2727
"""
28-
# if predicted future price is higher than the current,
28+
# if predicted future price is higher than the current,
2929
# then calculate the true future price minus the current price, to get the buy profit
30-
buy_profit=lambdacurrent,true_future,pred_future:true_future-currentifpred_future>currentelse0
30+
buy_profit=lambdacurrent,pred_future,true_future:true_future-currentifpred_future>currentelse0
3131
# if the predicted future price is lower than the current price,
3232
# then subtract the true future price from the current price
33-
sell_profit=lambdacurrent,true_future,pred_future:current-true_futureifpred_future<currentelse0
33+
sell_profit=lambdacurrent,pred_future,true_future:current-true_futureifpred_future<currentelse0
3434
X_test=data["X_test"]
3535
y_test=data["y_test"]
3636
# perform prediction and get prices
@@ -47,16 +47,16 @@ def get_final_df(model, data):
4747
test_df.sort_index(inplace=True)
4848
final_df=test_df
4949
# add the buy profit column
50-
final_df["buy_profit"]=list(map(buy_profit,
51-
final_df["adjclose"],
52-
final_df[f"adjclose_{LOOKUP_STEP}"],
50+
final_df["buy_profit"]=list(map(buy_profit,
51+
final_df["adjclose"],
52+
final_df[f"adjclose_{LOOKUP_STEP}"],
5353
final_df[f"true_adjclose_{LOOKUP_STEP}"])
5454
# since we don't have profit for last sequence, add 0's
5555
)
5656
# add the sell profit column
57-
final_df["sell_profit"]=list(map(sell_profit,
58-
final_df["adjclose"],
59-
final_df[f"adjclose_{LOOKUP_STEP}"],
57+
final_df["sell_profit"]=list(map(sell_profit,
58+
final_df["adjclose"],
59+
final_df[f"adjclose_{LOOKUP_STEP}"],
6060
final_df[f"true_adjclose_{LOOKUP_STEP}"])
6161
# since we don't have profit for last sequence, add 0's
6262
)
@@ -79,8 +79,8 @@ def predict(model, data):
7979

8080

8181
# load the data
82-
data=load_data(ticker,N_STEPS,scale=SCALE,split_by_date=SPLIT_BY_DATE,
83-
shuffle=SHUFFLE,lookup_step=LOOKUP_STEP,test_size=TEST_SIZE,
82+
data=load_data(ticker,N_STEPS,scale=SCALE,split_by_date=SPLIT_BY_DATE,
83+
shuffle=SHUFFLE,lookup_step=LOOKUP_STEP,test_size=TEST_SIZE,
8484
feature_columns=FEATURE_COLUMNS)
8585

8686
# construct the model
@@ -129,4 +129,4 @@ def predict(model, data):
129129
ifnotos.path.isdir(csv_results_folder):
130130
os.mkdir(csv_results_folder)
131131
csv_filename=os.path.join(csv_results_folder,model_name+".csv")
132-
final_df.to_csv(csv_filename)
132+
final_df.to_csv(csv_filename)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp