Plot decision boundaries of classifier, ValueError: X has 2 features per sample; expecting 908430"
<p>Based on the scikit-learn document <a href="http://scikit-learn.org/stable/auto_examples/svm/plot_iris.html#sphx-glr-auto-examples-svm-plot-iris-py" rel="nofollow">http://scikit-learn.org/stable/auto_examples/svm/plot_iris.html#sphx-glr-auto-examples-svm-plot-iris-py</a>.
I try to plot a decision boundaries of the classifier, but it sends a error message call "ValueError: X has 2 features per sample; expecting 908430" for this code "Z = clf.predict(np.c_[xx.ravel(), yy.ravel()])"</p>

<pre><code>clf = SGDClassifier().fit(step2, index)  
X=step2
y=index
h = .02
colors = "bry"
x_min, x_max = X[:, 0].min() - 1, X[:, 0].max() + 1
y_min, y_max = X[:, 1].min() - 1, X[:, 1].max() + 1
xx, yy = np.meshgrid(np.arange(x_min, x_max, h),
                 np.arange(y_min, y_max, h))

Z = clf.predict(np.c_[xx.ravel(), yy.ravel()])

# Put the result into a color plot
Z = Z.reshape(xx.shape)
plt.contourf(xx, yy, Z, cmap=plt.cm.Paired)
plt.axis('off')

# Plot also the training points
plt.scatter(X[:, 0], X[:, 1], c=y, cmap=plt.cm.Paired)
</code></pre>

<p>the 'index' is a label which contain around [98579 X 1] label for the comment which include positive, natural and negative</p>

<pre><code>array(['N', 'N', 'P', ..., 'NEU', 'P', 'N'], dtype=object)
</code></pre>

<p>the 'step2' is the [98579 X 908430] numpy matrix which formed by the Countvectorizer function, which is about the comment data</p>

<pre><code>&lt;98579x908430 sparse matrix of type '&lt;type 'numpy.float64'&gt;'
with 3168845 stored elements in Compressed Sparse Row format&gt;
</code></pre>

<p>The thing is you <strong>cannot</strong> plot decision boundary for a classifier for data which is not <strong>2 dimensional</strong>. Your data is clearly high dimensional, it has 908430 dimensions (NLP task I assume). There is no way to plot actual decision boundary for such a model. Example that you are using is trained on <strong>2D data</strong> (reduced Iris) and this is <strong>the only reason</strong> why they were able to plot it.</p>

python machine-learning scikit-learn