Commit dd22e39d authored by IT18174236(Gunarathna D.M.G.S)'s avatar IT18174236(Gunarathna D.M.G.S)

Merge branch 'IT18174236(Content_Creation_Component)' into 'master'

It18174236(content creation component)

See merge request !7
parents 102afa59 8ac75838
This diff is collapsed.
import warnings;
warnings.simplefilter('ignore')
import pandas as pd
import fbprophet
from fbprophet import Prophet
import json
from prophet.serialize import model_to_json, model_from_json
from matplotlib import pyplot
df = pd.read_csv('dataset.csv')
# data preprocessing
df['Year'] = df['Time Date'].apply(lambda x: str(x)[-4:])
df['Month'] = df['Time Date'].apply(lambda x: str(x)[-6:-4])
df['Day'] = df['Time Date'].apply(lambda x: str(x)[:-6])
df['ds'] = pd.DatetimeIndex(df['Year'] + '-' + df['Month'] + '-' + df['Day'])
df = df.loc[(df['Code'] == 2667437) & (df['Topic'] == 'QLD_CW_ST0203')]
df.drop(['Time Date', 'Code', 'Topic', 'Year', 'Month', 'Day'], axis=1, inplace=True)
df.columns = ['y', 'ds']
# sample print
print(df.head())
# train model
m = Prophet(interval_width=0.95, daily_seasonality=True)
model = m.fit(df)
# save trained model
with open('serialized_model.json', 'w') as fout:
json.dump(model_to_json(m), fout) # Save model
# future prediction (next 100 days)
future = m.make_future_dataframe(periods=100, freq='D')
forecast = m.predict(future)
# print predicted data
print(forecast)
# show charts prediction
model.plot(forecast)
pyplot.show()
plot1 = m.plot(forecast)
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment