Scikit SVM error: X.shape[1] = 1 should be equal to 2
<p>I am trying to use Scikit to train 2 features called: x1 and x2. Both these arrays are shape <code>(490,1)</code>. In order to pass in one <code>X</code> argument into <code>clf.fit(X,y)</code>, I used <code>np.concatenate</code> to produce an array shape <code>(490,2)</code>. The label array is composed of 1's and 0's and is shape <code>(490,)</code>. The code is shown below:</p>

<pre><code>x1 = int_x # previously defined array shape (490,1)
x2 = int_x2 # previously defined array shape (490,1)
y=np.ravel(close) # where close is composed of 1's and 0's shape (490,1)
X,y = np.concatenate((x1[:-1],x2[:-1]),axis=1), y[:-1] #train on all datapoints except last 
clf = SVC()
clf.fit(X,y)
</code></pre>

<p>The following error is shown:</p>

<pre><code>X.shape[1] = 1 should be equal to 2, the number of features at training time
</code></pre>

<p>What I don't understand is why this message appears even though when I check the shape of X, it is indeed 2 and not 1. I originally tried this with only one feature and <code>clf.fit(X,y)</code> worked well, so I am inclined to think that <code>np.concatenate</code> produced something that was not suitable. Any suggestions would be great. </p>

<p>I think I understand what was wrong with my code. </p>

<p>First, I should have created another variable, say <code>x</code> that defined the concatenation of <code>int_x</code> and <code>int_x2</code> and is shape: (490,2), which is the same shape as <code>close</code>. This came in handy later.</p>

<p>Next, the <code>clf.fit(X,y)</code> was not incorrect in itself. However, I did not correctly formulate my prediction code. For instance, I said: <code>clf.predict([close[-1]])</code> in hopes of capturing the binary target output (either 0 or 1). The argument that was passed into this method was incorrect. It should have been <code>clf.predict([x[-1]])</code> because the algorithm predicts the label at the feature location as opposed to the other way around. Since the variable <code>x</code> is now the same shape as <code>close</code>, then the result of <code>clf.predict([x[-1]])</code> should produce the predicted result of <code>close[-1]</code>.</p>

python scikit-learn svm