8000 DOC: use notebook-style for plot_logistic_path.py (#22536) · scikit-learn/scikit-learn@46f15a0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 46f15a0

Browse files
alexanmvlesteve
andauthored
DOC: use notebook-style for plot_logistic_path.py (#22536)
Co-authored-by: Loïc Estève <loic.esteve@ymail.com>
1 parent 5c7dac0 commit 46f15a0

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

examples/linear_model/plot_logistic_path.py

+18-11
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,11 @@
2828
# Author: Alexandre Gramfort <alexandre.gramfort@inria.fr>
2929
# License: BSD 3 clause
3030

31-
from time import time
32-
import numpy as np
33-
import matplotlib.pyplot as plt
31+
# %%
32+
# Load data
33+
# ---------
3434

35-
from sklearn import linear_model
3635
from sklearn import datasets
37-
from sklearn.svm import l1_min_c
3836

3937
iris = datasets.load_iris()
4038
X = iris.data
@@ -45,14 +43,17 @@
4543

4644
X /= X.max() # Normalize X to speed-up convergence
4745

48-
# #############################################################################
49-
# Demo path functions
46+
# %%
47+
# Compute regularization path
48+
# ---------------------------
5049

51-
cs = l1_min_c(X, y, loss="log") * np.logspace(0, 7, 16)
50+
import numpy as np
51+
52+
from sklearn import linear_model
53+
from sklearn.svm import l1_min_c
5254

55+
cs = l1_min_c(X, y, loss="log") * np.logspace(0, 7, 16)
5356

54-
print("Computing regularization path ...")
55-
start = time()
5657
clf = linear_model.LogisticRegression(
5758
penalty="l1",
5859
solver="liblinear",
@@ -66,9 +67,15 @@
6667
clf.set_params(C=c)
6768
clf.fit(X, y)
6869
coefs_.append(clf.coef_.ravel().copy())
69-
print("This took %0.3fs" % (time() - start))
7070

7171
coefs_ = np.array(coefs_)
72+
73+
# %%
74+
# Plot regularization path
75+
# ------------------------
76+
77+
import matplotlib.pyplot as plt
78+
7279
plt.plot(np.log10(cs), coefs_, marker="o")
7380
ymin, ymax = plt.ylim()
7481
plt.xlabel("log(C)")

0 commit comments

Comments
 (0)
0