Python scikits - 缓冲区的维数错误(预期1,得2)

zub*_*hta 3 python regression numpy scikits scikit-learn

我正在尝试此代码段.我正在使用scikits.learn 0.8.1

from scikits.learn import linear_model
import numpy as np
num_rows = 10000
X = np.zeros([num_rows,2])
y = np.zeros([num_rows,1])
# assume here I have filled in X and y appropriately with 0s and 1s from the dataset
clf = linear_model.LogisticRegression()
clf.fit(X, y)
Run Code Online (Sandbox Code Playgroud)

我得到了这个 - >

/usr/local/lib/python2.6/dist-packages/scikits/learn/svm/liblinear.so in scikits.learn.svm.liblinear.train_wrap (scikits/learn/svm/liblinear.c:992)()

ValueError: Buffer has wrong number of dimensions (expected 1, got 2)
Run Code Online (Sandbox Code Playgroud)

这里有什么问题?

zub*_*hta 5

解决了.该错误是由于:

y = np.zeros([num_rows,1])
Run Code Online (Sandbox Code Playgroud)

应该是:

y = np.zeros([num_rows])
Run Code Online (Sandbox Code Playgroud)

  • 或者只是`np.zeros(num_rows)`. (3认同)