Python / Scikit-Learn - 无法处理多类和连续的混合

时间:2016-05-21 19:57:30

标签: python scikit-learn

我试图让SGDRegressor适合我的数据,然后检查准确性。拟合工作正常,但预测与原始目标数据的数据类型(?)不同,我得到错误

print "Accuracy:", ms.accuracy_score(y_test,predictions)

致电Product_id/Date/product_group1/Price/Net price/Purchase price/Hour/Quantity/product_group2 0 107 12/31/2012 10 300 236 220 10 1 108

数据看起来像这样(只有20万+行):

from sklearn.preprocessing import StandardScaler
import numpy as np
from sklearn.linear_model import SGDRegressor
import numpy as np
from sklearn import metrics as ms

msk = np.random.rand(len(beers)) < 0.8

train = beers[msk]
test = beers[~msk]

X = train [['Price', 'Net price', 'Purchase price','Hour','Product_id','product_group2']]
y = train[['Quantity']]
y = y.as_matrix().ravel()

X_test = test [['Price', 'Net price', 'Purchase price','Hour','Product_id','product_group2']]
y_test = test[['Quantity']]
y_test = y_test.as_matrix().ravel()

clf = SGDRegressor(n_iter=2000)
clf.fit(X, y)
predictions = clf.predict(X_test)
print "Accuracy:", ms.accuracy_score(y_test,predictions)

代码如下:

{{1}}

我应该做些什么?谢谢!

2 个答案:

答案 0 :(得分:27)

准确度是一种分类指标。您不能将其与回归一起使用。有关各种指标的信息,请参阅the documentation

答案 1 :(得分:8)

准确度分数仅适用于分类问题。对于回归问题,您可以使用:R2 Score,MSE(Mean Squared Error),RMSE(均方根误差)。