[英]Preprocessing data for Time-Series prediction
好的,所以我正在研究如何进行时间序列预测。 像往常一样,预处理数据是困难的部分。 我知道我必须将数据文件中的“时间戳”转换为“日期时间”或“时间步长”。
df = pd.read_csv("airpassengers.csv")
month = pd.to_datatime(df['Month'])
(我可能错误地解析了数据时间,我看到人们使用pd.read_csv()
来解析数据。如果我这样做了,请告知如何正确执行)
我也了解我扩展数据的部分。 (有人可以向我解释缩放是如何工作的,我知道它会将我的所有数据都转换在我给它的范围内,但是我预测的 output 也会被缩放或其他什么。)
最后,一旦我对数据和时间戳进行了缩放和解析,我将如何使用经过训练的 model 进行实际预测。 我不知道要输入什么(例如) model.predict()
我做了一些研究,好像我必须改变我的数据集或其他东西,我不太明白文档在说什么。 该示例与时间序列预测没有直接关系。
我知道这很多,您现在可能能够回答所有问题。 我对此很陌生。 尽你所能提供帮助。 谢谢!
因此,因为您正在使用 airpassengers.csv 并询问预测建模,我假设您正在处理此 github
在我深入回答您的问题之前,我想确保您知道几件事。
让我们分解一下
加载和解析数据
import pandas as pd
import numpy as np
import matplotlib.pylab as plt
%matplotlib inline
from matplotlib.pylab import rcParams
rcParams['figure.figsize'] = 15, 6
air_passengers = pd.read_csv("./data/AirPassengers.csv", header = 0, parse_dates = [0], names = ['Month', 'Passengers'], index_col = 0)
这部分代码从 a.csv(逗号分隔值)文件加载数据。 它保存在数据框 air_passengers 中。 Inside the function to read in the csv we also state that there's a header in the first row, the first column is full of dates, the name of our columns is assigned, we index our data frame to the first column.
缩放数据
log_air_passengers = np.log(air_passengers.Passengers)
这样做是为了使数学有意义。 对数是指数的倒数(X^2 与 Log2X 相同)。 使用 numpy 的日志 function 它给了我们自然对数(log e)。 这也称为自然对数。 您的预测值实际上将非常接近百分比变化,您可以这样使用它们
现在数据已经被缩放,我们可以为统计建模做准备
log_air_passengers_diff = log_air_passengers - log_air_passengers.shift()
log_air_passengers_diff.dropna(inplace=True)
这会将数据帧更改为前一个数据点和下一个数据点之间的差异,而不仅仅是日志值本身。
您问题的最后一部分包含太多步骤,无法在此处介绍。 也不是调用单个function那么简单。 我鼓励您从这里了解更多信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.