Skip to content

Commit

Permalink
the l1 logreg example now works with l1_min_c
Browse files Browse the repository at this point in the history
  • Loading branch information
paolo-losi committed Apr 26, 2011
1 parent c6189e8 commit e44915f
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions examples/linear_model/plot_logistic_path.py
Expand Up @@ -18,6 +18,7 @@

from scikits.learn import linear_model
from scikits.learn import datasets
from scikits.learn.svm import l1_min_c

iris = datasets.load_iris()
X = iris.data
Expand All @@ -31,18 +32,19 @@
################################################################################
# Demo path functions

alphas = np.logspace(2, -4, 100)
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_ = [clf.fit(X, y, C=1.0/alpha).coef_.ravel().copy() for alpha in alphas]
coefs_ = [clf.fit(X, y, C=c).coef_.ravel().copy() for c in cs]
print "This took ", datetime.now() - start

coefs_ = np.array(coefs_)
pl.plot(-np.log10(alphas), coefs_)
pl.plot(np.log10(cs), coefs_)
ymin, ymax = pl.ylim()
pl.xlabel('-log(alpha)')
pl.xlabel('log(C)')
pl.ylabel('Coefficients')
pl.title('Logistic Regression Path')
pl.axis('tight')
Expand Down

0 comments on commit e44915f

Please sign in to comment.