【问题标题】:Python scikits - Buffer has wrong number of dimensions (expected 1, got 2)Python scikits - 缓冲区的维数错误(预期为 1,得到 2)
【发布时间】:2011-12-28 17:46:20
【问题描述】:

我正在尝试此代码 sn-p。我正在使用 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 的通用错误,它禁止将参数作为数组。

标签: python numpy regression scikits scikit-learn


【解决方案1】:

解决了。错误是由于:

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

应该是:

y = np.zeros([num_rows])

【讨论】:

  • 或者只是np.zeros(num_rows)
猜你喜欢
  • 1970-01-01
  • 2022-08-07
  • 1970-01-01
  • 1970-01-01
  • 2012-04-12
  • 1970-01-01
  • 2015-01-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多