update on log reg with examples

This commit is contained in:
mhjensen
2018-09-20 11:16:24 +02:00
parent 93390e5dae
commit b6c60e0fdc
20 changed files with 375 additions and 19 deletions
+26
View File
@@ -151,3 +151,29 @@ f(z)[1-f(z)]$. This equation defines a transcendental equation for
$\mathbf{w}$, the solution of which, unlike linear regression, cannot
be written in a closed form.
Here we need gradient descent methods!
!split
===== A _scikit-learn_ example =====
!bc pycod
import numpy as np
import matplotlib.pyplot as plt
from sklearn import datasets
iris = datasets.load_iris()
list(iris.keys())
['data', 'target_names', 'feature_names', 'target', 'DESCR']
X = iris["data"][:, 3:] # petal width
y = (iris["target"] == 2).astype(np.int) # 1 if Iris-Virginica, else 0
from sklearn.linear_model import LogisticRegression
log_reg = LogisticRegression()
log_reg.fit(X, y)
X_new = np.linspace(0, 3, 1000).reshape(-1, 1)
y_proba = log_reg.predict_proba(X_new)
plt.plot(X_new, y_proba[:, 1], "g-", label="Iris-Virginica")
plt.plot(X_new, y_proba[:, 0], "b--", label="Not Iris-Virginica")
plt.show()
!ec