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>It's difficult to say without having the concrete values of <code>int_x</code>, <code>int_x2</code> and <code>close</code>. Indeed, if I try with <code>int_x</code>, <code>int_x2</code> and <code>close</code> randomly constructed as  </p>

<pre><code>import numpy as np
from sklearn.svm import SVC

int_x = np.random.normal(size=(490,1))
int_x2 = np.random.normal(size=(490,1))
close = np.random.randint(2, size=(490,))
</code></pre>

<p>which conforms to your specs, then your code works. Thus the error may be in the way you constructed int_x, int_x2 and close. </p>

<p>If you believe the problem is not there, could you please share a minimal reproducible example with specific values of <code>int_x</code>, <code>int_x2</code> and <code>close</code>?</p>

python scikit-learn svm