Python/Scikit-Learn - 无法处理多类和连续的混合 [英] Python/Scikit-Learn - Can't handle mix of multiclass and continuous

查看:78
本文介绍了Python/Scikit-Learn - 无法处理多类和连续的混合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to fit an SGDRegressor to my data and then check the accuracy. The fitting works fine, but then the predictions are not in the same datatype(?) as the original target data, and I get the error

ValueError: Can't handle mix of multiclass and continuous

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

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

The data looks like this (just 200 thousand + rows):

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

代码如下:

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)

我应该怎么做?谢谢!

推荐答案

准确度是一个分类指标.您不能将它与回归一起使用.有关各种指标的信息,请参阅文档.

Accuracy is a classification metric. You can't use it with a regression. See the documentation for info on the various metrics.

这篇关于Python/Scikit-Learn - 无法处理多类和连续的混合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆