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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ian Johnson
scikit-learn
Commits
0a382ac5
Commit
0a382ac5
authored
12 years ago
by
Vlad Niculae
Committed by
Nelle Varoquaux
12 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix example using deprecated API, output was misleading.
parent
9e7c03f7
No related branches found
No related tags found
Loading
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/linear_model/lasso_dense_vs_sparse_data.py
+9
-10
9 additions, 10 deletions
examples/linear_model/lasso_dense_vs_sparse_data.py
with
9 additions
and
10 deletions
examples/linear_model/lasso_dense_vs_sparse_data.py
+
9
−
10
View file @
0a382ac5
...
...
@@ -3,9 +3,8 @@
Lasso on dense and sparse data
==============================
We show that linear_model.Lasso and linear_model.sparse.Lasso
provide the same results and that in the case of
sparse data linear_model.sparse.Lasso improves the speed.
We show that linear_model.Lasso provides the same results for dense and sparse
data and that in the case of sparse data the speed is improved.
"""
print
__doc__
...
...
@@ -15,8 +14,7 @@ from scipy import sparse
from
scipy
import
linalg
from
sklearn.datasets.samples_generator
import
make_regression
from
sklearn.linear_model.sparse
import
Lasso
as
SparseLasso
from
sklearn.linear_model
import
Lasso
as
DenseLasso
from
sklearn.linear_model
import
Lasso
###############################################################################
...
...
@@ -24,13 +22,14 @@ from sklearn.linear_model import Lasso as DenseLasso
print
"
--- Dense matrices
"
X
,
y
=
make_regression
(
n_samples
=
200
,
n_features
=
5000
,
random_state
=
0
)
X_sp
=
sparse
.
coo_matrix
(
X
)
alpha
=
1
sparse_lasso
=
Sparse
Lasso
(
alpha
=
alpha
,
fit_intercept
=
False
,
max_iter
=
1000
)
dense_lasso
=
Dense
Lasso
(
alpha
=
alpha
,
fit_intercept
=
False
,
max_iter
=
1000
)
sparse_lasso
=
Lasso
(
alpha
=
alpha
,
fit_intercept
=
False
,
max_iter
=
1000
)
dense_lasso
=
Lasso
(
alpha
=
alpha
,
fit_intercept
=
False
,
max_iter
=
1000
)
t0
=
time
()
sparse_lasso
.
fit
(
X
,
y
)
sparse_lasso
.
fit
(
X
_sp
,
y
)
print
"
Sparse Lasso done in %fs
"
%
(
time
()
-
t0
)
t0
=
time
()
...
...
@@ -52,8 +51,8 @@ Xs = Xs.tocsc()
print
"
Matrix density : %s %%
"
%
(
Xs
.
nnz
/
float
(
X
.
size
)
*
100
)
alpha
=
0.1
sparse_lasso
=
Sparse
Lasso
(
alpha
=
alpha
,
fit_intercept
=
False
,
max_iter
=
10000
)
dense_lasso
=
Dense
Lasso
(
alpha
=
alpha
,
fit_intercept
=
False
,
max_iter
=
10000
)
sparse_lasso
=
Lasso
(
alpha
=
alpha
,
fit_intercept
=
False
,
max_iter
=
10000
)
dense_lasso
=
Lasso
(
alpha
=
alpha
,
fit_intercept
=
False
,
max_iter
=
10000
)
t0
=
time
()
sparse_lasso
.
fit
(
Xs
,
y
)
...
...
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