New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MRG+1] Fixes #10284 Added store_cv_values to RidgeClassifierCV and a test. #10297
Changes from 3 commits
1745347
eb59462
90a7205
f6130fe
980ea0e
c894d04
1d18ca2
cf4076f
058be5b
771ab2c
e68b31b
992fd6e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,8 +49,11 @@ | |
X_iris = sp.csr_matrix(iris.data) | ||
y_iris = iris.target | ||
|
||
DENSE_FILTER = lambda X: X | ||
SPARSE_FILTER = lambda X: sp.csr_matrix(X) | ||
|
||
def DENSE_FILTER(X): return X | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While I said, sure, get rid of the extra There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, pep8 made that. Generally, I reverse those changes but missed this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reverse this |
||
|
||
|
||
def SPARSE_FILTER(X): return sp.csr_matrix(X) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you reverse that |
||
|
||
|
||
def test_ridge(): | ||
|
@@ -352,7 +355,7 @@ def _test_ridge_loo(filter_): | |
assert_equal(ridge_gcv2.alpha_, alpha_) | ||
|
||
# check that we get same best alpha with custom score_func | ||
func = lambda x, y: -mean_squared_error(x, y) | ||
def func(x, y): return -mean_squared_error(x, y) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reverse this change |
||
scoring = make_scorer(func) | ||
ridge_gcv3 = RidgeCV(fit_intercept=False, scoring=scoring) | ||
f(ridge_gcv3.fit)(filter_(X_diabetes), y_diabetes) | ||
|
@@ -576,7 +579,7 @@ def test_class_weights_cv(): | |
|
||
def test_ridgecv_store_cv_values(): | ||
# Test _RidgeCV's store_cv_values attribute. | ||
rng = rng = np.random.RandomState(42) | ||
rng = np.random.RandomState(42) | ||
|
||
n_samples = 8 | ||
n_features = 5 | ||
|
@@ -592,10 +595,37 @@ def test_ridgecv_store_cv_values(): | |
assert_equal(r.cv_values_.shape, (n_samples, n_alphas)) | ||
|
||
# with len(y.shape) == 2 | ||
n_responses = 3 | ||
y = rng.randn(n_samples, n_responses) | ||
n_targets = 3 | ||
y = rng.randn(n_samples, n_targets) | ||
r.fit(x, y) | ||
assert_equal(r.cv_values_.shape, (n_samples, n_targets, n_alphas)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. assert r.cv_values_.shape == (n_samples, n_targets, n_alphas) |
||
|
||
|
||
def test_ridge_classifier_cv_store_cv_values(): | ||
# Test RidgeClassifier | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove this comment |
||
x = np.array([[-1.0, -1.0], [-1.0, 0], [-.8, -1.0], | ||
[1.0, 1.0], [1.0, 0.0]]) | ||
y = np.array([1, 1, 1, -1, -1]) | ||
|
||
n_samples = x.shape[0] | ||
|
||
alphas = [1e-1, 1e0, 1e1] | ||
n_alphas = len(alphas) | ||
|
||
r = RidgeClassifierCV(alphas=alphas, store_cv_values=True) | ||
|
||
# with len(y.shape) == 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. len(y.shape) == 2. |
||
n_targets = 1 | ||
r.fit(x, y) | ||
assert_equal(r.cv_values_.shape, (n_samples, n_targets, n_alphas)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. plain assert |
||
|
||
# with len(y.shape) == 2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But this is the case with both tests. What do you intend to distinguish between the different ys? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was trying to replicate the test for RidgeCV: def test_ridgecv_store_cv_values():
# Test _RidgeCV's store_cv_values attribute.
rng = np.random.RandomState(42)
n_samples = 8
n_features = 5
x = rng.randn(n_samples, n_features)
alphas = [1e-1, 1e0, 1e1]
n_alphas = len(alphas)
r = RidgeCV(alphas=alphas, store_cv_values=True)
# with len(y.shape) == 1
y = rng.randn(n_samples)
r.fit(x, y)
assert_equal(r.cv_values_.shape, (n_samples, n_alphas))
# with len(y.shape) == 2
n_responses = 3
y = rng.randn(n_samples, n_responses)
r.fit(x, y)
assert_equal(r.cv_values_.shape, (n_samples, n_responses, n_alphas)) However, for the first case I guess then two tests are unnecessary. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! Removed it. |
||
y = np.array([[1, 1, 1, -1, -1], | ||
[1, -1, 1, -1, 1], | ||
[-1, -1, 1, -1, -1]]).transpose() | ||
n_targets = y.shape[1] | ||
r.fit(x, y) | ||
assert_equal(r.cv_values_.shape, (n_samples, n_responses, n_alphas)) | ||
assert_equal(r.cv_values_.shape, (n_samples, n_targets, n_alphas)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. plain assert |
||
|
||
|
||
def test_ridgecv_sample_weight(): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Double backticks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok! Dind't touch this, I copied it from RidgeCV. Should I change documentation for store_cv_values_ and cv_values_ too in other parts of the file to keep consistency??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose so