In [ ]:
%matplotlib inline
In [1]:
print(__doc__)
# Code source: Gaël Varoquaux
# Modified for documentation by Jaques Grobler
# License: BSD 3 clause
import numpy as np
import matplotlib.pyplot as plt
from sklearn import linear_model, datasets
# import some data to play with
iris = datasets.load_iris()
X = iris.data[:, :2] # we only take the first two features.
Y = iris.target
h = .02 # step size in the mesh
logreg = linear_model.LogisticRegression(C=1e5)
# we create an instance of Neighbours Classifier and fit the data.
logreg.fit(X, Y)
# Plot the decision boundary. For that, we will assign a color to each
# point in the mesh [x_min, x_max]x[y_min, y_max].
x_min, x_max = X[:, 0].min() - .5, X[:, 0].max() + .5
y_min, y_max = X[:, 1].min() - .5, X[:, 1].max() + .5
xx, yy = np.meshgrid(np.arange(x_min, x_max, h), np.arange(y_min, y_max, h))
Z = logreg.predict(np.c_[xx.ravel(), yy.ravel()])
# Put the result into a color plot
Z = Z.reshape(xx.shape)
plt.figure(1, figsize=(4, 3))
plt.pcolormesh(xx, yy, Z, cmap=plt.cm.Paired)
# Plot also the training points
plt.scatter(X[:, 0], X[:, 1], c=Y, edgecolors='k', cmap=plt.cm.Paired)
plt.xlabel('Sepal length')
plt.ylabel('Sepal width')
plt.xlim(xx.min(), xx.max())
plt.ylim(yy.min(), yy.max())
plt.xticks(())
plt.yticks(())
plt.show()
In [1]:
import numpy as np
In [3]:
X = np.array([[1,1],[2,1],[1,3],[2,3]])
y = np.array([[0,0,1,1]])
In [47]:
import matplotlib as mpl
import matplotlib.pyplot as plt
%matplotlib inline
fig = plt.figure()
ax = fig.add_subplot(111)
plt.scatter(X[0:2,0],X[0:2,1],color='Blue',marker='^',s=50)
plt.scatter(X[2:,0],X[2:,1],color='Green',marker='o',s=50)
x1 = np.arange(0, 2.5, 0.1)
x2 = 2*x1
plt.plot(x1,x2, color='red',linestyle='-.')
x2 = 0*x1 + 2
plt.plot(x1,x2, color='red',linestyle='-')
x2 = 0*x1 + 1.5
plt.plot(x1,x2, color='red',linestyle='--')
ax.text(1.3, 4, "$x_2 - 2x_1 = 0$")
ax.text(2.2, 2.1, "$x_2 - 2 = 0$")
ax.text(2.2, 1.2, "$x_2 - 1.5 = 0$")
Out[47]: