Take the 2-minute tour ×

I am trying this code snippet. I am using 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)

I am getting this -->

/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)

What is wrong in here?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Solved. The error was due to:

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

It should have been:

y = np.zeros([num_rows])
share|improve this answer
Or just np.zeros(num_rows). –  larsmans Nov 15 '11 at 12:53

Your Answer


