Python scikits - 缓冲区维度错误(期望1,得到2)

3

我正在尝试这段代码。我使用的是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)

我遇到了这个问题 -->
/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)

这里有什么问题?

这是numpy的通用错误,当它禁止一个参数成为数组时会出现。 - smci
1个回答

5

问题已解决。错误原因是:

y = np.zeros([num_rows,1])

它应该是这样的:
y = np.zeros([num_rows])

4
或者只需使用np.zeros(num_rows) - Fred Foo

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接