import pandas as pd
import os
import numpy as np
from prophet import Prophet
from sklearn.metrics import mean_absolute_error
path="E:/Predition/data/environment_data/城市/处理表头数据/daily_results/normal_daily_results"
df = pd.read_csv('E:/Predition/data/environment_data/城市/处理表头数据/daily_results/normal_daily_results/test.csv',index_col= 'date',parse_dates=['date'])
print(df.shape)
df.reset_index(inplace=True)
df.columns = ["ds", "y"]
output_file = os.path.join(path, 'test-output.csv')
df.to_csv(output_file)
train = df[:int(df.shape[0]*0.7)]
test=df[int(df.shape[0]*0.7):]
train.shape, test.shape
model=Prophet(growth="linear",
              yearly_seasonality=True,
              weekly_seasonality=False,
              daily_seasonality=False,
              seasonality_mode="multiplicative",
              seasonality_prior_scale=12,
              )
model.fit(train)
forecast=model.predict(test)
print(forecast)
print(forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].head())
new_y = df.y.fillna('0')
df['new_y'] = new_y.values
df.dropna()
na_index =test[test.y.isna()].ds.values
na_index
forecast.tail()
print("在测试集上绝对值预测误差为:",mean_absolute_error(new_df.y.values,forecast.yhat.values))