我正在尝试将SGDRegressor放入我的数据中,然后检查准确性.拟合工作正常,但是预测与原始目标数据的数据类型(?)不同,我得到了错误
ValueError: Can't handle mix of multiclass and continuous
Run Code Online (Sandbox Code Playgroud)
当调用print "Accuracy:", ms.accuracy_score(y_test,predictions).
数据看起来像这样(只有20万+行):
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
Run Code Online (Sandbox Code Playgroud)
代码如下:
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', …Run Code Online (Sandbox Code Playgroud) 如果我打开同一个文件两次,它会给出错误,还是会创建两个不同的文件描述符?例如
a = open("teste.txt", O_RDONLY);
b = open("teste.txt", O_RDONLY);
Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个数据集来检查我的 Logistic 回归算法,但我无法从字典中创建一个 Pandas DataFrame。我收到“数据必须是一维的”异常。
x1 = np.random.random(size=(10,1))*2
x2 = np.random.random(size=(10,1))*2
x3 = np.random.random(size=(10,1))*2 + 2
x4 = np.random.random(size=(10,1))*2 + 2
y0 = np.zeros(shape=(10,1))
y1 = np.ones(shape=(10,1))
plt.scatter(x1,x2, color='g', marker='o')
plt.scatter(x3,x4, color='r', marker='o')
dict_data = { 'X1':np.concatenate((x1,x3)),
'X2':np.concatenate((x2,x4)),
'Y':np.concatenate((y0,y1))}
data = pd.DataFrame(dict_data, index=np.arange(20))
Run Code Online (Sandbox Code Playgroud)
我得到这个作为输出,错误数据必须是 1 维。
--------------------------------------------------------------------------
Exception Traceback (most recent call last)
<ipython-input-49-fe81f079ebc6> in <module>
13 dict_data = { 'X1':np.concatenate((x1,x3)), 'X2':np.concatenate((x2,x4)),'Y':np.concatenate((y0,y1))}
14 #print(dict_data.shape)
---> 15 data = pd.DataFrame(dict_data, index=np.arange(20).reshape(20))
~/anaconda3/lib/python3.6/site-packages/pandas/core/frame.py in __init__(self, data, index, columns, dtype, copy)
328 dtype=dtype, …Run Code Online (Sandbox Code Playgroud)