拥有4行特征的熊猫数据框,我从“forecast_col”为它们创建标签,然后将它们移回过去以便稍后进行预测:

pandasdf['label'] = pandasdf[forecast_col].shift(-forecast_out)

获取除“标签”列以外的所有行:

X = np.array(pandasdf.drop(['label'], 1))

规范化数据:

X = preprocessing.scale(X)

将最后一行用于未来预测:

X_lately = X[-forecast_out:]

选择用于培训和交叉验证的数据:

X = X[:-forecast_out]
y = np.array(pandasdf['label'])[:-forecast_out] 
X_train, X_test, y_train, y_test = cross_validation.train_test_split(X, y, test_size=0.3)

训练分类器:

clf = LinearRegression(n_jobs=-1)
clf.fit(X_train, y_train)

检查准确度 - 大约95%:准确度= clf.score(X_test,y_test)

预测最后的数据:

forecast_set = clf.predict(X_lately)

在这里,我应该得到“forecast_out”期间的未来价格列表,但我正在预测相同的最后数据(X_lately)价格

这是一个例子:forecasting the past

我究竟做错了什么?