【发布时间】:2019-09-18 02:35:30
【问题描述】:
我正在开发一个项目,用于按日期和时间预测 -1 到 1 之间的值。 我有一个包含 100 个预测值的数据集,我将数据拆分为 70 个训练集和 30 个测试集。 数据包含:日期和时间(2019-04-25 21:00:00)和预测(-1 到 1 值)
当我尝试在火车上调用 fit_transform 时,我收到了一个错误:
"ValueError: 预期二维数组,得到一维数组:array=[-1.-1. 1.-1。 -1。 -1。 -1。 -1。 -1。 -1。 -1。 -1。 -1。 1.-1。 1.-1。 1. 1.-1。 1.-1。 -1。 -1。 -1。 -1。 -1。 1.-1。 -1。 -1。 1.-1。 -1。 -1。 -1。 -1。 -1。 1.-1。 -1。 -1。 -1。 -1。 -1。 -1。 1.-1。 -1。 -1。 1.-1。 -1。 -1。 -1。 -1.]。如果您的数据具有单个特征,则使用 array.reshape(-1, 1) 或 array.reshape(1, -1) 重塑您的数据 包含一个样本。”
df = pd.read_csv(file_to_read)
df['Date']=pd.to_datetime(df['Date'])
df=df.set_index(['Date'],drop=True)
print(df.head(size))
#Index for prediction
pred_index=int((size*30)/100)
from_specific_time=df.index[pred_index]
split_date=pd.Timestamp(from_specific_time)
df=df['Predict']
train=df.loc[split_date:]
test=df.loc[:split_date]
plt.figure(figsize=(10,6))
ax=train.plot()
test.plot(ax=ax)
plt.legend(['train','test'])
scaler=MinMaxScaler(feature_range=(-1,1))
train_scaler=scaler.fit_transform(train)
test_scaler=scaler.transform(test)
我想在 csv 中按确切时间创建一个时间序列,然后预测测试值..我不确定我做错了什么.. 顺便说一句,我正在学习教程:https://towardsdatascience.com/an-introduction-on-time-series-forecasting-with-simple-neura-networks-lstm-f788390915b
谢谢!
【问题讨论】:
-
您在使用 MinMaxScaler 之前尝试过 train.values.reshape(-1, 1) 吗?
标签: python keras deep-learning time-series prediction