Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
scikit-learn
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ian Johnson
scikit-learn
Commits
6e982be9
Commit
6e982be9
authored
14 years ago
by
Alexandre Gramfort
Browse files
Options
Downloads
Patches
Plain Diff
pretifying the LAR / LARS examples to match with results on wikipedia page
parent
87644dbc
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/glm/plot_lar.py
+6
-4
6 additions, 4 deletions
examples/glm/plot_lar.py
examples/glm/plot_lasso_lars.py
+9
-16
9 additions, 16 deletions
examples/glm/plot_lasso_lars.py
with
15 additions
and
20 deletions
examples/glm/plot_lar.py
+
6
−
4
View file @
6e982be9
...
@@ -33,15 +33,17 @@ X[:,6] *= -1 # To reproduce wikipedia LAR page
...
@@ -33,15 +33,17 @@ X[:,6] *= -1 # To reproduce wikipedia LAR page
print
"
Computing regularization path using the LARS ...
"
print
"
Computing regularization path using the LARS ...
"
start
=
datetime
.
now
()
start
=
datetime
.
now
()
alphas
_
,
_
,
coefs_
=
glm
.
lars_path
(
X
,
y
,
max_features
=
9
,
method
=
"
lar
"
)
_
,
_
,
coefs_
=
glm
.
lars_path
(
X
,
y
,
max_features
=
10
,
method
=
"
lar
"
)
print
"
This took
"
,
datetime
.
now
()
-
start
print
"
This took
"
,
datetime
.
now
()
-
start
###############################################################################
###############################################################################
# Display path
# Display path
pl
.
plot
(
-
np
.
log10
(
alphas_
),
coefs_
.
T
)
xx
=
np
.
sum
(
np
.
abs
(
coefs_
),
axis
=
0
)
xx
/=
xx
[
-
1
]
pl
.
plot
(
xx
,
coefs_
.
T
)
ymin
,
ymax
=
pl
.
ylim
()
ymin
,
ymax
=
pl
.
ylim
()
pl
.
vlines
(
-
np
.
log10
(
alphas_
)
,
ymin
,
ymax
,
linestyle
=
'
dashed
'
)
pl
.
vlines
(
xx
,
ymin
,
ymax
,
linestyle
=
'
dashed
'
)
pl
.
xlabel
(
'
-Log(lambda)
'
)
# XXX : wrong label
pl
.
xlabel
(
'
|coef| / max|coef|
'
)
pl
.
ylabel
(
'
Coefficients
'
)
pl
.
ylabel
(
'
Coefficients
'
)
pl
.
title
(
'
Least Angle Regression (LAR) Path
'
)
pl
.
title
(
'
Least Angle Regression (LAR) Path
'
)
pl
.
axis
(
'
tight
'
)
pl
.
axis
(
'
tight
'
)
...
...
This diff is collapsed.
Click to expand it.
examples/glm/plot_lasso_lars.py
+
9
−
16
View file @
6e982be9
...
@@ -4,6 +4,8 @@
...
@@ -4,6 +4,8 @@
Lasso with Least Angle Regression
Lasso with Least Angle Regression
=================================
=================================
Computes Lasso Path with the LARS algorithm
"""
"""
print
__doc__
print
__doc__
...
@@ -12,7 +14,6 @@ print __doc__
...
@@ -12,7 +14,6 @@ print __doc__
# License: BSD Style.
# License: BSD Style.
from
datetime
import
datetime
from
datetime
import
datetime
import
itertools
import
numpy
as
np
import
numpy
as
np
import
pylab
as
pl
import
pylab
as
pl
...
@@ -22,30 +23,22 @@ from scikits.learn import datasets
...
@@ -22,30 +23,22 @@ from scikits.learn import datasets
diabetes
=
datasets
.
load_diabetes
()
diabetes
=
datasets
.
load_diabetes
()
X
=
diabetes
.
data
X
=
diabetes
.
data
y
=
diabetes
.
target
y
=
diabetes
.
target
# someting's wrong with our dataset
X
[:,
6
]
*=
-
1
# To reproduce wikipedia LASSO page
X
[:,
6
]
=
-
X
[:,
6
]
################################################################################
################################################################################
# Demo path functions
# Demo path functions
G
=
np
.
dot
(
X
.
T
,
X
)
print
"
Computing regularization path using the LARS ...
"
print
"
Computing regularization path using the LARS ...
"
start
=
datetime
.
now
()
start
=
datetime
.
now
()
alphas
,
active
,
path
=
glm
.
lars_path
(
X
,
y
,
Gram
=
G
,
method
=
'
lasso
'
)
alphas
_
,
_
,
coefs_
=
glm
.
lars_path
(
X
,
y
,
method
=
'
lasso
'
)
print
"
This took
"
,
datetime
.
now
()
-
start
print
"
This took
"
,
datetime
.
now
()
-
start
alphas
=
np
.
sum
(
np
.
abs
(
path
.
T
),
axis
=
1
)
xx
=
np
.
sum
(
np
.
abs
(
coefs_
.
T
),
axis
=
1
)
alphas
/=
alphas
[
-
1
]
xx
/=
xx
[
-
1
]
pl
.
plot
(
xx
,
coefs_
.
T
)
# # Display results
color_iter
=
itertools
.
cycle
([
'
r
'
,
'
g
'
,
'
b
'
,
'
c
'
])
for
coef_
,
color
in
zip
(
path
,
color_iter
):
pl
.
plot
(
alphas
,
coef_
.
T
,
color
)
ymin
,
ymax
=
pl
.
ylim
()
ymin
,
ymax
=
pl
.
ylim
()
pl
.
vlines
(
alphas
,
ymin
,
ymax
,
linestyle
=
'
dashed
'
)
pl
.
vlines
(
xx
,
ymin
,
ymax
,
linestyle
=
'
dashed
'
)
pl
.
xlabel
(
'
-Log(lambda)
'
)
# XXX : wrong label
pl
.
xlabel
(
'
|coef| / max|coef|
'
)
pl
.
ylabel
(
'
Coefficients
'
)
pl
.
ylabel
(
'
Coefficients
'
)
pl
.
title
(
'
LASSO Path
'
)
pl
.
title
(
'
LASSO Path
'
)
pl
.
axis
(
'
tight
'
)
pl
.
axis
(
'
tight
'
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment