Python scikits - 缓冲区维度不正确(预期1,得到2)

3 投票
1 回答
17460 浏览
提问于 2025-04-17 06:17

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

这里面有什么问题吗?

1 个回答

5

问题解决了。错误的原因是:

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

应该是:

y = np.zeros([num_rows])

撰写回答