title: How do I plot the decision boundary of a regression using matplotlib?
body: <p>How do I add a countour map of the results of the logistic regression to my scatterplot? I want colored 0/1 zones, which delineate the decision boundary of the classifier.</p>
  
  <pre><code>import pandas as pd
  import numpy as np
  import pylab as pl
  import statsmodels.api as sm
  
  # Build X, Y from file
  f = open('ex2data2.txt')
  lines = f.readlines()
  x1 = []
  x2 = []
  y = []
  for line in lines:
      line = line.replace("\n", "")
      vals = line.split(",")
      x1.append(float(vals[0]))
      x2.append(float(vals[1]))
      y.append(int(vals[2]))
  
  x1 = np.array(x1)
  x2 = np.array(x2)
  y = np.array(y)
  
  x = np.vstack([x1, x2]).T
  
  # Scatter plot 0/1s
  pos_mask = y == 1
  neg_mask = y == 0
  pos_x1 = x1[pos_mask]
  neg_x1 = x1[neg_mask]
  pos_x2 = x2[pos_mask]
  neg_x2 = x2[neg_mask]
  pl.clf()
  pl.scatter(pos_x1, pos_x2, c='r')
  pl.scatter(neg_x1, neg_x2, c='g')
  
  # Run logistic regression
  logit = sm.Logit(y, x)
  result = logit.fit()
  result.params
  result.predict([1.0, 1.0])
  
  # Now I want to add a countour for 0/1 regression results to the scatter plot.
  </code></pre>