53 lines
2.5 KiB
Diff
53 lines
2.5 KiB
Diff
Based on the GitHub issue, I can provide the patch for fixing the `store_cv_values` parameter issue in `RidgeClassifierCV`. This is a well-known scikit-learn issue where `RidgeClassifierCV` inherits from `_BaseRidgeCV` but doesn't expose the `store_cv_values` parameter that `RidgeCV` does.
|
|
|
|
The fix involves adding the `store_cv_values` parameter to `RidgeClassifierCV`'s `__init__` method. Here's the patch:
|
|
|
|
--- a/sklearn/linear_model/ridge.py
|
|
+++ b/sklearn/linear_model/ridge.py
|
|
@@ -1297,7 +1297,7 @@ class RidgeClassifierCV(LinearClassifierMixin, _BaseRidgeCV):
|
|
def __init__(self, alphas=(0.1, 1.0, 10.0), fit_intercept=True,
|
|
normalize=False, scoring=None, cv=None, class_weight=None,
|
|
- store_cv_values=False):
|
|
+ store_cv_values=False):
|
|
super(RidgeClassifierCV, self).__init__(
|
|
alphas=alphas, fit_intercept=fit_intercept, normalize=normalize,
|
|
- scoring=scoring, cv=cv)
|
|
+ scoring=scoring, cv=cv, store_cv_values=store_cv_values)
|
|
self.class_weight = class_weight
|
|
--- a/sklearn/linear_model/ridge.py
|
|
+++ b/sklearn/linear_model/ridge.py
|
|
@@ -1290,12 +1290,13 @@ class RidgeClassifierCV(LinearClassifierMixin, _BaseRidgeCV):
|
|
self.classes_ : array of shape = [n_classes]
|
|
The classes labels.
|
|
"""
|
|
def __init__(self, alphas=(0.1, 1.0, 10.0), fit_intercept=True,
|
|
- normalize=False, scoring=None, cv=None, class_weight=None):
|
|
+ normalize=False, scoring=None, cv=None, class_weight=None,
|
|
+ store_cv_values=False):
|
|
super(RidgeClassifierCV, self).__init__(
|
|
alphas=alphas, fit_intercept=fit_intercept, normalize=normalize,
|
|
- scoring=scoring, cv=cv)
|
|
+ scoring=scoring, cv=cv, store_cv_values=store_cv_values)
|
|
self.class_weight = class_weight
|
|
--- a/sklearn/linear_model/tests/test_ridge.py
|
|
+++ b/sklearn/linear_model/tests/test_ridge.py
|
|
@@ -575,6 +575,20 @@ def test_class_weights_cv():
|
|
assert_array_equal(coefs.classes_, classes)
|
|
|
|
|
|
+def test_ridgecv_store_cv_values():
|
|
+ rng = np.random.RandomState(42)
|
|
+
|
|
+ n_samples, n_features = 8, 5
|
|
+ x = rng.randn(n_samples, n_features)
|
|
+ y = rng.randint(0, 2, n_samples)
|
|
+
|
|
+ # Test with store_cv_values=True
|
|
+ ridgecv = RidgeClassifierCV(alphas=[0.1, 1.0, 10.0], store_cv_values=True)
|
|
+ ridgecv.fit(x, y)
|
|
+ assert hasattr(ridgecv, 'cv_values_')
|
|
+ assert ridgecv.cv_values_.shape[0] == n_samples
|
|
+
|
|
+
|
|
def test_class_weight_vs_sample_weight():
|
|
"""Check class_weight resorts to sample_weight."""
|