<jupyter_start><jupyter_text>Домашнее задание ===Данные----Данные содержат информацию о продажах автомобилей в месяц. Задание--* Построить модель предсказаний, используя библиотеку Propeht. * Сделать предсказание на год вперед (12 месяцев)* При постоении модели использовать кросс-валидацию<jupyter_code>from fbprophet import Prophet
from fbprophet.diagnostics import cross_validation
from fbprophet.diagnostics import performance_metrics
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv('../datatest/monthly-car-sales.csv')
df['Month'] = pd.to_datetime(df['Month'])
df.rename(columns = {'Month': 'ds',
                     'Sales': 'y'},
          inplace=True)
df.head()<jupyter_output><empty_output><jupyter_text>1. prophet model<jupyter_code>m = Prophet()
m.fit(df)
future = m.make_future_dataframe(periods=12, freq='M')
forecast = m.predict(future)
forecast
fig = m.plot(forecast)
ax = fig.add_subplot(111)
ax.axvline(x=forecast['ds'].max() - pd.Timedelta('365 days'), c='red', lw=2, alpha=0.5, ls='--')
fig.show()
df_cv = cross_validation(m, horizon='365 days')
cutoffs = df_cv.groupby('cutoff').mean().reset_index()['cutoff']
df_cv1 = df_cv[df_cv['cutoff']==df_cv['cutoff'].unique()[0]]
fig, ax = plt.subplots()

ax.plot(m.history['ds'], m.history['y'], 'k.', label = 'Historical')
ax.plot(df_cv1['ds'], df_cv1['yhat'], ls = '-', label = 'Horizon', color='blue')
ax.fill_between(df_cv1['ds'],
                df_cv1['yhat_lower'],
                df_cv1['yhat_upper'],
                color = 'blue',
                alpha = 0.2)
for i in range(len(cutoffs)):
    plt_dict = {'x': cutoffs[i],
                'c': 'red',
                'ls':'--'
                }
    if i == 0:
        plt_dict['label'] = 'Cuttofs'
    ax.axvline(**plt_dict)
ax.legend()
plt.show()

df_p = performance_metrics(df_cv)
df_p.head()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17103153393907003, 'fraction_numerical': 0.014430785676109033, 'mean_word_length': 3.9655172413793105, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '8885', 'license': 'MIT', 'n_tokens_mistral': 739, 'n_tokens_neox': 731, 'n_words': 131, 'path': 'home-work5.ipynb', 'repo_name': 'vladdez/RD_forscasting', 'size': '1871'}