lr_sklearn



In [32]:
from sklearn import datasets
import numpy as np

from sklearn.linear_model import LogisticRegression

import matplotlib as mpl
import matplotlib.pyplot as plt
%matplotlib inline

In [33]:
iris = datasets.load_iris()
x = iris['data'][:,3:] #patal width
y = (iris['target']==2).astype(np.int)

In [34]:
logit_reg = LogisticRegression()
logit_reg.fit(x, y)


Out[34]:
LogisticRegression(C=1.0, class_weight=None, dual=False, fit_intercept=True,
          intercept_scaling=1, max_iter=100, multi_class='ovr', n_jobs=1,
          penalty='l2', random_state=None, solver='liblinear', tol=0.0001,
          verbose=0, warm_start=False)

In [35]:
plt.plot(x)
plt.figure() 
plt.plot(iris['target'])
plt.figure() 
plt.plot(x, y, "g-", label="Iris-Viginica")
# plt.plot(x, y, "b--", label="None Iris-Viginica")


Out[35]:
[<matplotlib.lines.Line2D at 0x1e6a27078d0>]

In [36]:
x_new = np.linspace(0,3,1000).reshape(-1,1)
y_prob = logit_reg.predict_proba(x_new)
decision_boundary = x_new[y_prob[:,1]>=0.5][0]
print(decision_boundary)


[ 1.61561562]

In [37]:
plt.plot(x_new, y_prob[:,1], "g-", label="Iris-Viginica")
plt.plot(x_new, y_prob[:,0], "b--", label="None Iris-Viginica")


Out[37]:
[<matplotlib.lines.Line2D at 0x1e6a21a6128>]

In [ ]: