File size: 1,186 Bytes
516b6c7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
!pip install neuralprophet

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from neuralprophet import NeuralProphet

import warnings
warnings.filterwarnings('ignore')

import os
for dirname, _, filesnames in os.walk('yourstockdata.csv')
    for filenames in filesnames:
        print(os.path.join(dirname, filename))

df = pd.read_csv('youstockdata.csv')

df.head()

df.info()

df['Date'] = pd.to_datetime(df['Date'])

df.dtypes

df = df[['Date', 'Close']]

df.head()

df.columns = ['ds', 'y']

df.head()

plt.plot(df['ds'], df['y'], label='actual', c='g')
plt.title('Stock Data')
plt.xlabel('Date')
plt.ylabel('Stock Price')
plt.show()

model = NeuralProphet(
    batch_size=16
)

model.fit(df)

future = model.make_future_dataframe(df, periods=365)

forecast = model.predict(future)
forecast

actual_prediction = model.predict(df)

plt.plot(df['ds'], df['y'], label='actual', c='g')
plt.plot(actual_prediction['ds'], actual_prediction['yhat1'], label='prediction_actual', c='r')
plt.plot(forecast['ds'], forecast['yhat1'], label='future_prediction', c='b')
plt.xlabel('Date')
plt.ylabel('Stock Price')
plt.legend()

plt.show()

model.plot_components(forecast)