IoannisTr commited on
Commit
41fcaea
1 Parent(s): 93857bb

Update functions.py

Browse files
Files changed (1) hide show
  1. functions.py +27 -3
functions.py CHANGED
@@ -339,7 +339,9 @@ class Models(object):
339
  predictions = scaler.inverse_transform(predictions)
340
  #rmse = np.sqrt(np.mean(((predictions - y_test) ** 2)))
341
  global r_squared_score
 
342
  r_squared_score = round(r2_score(y_test, predictions),2)
 
343
  #print('Rmse Score: ', round(rmse),2)
344
  print('R2 Score: ', r_squared_score)
345
 
@@ -439,20 +441,42 @@ class Models(object):
439
  mode = 'lines',
440
  name = '7-day Prediction',
441
  line=dict(width=1,color="#EE3B3B"))
 
 
 
 
 
 
442
 
443
  layout = go.Layout(
444
  title = 'Next 7 days stock price prediction of ' + str(ticker),
445
  xaxis = {'title' : "Date"},
446
  yaxis = {'title' : "Price ($)"}
447
  )
448
- fig = go.Figure(data=[plot_1, plot_2], layout=layout)
449
  fig.update_layout(template='plotly_dark',autosize=True)
450
  fig.update_layout(legend=dict(
451
  orientation="h",
452
  yanchor="bottom",
453
  y=1.02,
454
  xanchor="right",
455
- x=1
456
- ))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
457
 
458
  return fig
 
339
  predictions = scaler.inverse_transform(predictions)
340
  #rmse = np.sqrt(np.mean(((predictions - y_test) ** 2)))
341
  global r_squared_score
342
+ global rmse
343
  r_squared_score = round(r2_score(y_test, predictions),2)
344
+ rmse = np.sqrt(np.mean(((predictions - y_test) ** 2)))
345
  #print('Rmse Score: ', round(rmse),2)
346
  print('R2 Score: ', r_squared_score)
347
 
 
441
  mode = 'lines',
442
  name = '7-day Prediction',
443
  line=dict(width=1,color="#EE3B3B"))
444
+ plot_3 = go.Scatter(
445
+ x = finaldfPredictions['Date'][:1],
446
+ y = finaldfPredictions['Adj Close'][:1],
447
+ mode = 'markers',
448
+ name = 'Latest Actual Closing Price',
449
+ line=dict(width=1))
450
 
451
  layout = go.Layout(
452
  title = 'Next 7 days stock price prediction of ' + str(ticker),
453
  xaxis = {'title' : "Date"},
454
  yaxis = {'title' : "Price ($)"}
455
  )
456
+ fig = go.Figure(data=[plot_1, plot_2,plot_3], layout=layout)
457
  fig.update_layout(template='plotly_dark',autosize=True)
458
  fig.update_layout(legend=dict(
459
  orientation="h",
460
  yanchor="bottom",
461
  y=1.02,
462
  xanchor="right",
463
+ x=1),
464
+ annotations = [dict(x=0.5,
465
+ y=0,
466
+ xref='paper',
467
+ yref='paper',
468
+ text="Current In Sample R- Squared : " + str(r_squared_score*100) + " % \n",
469
+ showarrow = False)],
470
+ xaxis=dict(showgrid=False),
471
+ yaxis=dict(showgrid=False)
472
+
473
+
474
+ )
475
+ fig.add_annotation(x=0.5,
476
+ y=0.05,
477
+ xref='paper',
478
+ yref='paper',
479
+ text="Current In Sample Root Mean Square Error : " + str(round(rmse,2)) + " % ",
480
+ showarrow=False)
481
 
482
  return fig