@@ -910,6 +910,7 @@ def __init__(self, alphas=(0.1, 1.0, 10.0),
910
910
911
911
def _pre_compute (self , X , y , centered_kernel = True ):
912
912
# even if X is very sparse, K is usually very dense
913
+ n_samples , n_features = X .shape
913
914
K = safe_sparse_dot (X , X .T , dense_output = True )
914
915
# the following emulates an additional constant regressor
915
916
# corresponding to fit_intercept=True
@@ -960,13 +961,14 @@ def _values(self, alpha, y, v, Q, QT_y):
960
961
return y - (c / G_diag ), c
961
962
962
963
def _pre_compute_svd (self , X , y , centered_kernel = True ):
963
- if sparse .issparse (X ):
964
- raise TypeError ("SVD not supported for sparse matrices" )
965
964
if centered_kernel :
966
965
X = np .hstack ((X , np .ones ((X .shape [0 ], 1 ))))
967
966
# to emulate fit_intercept=True situation, add a column on ones
968
967
# Note that by centering, the other columns are orthogonal to that one
969
- U , s , _ = linalg .svd (X , full_matrices = 0 )
968
+ if sparse .issparse (X ):
969
+ U , s , _ = sp_linalg .svds (X )
970
+ else :
971
+ U , s , _ = linalg .svd (X , full_matrices = 0 )
970
972
v = s ** 2
971
973
UT_y = np .dot (U .T , y )
972
974
return v , U , UT_y
@@ -1027,7 +1029,7 @@ def fit(self, X, y, sample_weight=None):
1027
1029
with_sw = len (np .shape (sample_weight ))
1028
1030
1029
1031
if gcv_mode is None or gcv_mode == 'auto' :
1030
- if sparse . issparse ( X ) or n_features > n_samples or with_sw :
1032
+ if n_features > n_samples or with_sw :
1031
1033
gcv_mode = 'eigen'
1032
1034
else :
1033
1035
gcv_mode = 'svd'
@@ -1283,8 +1285,7 @@ class RidgeClassifierCV(LinearClassifierMixin, _BaseRidgeCV):
1283
1285
See glossary entry for :term:`cross-validation estimator`.
1284
1286
1285
1287
By default, it performs Generalized Cross-Validation, which is a form of
1286
- efficient Leave-One-Out cross-validation. Currently, only the n_features >
1287
- n_samples case is handled efficiently.
1288
+ efficient Leave-One-Out cross-validation.
1288
1289
1289
1290
Read more in the :ref:`User Guide <ridge_regression>`.
1290
1291
0 commit comments