Classifier.fit(X,y) error
<p>I'm trying some machine learning algorithms.</p>

<p>I'm using sklearn tool for logistic regression script.</p>

<p>this is my script:</p>

<pre><code>import numpy as np
from matplotlib import pyplot as plt
from sklearn.linear_model import LogisticRegression
#from sklearn.neighbors import KNeighborsClassifier
X = np.array([[10000,80000,35],[7000,120000,57],[100,23000,22],[223,18000,26]])

y = np.array([1,1,0,0]).reshape((1, -1))
classifier = LogisticRegression()
classifier.fit(X,y)
print(classifier.predict([5500,80000,25]))
</code></pre>

<p>The error that I got : </p>

<pre><code>Traceback (most recent call last):
  File "logictic_regression2.py", line 11, in &lt;module&gt;
 classifier.fit(X,y)
  File "/usr/local/lib/python2.7/dist-packages/sklearn/linear_model
logistic.py", line 1142, in fit order="C")
 File "/usr/local/lib/python2.7/dist-packages/sklearn/utils
validation.py", line 515, in check_X_y
y = column_or_1d(y, warn=True)
File "/usr/local/lib/python2.7/dist-packages/sklearn/util
/validation.py", line 551, in column_or_1d
raise ValueError("bad input shape {0}".format(shape))
ValueError: bad input shape (1, 4)
</code></pre>

<p>The <code>LogisticRegression.fit()</code> method expects a one-dimensional array for the target vector <code>y</code>. The error you mentioned should be gone if you remove the <code>.reshape((1, -1))</code> that converts it into a 1x4 matrix (row vector).</p>

<p>Furthermore, the last line of your code</p>

<pre><code>print(classifier.predict([5500,80000,25]))
</code></pre>

<p>raises a warning (at least in sklearn version 0.17.1) as for data a row per observation is expected. If you pass a two-dimensional numpy array (1x3 matrix) (<code>np.array([[5500,80000,25]]))</code>) everything works as expected.</p>

python scikit-learn