antitheft159
commited on
Commit
•
516b6c7
1
Parent(s):
e4489c3
Create StockPredictor.py
Browse files- StockPredictor.py +63 -0
StockPredictor.py
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
!pip install neuralprophet
|
2 |
+
|
3 |
+
import numpy as np
|
4 |
+
import pandas as pd
|
5 |
+
import matplotlib.pyplot as plt
|
6 |
+
from neuralprophet import NeuralProphet
|
7 |
+
|
8 |
+
import warnings
|
9 |
+
warnings.filterwarnings('ignore')
|
10 |
+
|
11 |
+
import os
|
12 |
+
for dirname, _, filesnames in os.walk('yourstockdata.csv')
|
13 |
+
for filenames in filesnames:
|
14 |
+
print(os.path.join(dirname, filename))
|
15 |
+
|
16 |
+
df = pd.read_csv('youstockdata.csv')
|
17 |
+
|
18 |
+
df.head()
|
19 |
+
|
20 |
+
df.info()
|
21 |
+
|
22 |
+
df['Date'] = pd.to_datetime(df['Date'])
|
23 |
+
|
24 |
+
df.dtypes
|
25 |
+
|
26 |
+
df = df[['Date', 'Close']]
|
27 |
+
|
28 |
+
df.head()
|
29 |
+
|
30 |
+
df.columns = ['ds', 'y']
|
31 |
+
|
32 |
+
df.head()
|
33 |
+
|
34 |
+
plt.plot(df['ds'], df['y'], label='actual', c='g')
|
35 |
+
plt.title('Stock Data')
|
36 |
+
plt.xlabel('Date')
|
37 |
+
plt.ylabel('Stock Price')
|
38 |
+
plt.show()
|
39 |
+
|
40 |
+
model = NeuralProphet(
|
41 |
+
batch_size=16
|
42 |
+
)
|
43 |
+
|
44 |
+
model.fit(df)
|
45 |
+
|
46 |
+
future = model.make_future_dataframe(df, periods=365)
|
47 |
+
|
48 |
+
forecast = model.predict(future)
|
49 |
+
forecast
|
50 |
+
|
51 |
+
actual_prediction = model.predict(df)
|
52 |
+
|
53 |
+
plt.plot(df['ds'], df['y'], label='actual', c='g')
|
54 |
+
plt.plot(actual_prediction['ds'], actual_prediction['yhat1'], label='prediction_actual', c='r')
|
55 |
+
plt.plot(forecast['ds'], forecast['yhat1'], label='future_prediction', c='b')
|
56 |
+
plt.xlabel('Date')
|
57 |
+
plt.ylabel('Stock Price')
|
58 |
+
plt.legend()
|
59 |
+
|
60 |
+
plt.show()
|
61 |
+
|
62 |
+
model.plot_components(forecast)
|
63 |
+
|