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
0eeaa3af
Commit
0eeaa3af
authored
14 years ago
by
Fabian Pedregosa
Browse files
Options
Downloads
Patches
Plain Diff
Do not import scipy.sparse globally.
Import time and for compatibility with old scipy.
parent
7fa40ad5
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
scikits/learn/linear_model/ridge.py
+6
-3
6 additions, 3 deletions
scikits/learn/linear_model/ridge.py
with
6 additions
and
3 deletions
scikits/learn/linear_model/ridge.py
+
6
−
3
View file @
0eeaa3af
...
...
@@ -6,9 +6,6 @@ Ridge regression
# License: Simplified BSD
import
numpy
as
np
import
scipy.sparse
as
sp
from
scipy
import
linalg
from
scipy.sparse
import
linalg
as
sp_linalg
from
.base
import
LinearModel
from
..utils.extmath
import
safe_sparse_dot
...
...
@@ -85,6 +82,7 @@ class Ridge(LinearModel):
X
,
y
,
Xmean
,
ymean
=
\
LinearModel
.
_center_data
(
X
,
y
,
self
.
fit_intercept
)
import
scipy.sparse
as
sp
if
sp
.
issparse
(
X
):
self
.
_solve_sparse
(
X
,
y
,
sample_weight
)
else
:
...
...
@@ -116,6 +114,7 @@ class Ridge(LinearModel):
def
_solve_sparse
(
self
,
X
,
y
,
sample_weight
):
n_samples
,
n_features
=
X
.
shape
import
scipy.sparse
as
sp
if
n_features
>
n_samples
or
\
isinstance
(
sample_weight
,
np
.
ndarray
)
or
\
sample_weight
!=
1.0
:
...
...
@@ -132,14 +131,17 @@ class Ridge(LinearModel):
def
_solve
(
self
,
A
,
b
):
if
self
.
solver
==
"
cg
"
:
# this solver cannot handle a 2-d b.
from
scipy.sparse
import
linalg
as
sp_linalg
sol
,
error
=
sp_linalg
.
cg
(
A
,
b
)
if
error
:
raise
ValueError
(
"
Failed with error code %d
"
%
error
)
return
sol
else
:
import
scipy.sparse
as
sp
# we are working with dense symmetric positive A
if
sp
.
issparse
(
A
):
A
=
A
.
todense
()
from
scipy
import
linalg
return
linalg
.
solve
(
A
,
b
,
sym_pos
=
True
,
overwrite_a
=
True
)
...
...
@@ -255,6 +257,7 @@ class _RidgeGCV(LinearModel):
def
_pre_compute
(
self
,
X
,
y
):
# even if X is very sparse, K is usually very dense
K
=
safe_sparse_dot
(
X
,
X
.
T
,
dense_output
=
True
)
from
scipy
import
linalg
v
,
Q
=
linalg
.
eigh
(
K
)
return
K
,
v
,
Q
...
...
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