# Importing libraries import pandas as pd from tsfresh import extract_features, extract_relevant_features, select_features from tsfresh.utilities.dataframe_functions import impute, make_forecasting_frame from tsfresh.feature_extraction import ComprehensiveFCParameters, settings
# Reading the data data = pd.read_csv('../input/air-passengers/AirPassengers.csv')
# Some preprocessing for time component: data.columns = ['month','Passengers'] data['month'] = pd.to_datetime(data['month'],infer_datetime_format=True,format='%y%m') data.index = data.month df_air = data.drop(['month'], axis = 1)
# Use Forecasting frame from tsfresh for rolling forecast training df_shift, y_air = make_forecasting_frame(df_air["Passengers"], kind="Passengers", max_timeshift=12, rolling_direction=1) print(df_shift)
数据需要被格式化为如下格式:
# Getting Comprehensive Features extraction_settings = ComprehensiveFCParameters() X = extract_features(df_shift, column_id="id", column_sort="time", column_value="value", impute_function=impute,show_warnings=False,default_fc_parameters=extraction_settings)
# Loading the library import pandas as pd import matplotlib.pyplot as plt from fbprophet import Prophet
# Loading the data from the repo: df = pd.read_csv("https://raw.githubusercontent.com/facebook/prophet/master/examples/example_wp_log_peyton_manning.csv")
# Fitting the model model = Prophet() model.fit(df) #fit the model.
# Predict future = model.make_future_dataframe(periods=730) # predicting for ~ 2 years forecast = model.predict(future) # Predict future
# Plot results fig1 = model.plot(forecast) # Plot the fit to past data and future forcast. fig2 = model.plot_components(forecast) # Plot breakdown of components. plt.show() forecast # Displaying various results in table format.
#Loading the package from darts import TimeSeries from darts.models import ExponentialSmoothing import matplotlib.pyplot as plt
# Reading the data data = pd.read_csv('../input/air-passengers/AirPassengers.csv') series = TimeSeries.from_dataframe(data, 'Month', '#Passengers') print(series)
# Splitting the series in train and validation set train, val = series.split_before(pd.Timestamp('19580101'))
# Applying a simple Exponential Smoothing model model = ExponentialSmoothing() model.fit(train)
# Getting and plotting the predictions
prediction = model.predict(len(val))series.plot(label='actual') prediction.plot(label='forecast', lw=3) plt.legend()
from sktime.datasets import load_airline from sktime.forecasting.base import ForecastingHorizon from sktime.forecasting.model_selection import temporal_train_test_split from sktime.forecasting.theta import ThetaForecaster from sktime.performance_metrics.forecasting import mean_absolute_percentage_error