2011-11-14 96 views
3

我正在嘗試此代碼片段。我使用scikits.learn 0.8.1Python scikits - 緩衝區的維數錯誤(預計1,得到2)

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) 

什麼在這裏錯了嗎?

+0

這是numpy的一般性錯誤時,禁止參數是一個數組。 – smci

回答

5

已解決。該錯誤是由於:

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

它應該是:

y = np.zeros([num_rows]) 
+3

或者只是'np.zeros(num_rows)'。 –

相關問題