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)
从上面的输出中,我们可以看到大约创建了800个特征。tsfresh还有助于基于p值的特征选择。更多详细信息可以查看Github: https://github.com/blue-yonder/tsfresh
官方文档 https://tsfresh.readthedocs.io/en/latest/index.html
2、autots
AutoTS 是一个自动化的时间序列预测库,可以使用简单的代码训练多个时间序列模型,此库的一些最佳功能包括:
-
利用遗传规划优化方法寻找最优时间序列预测模型。
-
提供置信区间预测值的下限和上限。
-
它训练各种各样的模型,如统计的,机器学习以及深度学习模型
-
它还可以执行最佳模型的自动集成
-
它还可以通过学习最优NaN插补和异常值去除来处理混乱的数据
-
它可以运行单变量和多变量时间序列
让我们以苹果股票数据集为例,更详细地了解一下:
Loading the package
from autots import AutoTS
import matplotlib.pyplot as plt
import pandas as pd
Reading the data
df = pd.read_csv(‘…/input/apple-aapl-historical-stock-data/HistoricalQuotes.csv’)
Doing some preprocessing
def remove_dollar(x):
return x[2:]
df[’ Close/Last’] = df[’ Close/Last’].apply(remove_dollar)
df[’ Close/Last’] = df[’ Close/Last’].astype(float)
df[‘Date’] = pd.to_datetime(df[‘Date’])
Plot to see the data:
df = df[[“Date”, " Close/Last"]]
df[“Date”] = pd.to_datetime(df.Date)
temp_df = df.set_index(‘Date’)
temp_df[" Close/Last"].plot(figsize=(12, 8), title=“Apple Stock Prices”, fontsize=20, label=“Close Price”)
plt.legend()
plt.grid()
plt.show()
model = AutoTS(forecast_length=40, frequency=‘infer’, ensemble=‘simple’, drop_data_older_than_periods=100)
model = model.fit(df, date_col=‘Date’, value_col=’ Close/Last’, id_col=None)
这将运行数百个模型。你将在输出窗格中看到运行的各种模型。让我们看看模型如何预测:
prediction = model.predict()
forecast = prediction.forecast
print(“Stock Price Prediction of Apple”)
print(forecast)
temp_df[’ Close/Last’].plot(figsize=(15,8), title= ‘AAPL Stock Price’, fontsize=18, label=‘Train’)
forecast[’ Close/Last’].plot(figsize=(15,8), title= ‘AAPL Stock Price’, fontsize=18, label=‘Test’)
plt.legend()
plt.grid()
plt.show()
更多详细信息可以查看 Github: https://github.com/winedarksea/AutoTS
官网文档: https://winedarksea.github.io/AutoTS/build/html/source/tutorial.html
3、Prophet
Prophet是Facebook研究团队开发的知名时间序列软件包,于2017年首次发布,适用于具有强烈季节性影响的数据和多个季节的历史数据。它具有高度的用户友好性和可定制性,只需进行最少的设置。
让我们看一个简单的例子:
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.
趋势图和季节性图如下所示:
我们还可以看到预测以及所有的置信区间
更多详细信息可以查看Github: https://github.com/facebook/prophet
文档: https://facebook.github.io/prophet/
4、darts:
Darts 是另一个 Python 包,它有助于时间序列的操作和预测。语法是“sklearn-friendly”,使用fit和predict函数来实现目标。此外,它还包含了从 ARIMA 到神经网络的各种模型。
该软件包最好的部分是它不仅支持单变量,而且还支持多变量时间序列和模型。该库还可以方便地对模型进行回溯测试,并将多个模型的预测和外部回归组合起来。让我们举一个简单的例子来了解它的工作原理:
#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()
更多详细信息可以查看Github: https://github.com/unit8co/darts
文档: https://unit8co.github.io/darts/README.html
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数Python工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年Python开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上前端开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新
如果你觉得这些内容对你有帮助,可以扫码获取!!!(备注:Python)
605169)]
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上前端开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新
如果你觉得这些内容对你有帮助,可以扫码获取!!!(备注:Python)