我试图预测未来的利润数据在一个铜矿企业数据集的csv格式。在
我看了数据:
data = pd.read_csv('data.csv')
我把数据分开:
^{pr2}$创建svr预测值:
clf_svr= svm.SVR(kernel='rbf')
数据标准化:
from sklearn.preprocessing import StandardScaler
scalerX = StandardScaler().fit(x_train)
scalery = StandardScaler().fit(y_train)
x_train = scalerX.transform(x_train)
y_train = scalery.transform(y_train)
x_test = scalerX.transform(x_test)
y_test = scalery.transform(y_test)
print np.max(x_train), np.min(x_train), np.mean(x_train), np.max(y_train), np.min(y_train), np.mean(y_train)
然后预测:
y_pred=clf.predict(x_test)
并对预测数据进行了标准化处理。我希望预测的数据是原始格式,我该怎么做?在
正如其他人已经提到的,您应该使用
inverse_transform()
方法从之前应用的相应转换中检索原始数据。 另一个需要思考的问题是,如果我们的目的是预测实际的目标'y'值,为什么需要转换目标y_test, y_train
?在预测过程中,我们也可以保持它的原始状态。在另外(在python3.7.3,sklearn0.20.3)中,当您像上面所做的那样标准化单列行时,您会无意中收到一个numpy数组的输出,这对数据帧操作没有帮助
例如:
当您指定输出应该类似于一个单列数据帧时,您可能会遇到更多问题
例如:
解决方案:必须使用适当的子集选择运算符(.loc/.iloc)在列表中显式声明目标列名/索引。在
例如:
注意:在live-ML项目中,测试数据是指当您的模型准备好在产品化阶段进行调优时,将来到达或实时收集的数据。在
一个标准化的训练测试特征集,如
X_train, X_test
有助于比较特征变量与平均值之间的差异,也有助于对特征变量进行标准化的正则化和主成分分析技术。在您应该使用y-scaler的
inverse_transform
方法。请注意,您可以使用管道更简洁地完成所有这些,如下所示许多人只会在全球范围内扩大目标,而不会太过适应。但你不上当是好事。AFAIK对y数据使用单独的定标器(如代码中所示)是唯一的方法。在
我知道这个问题很古老,当时的答案是正确的,但是现在有一种scikit-learn方法来做这个。在
http://scikit-learn.org/dev/modules/compose.html#transforming-target-in-regression
相关问题 更多 >
编程相关推荐