title: How can I visualize border/decision function of two classes using scikit-learn
body: <p>I am pretty new in machine learning, so I still don't understand how I can visualize the border between 2 classes in bag of words case.</p>
  
  <p>I found the following exaplpe to plot data</p>
  
  <p><a href="https://stackoverflow.com/questions/28160335/plot-a-document-tfidf-2d-graph">plot a document tfidf 2D graph</a></p>
  
  <pre><code>from sklearn.datasets import fetch_20newsgroups
  from sklearn.feature_extraction.text import CountVectorizer, TfidfTransformer
  from sklearn.decomposition import PCA
  from sklearn.pipeline import Pipeline
  import matplotlib.pyplot as plt
  
  newsgroups_train = fetch_20newsgroups(subset='train', 
                                        categories=['alt.atheism', 'sci.space'])
  pipeline = Pipeline([
      ('vect', CountVectorizer()),
      ('tfidf', TfidfTransformer()),
  ])        
  X = pipeline.fit_transform(newsgroups_train.data).todense()
  
  pca = PCA(n_components=2).fit(X)
  data2D = pca.transform(X)
  plt.scatter(data2D[:,0], data2D[:,1], c=newsgroups_train.target)
  plt.show()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/FG6BU.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FG6BU.jpg" alt="enter image description here"></a></p>
  
  <p>In my project I use SVC estimator</p>
  
  <pre><code>clf = SVC(random_state=241, kernel = 'linear')
  clf.fit(X,newsgroups_train.target)
  </code></pre>
  
  <p>I have tried to use the example
  <a href="http://scikit-learn.org/stable/auto_examples/svm/plot_iris.html" rel="nofollow noreferrer">http://scikit-learn.org/stable/auto_examples/svm/plot_iris.html</a>
  but it didn't work in text clasification case</p>
  
  <p>So how can I add the border of two classes to this plot?</p>
  
  <p>Thank you!</p>