update on log reg with examples
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user