|
!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) |
|
|
|
|