Improving an interpreted Prophet model with deep learning
Hello, Khabrovites. As part of the recruitment of students for the online course " Machine Learning. Advanced ", we prepared a translation of the material.
We invite everyone to participate in the open demo lesson "Clustering Time Series" : an interesting task that can be tied to time series.
β’ Is it possible to find financial assets similar to each other in dynamics on the stock exchange?
β’ How to group users according to their behavior?
β’ Who Framed Roger Rabbit?
We will get answers to some of these questions in an online lesson. Join us!
, Prophet, Facebook. , , , , (, ) . , .
, , β NeuralProphet. , Prophet , . , , , Prophet.
, NeuralProphet
. , , . , , . !
NeuralProphet
, NeuralProphet
, , .
β , . , ( ), , . X, . , , , .
, β , , . ββ , - . , , .
Prophet . , , β ββ . β β , . Prophet , :
Prophet β ..
β ,
β . , , . , ( ) . , , .. , . . , :
, ( ), , .
, , ,
, , ( )
, Prophet , , . NeuralProphet
β Prophet, (PyTorch Stan) (AR-Net), . AR-Net , , , , .
NeuralProphet Prophet
NeuralProphet
PyTorch,
.
.
,
( 1).
.
, , -. , , Prophet , , .
, NeuralProphet
β , pip install.
. . .
, Python.
import pandas as pd
from fbprophet import Prophet
from neuralprophet import NeuralProphet
from sklearn.metrics import mean_squared_error
# plotting
import matplotlib.pyplot as plt
# settings
plt.style.use('seaborn')
plt.rcParams["figure.figsize"] = (16, 8)
neural_prophet_1.py hosted with β€ by GitHub
Peyton Manning ( ). , , , , Prophet. β .
Facebook, , Prophet, Prophet, NeuralProphet
.
, :
# loading the dataset
df = pd.read_csv('../neural_prophet/example_data/wp_log_peyton_manning.csv')
print(f'The dataset contains {len(df)} observations.')
df.head()
neural_prophet_2.py hosted with β€ by GitHub
, Prophet, : ds
β /, y
β , . , , .
, . , , . , , .
df.plot(x='ds', y='y', title='Log daily page views');
# getting the train/test split
test_length = 365
df_train = df.iloc[:-test_length]
df_test = df.iloc[-test_length:]
neural_prophet_3.py hosted with β€ by GitHub
Prophet
, Prophet . 4 . . , . , . , Β«future dataframeΒ». , . . , ( ). , preds_df_1
.
prophet_model = Prophet() prophet_model.fit(df_train) future_df = prophet_model.make_future_dataframe(periods=test_length) preds_df_1 = prophet_model.predict(future_df)
neural_prophet_4.py hosted with β€ by GitHub
, ( ).
, . .
. .
prophet_model.plot_components(preds_df_1);
.
NeuralProphet
, API NeuralProphet
Prophet. , , , NeuralProphet
.
nprophet_model = NeuralProphet()
metrics = nprophet_model.fit(df_train, freq="D")
future_df = nprophet_model.make_future_dataframe(df_train,
periods = test_length,
n_historic_predictions=len(df_train))
preds_df_2 = nprophet_model.predict(future_df)
neural_prophet_5.py hosted with β€ by GitHub
, . ( Prophet ) , Β«future dataframeΒ». , .
, , .
nprophet_model.plot(preds_df_2);
. ( , preds_df_2
, preds_df_1
, , , !), .
nprophet_model.plot_components(preds_df_2, residuals=True);
, .
nprophet_model.plot_parameters();
, , plot_components ( ).
, . DataFrame
, (MSE).
# prepping the DataFrame
df_test['prophet'] = preds_df_1.iloc[-test_length:].loc[:, 'yhat']
df_test['neural_prophet'] = preds_df_2.iloc[-test_length:].loc[:, 'yhat1']
df_test.set_index('ds', inplace=True)
print('MSE comparison ----')
print(f"Prophet:\t{mean_squared_error(df_test['y'], preds_df_1.iloc[-test_length:]['yhat']):.4f}")
print(f"NeuralProphet:\t{mean_squared_error(df_test['y'], preds_df_2.iloc[-test_length:]['yhat1']):.4f}")
df_test.plot(title='Forecast evaluation');
neural_prophet_6.py hosted with β€ by GitHub
.
, , MSE β NeuralProphet
.
, , . , , , , , , . . . .
NeuralProphet
β ( -), . , . Prophet, , , , .
Prophet NeuralProphet
, , , . , !
, , GitHub. , . .