<jupyter_start><jupyter_text>Logistic Regression ExampleComputes path on IRIS dataset.<jupyter_code>print(__doc__)

from datetime import datetime
import numpy as np
import matplotlib.pyplot as plt

from sklearn import linear_model
from sklearn import datasets
from sklearn.svm import l1_min_c

iris = datasets.load_iris()
X = iris.data
y = iris.target

X = X[y != 2]
y = y[y != 2]

X -= np.mean(X, 0)

cs = l1_min_c(X, y, loss='log') * np.logspace(0, 3)

print("Computing regularization path ...")
start = datetime.now()
clf = linear_model.LogisticRegression(C=1.0, penalty='l1', tol=1e-6)
coefs_ = []
for c in cs:
    clf.set_params(C=c)
    clf.fit(X, y)
    coefs_.append(clf.coef_.ravel().copy())
print("Running time ", datetime.now() - start)

coefs_ = np.array(coefs_)
plt.plot(np.log10(cs), coefs_)
ymin, ymax = plt.ylim()
plt.xlabel('log(C)')
plt.ylabel('Coefficients')
plt.title('Logistic Regression Path')
plt.axis('tight')
plt.show()<jupyter_output>Automatically created module for IPython interactive environment
Computing regularization path ...
Running time  0:00:00.037826
{'fraction_non_alphanumeric': 0.13983440662373506, 'fraction_numerical': 0.022999080036798528, 'mean_word_length': 5.112359550561798, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '573672', 'license': 'Apache-2.0', 'n_tokens_mistral': 439, 'n_tokens_neox': 413, 'n_words': 100, 'path': 'notebooks/plot_logistic_path.ipynb', 'repo_name': 'lynnlangit/gcp-ml', 'size': '1087'}