8000 Merge pull request #2299 from ogrisel/grid-scores · scikit-learn/scikit-learn@2df651b · GitHub
[go: up one dir, main page]

Skip to content

Commit 2df651b

Browse files
committed
Merge pull request #2299 from ogrisel/grid-scores
Rename cv_scores(_) back to grid_scores(_) to keep the name free
2 parents e0e900f + b0035bf commit 2df651b

12 files changed

+46
-52
lines changed

doc/datasets/mldata_fixture.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ def setup_module():
4242

4343
def teardown_module():
4444
uninstall_mldata_mock()
45-
shutil.rmtree(custom_data_home)
45+
shutil.rmtree(custom_data_home)

examples/covariance/plot_sparse_cov.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
# plot the model selection metric
127127
pl.figure(figsize=(4, 3))
128128
pl.axes([.2, .15, .75, .7])
129-
pl.plot(model.cv_alphas_, np.mean(model.cv_scores, axis=1), 'o-')
129+
pl.plot(model.cv_alphas_, np.mean(model.grid_scores, axis=1), 'o-')
130130
pl.axvline(model.alpha_, color='.5')
131131
pl.title('Model selection')
132132
pl.ylabel('Cross-validation score')

examples/grid_search_digits.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
print()
6161
print("Grid scores on development set:")
6262
print()
63-
for params, mean_score, scores in clf.cv_scores_:
63+
for params, mean_score, scores in clf.grid_scores_:
6464
print("%0.3f (+/-%0.03f) for %r"
6565
% (mean_score, scores.std() / 2, params))
6666
print()

examples/plot_rfe_with_cross_validation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
pl.figure()
3333
pl.xlabel("Number of features selected")
3434
pl.ylabel("Cross validation score (nb of misclassifications)")
35-
pl.plot(range(1, len(rfecv.cv_scores_) + 1), rfecv.cv_scores_)
35+
pl.plot(range(1, len(rfecv.grid_scores_) + 1), rfecv.grid_scores_)
3636
pl.show()

examples/randomized_search.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939

4040

4141
# Utility function to report best scores
42-
def report(cv_scores, n_top=3):
43-
top_scores = sorted(cv_scores, key=itemgetter(1), reverse=True)[:n_top]
42+
def report(grid_scores, n_top=3):
43+
top_scores = sorted(grid_scores, key=itemgetter(1), reverse=True)[:n_top]
4444
for i, score in enumerate(top_scores):
4545
print("Model with rank: {0}".format(i + 1))
4646
print("Mean validation score: {0:.3f} (std: {1:.3f})".format(
@@ -67,7 +67,7 @@ def report(cv_scores, n_top=3):
6767
random_search.fit(X, y)
6868
print("RandomizedSearchCV took %.2f seconds for %d candidates"
6969
" parameter settings." % ((time() - start), n_iter_search))
70-
report(random_search.cv_scores_)
70+
report(random_search.grid_scores_)
7171

7272
# use a full grid over all parameters
7373
param_grid = {"max_depth": [3, None],
@@ -82,5 +82,5 @@ def report(cv_scores, n_top=3):
8282
grid_search.fit(X, y)
8383

8484
print("GridSearchCV took %.2f seconds for %d candidate parameter settings."
85-
% (time() - start, len(grid_search.cv_scores_)))
86-
report(grid_search.cv_scores_)
85+
% (time() - start, len(grid_search.grid_scores_)))
86+
report(grid_search.grid_scores_)

examples/svm/plot_rbf_parameters.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@
105105
pl.axis('tight')
106106

107107
# plot the scores of the grid
108-
# cv_scores_ contains parameter settings and scores
109-
score_dict = grid.cv_scores_
108+
# grid_scores_ contains parameter settings and scores
109+
score_dict = grid.grid_scores_
110110

111111
# We extract just the scores
112112
scores = [x[1] for x in score_dict]

examples/svm/plot_svm_scale_c.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
cv=ShuffleSplit(n=n_samples, train_size=train_size,
132132
n_iter=250, random_state=1))
133133
grid.fit(X, y)
134-
scores = [x[1] for x in grid.cv_scores_]
134+
scores = [x[1] for x in grid.grid_scores_]
135135

136136
scales = [(1, 'No scaling'),
137137
((n_samples * train_size), '1/n_samples'),

sklearn/covariance/graph_lasso_.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ class GraphLassoCV(GraphLasso):
422422
`cv_alphas_`: list of float
423423
All penalization parameters explored.
424424
425-
`cv_scores`: 2D numpy.ndarray (n_alphas, n_folds)
425+
`grid_scores`: 2D numpy.ndarray (n_alphas, n_folds)
426426
Log-likelihood score on left-out data across folds.
427427
428428
See Also
@@ -551,14 +551,14 @@ def fit(self, X, y=None):
551551
% (i + 1, n_refinements, time.time() - t0))
552552

553553
path = list(zip(*path))
554-
cv_scores = list(path[1])
554+
grid_scores = list(path[1])
555555
alphas = list(path[0])
556556
# Finally, compute the score with alpha = 0
557557
alphas.append(0)
558-
cv_scores.append(cross_val_score(EmpiricalCovariance(), X,
558+
grid_scores.append(cross_val_score(EmpiricalCovariance(), X,
559559
cv=cv, n_jobs=self.n_jobs,
560560
verbose=inner_verbose))
561-
self.cv_scores = np.array(cv_scores)
561+
self.grid_scores = np.array(grid_scores)
562562
best_alpha = alphas[best_index]
563563
self.alpha_ = best_alpha
564564
self.cv_alphas_ = alphas

sklearn/feature_selection/rfe.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,9 @@ class RFECV(RFE, MetaEstimatorMixin):
261261
Selected (i.e., estimated best)
262262
features are assigned rank 1.
263263
264-
`cv_scores_` : array of shape [n_subsets_of_features]
264+
`grid_scores_` : array of shape [n_subsets_of_features]
265265
The cross-validation scores such that
266-
`cv_scores_[i]` corresponds to
266+
`grid_scores_[i]` corresponds to
267267
the CV score of the i-th subset of features.
268268
269269
`estimator_` : object
@@ -373,5 +373,5 @@ def fit(self, X, y):
373373
self.estimator_.set_params(**self.estimator_params)
374374
self.estimator_.fit(self.transform(X), y)
375375

376-
self.cv_scores_ = scores / n
376+
self.grid_scores_ = scores / n
377377
return self

sklearn/feature_selection/tests/test_rfe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def test_rfecv():
7272
rfecv = RFECV(estimator=SVC(kernel="linear"), step=1, cv=3)
7373
rfecv.fit(X, y)
7474
# non-regression test for missing worst feature:
75-
assert_equal(len(rfecv.cv_scores_), X.shape[1])
75+
assert_equal(len(rfecv.grid_scores_), X.shape[1])
7676
assert_equal(len(rfecv.ranking_), X.shape[1])
7777
X_r = rfecv.transform(X)
7878

sklearn/grid_search.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -488,8 +488,8 @@ def _fit(self, X, y, parameter_iterable):
488488
n_jobs=self.n_jobs, verbose=self.verbose,
489489
pre_dispatch=pre_dispatch)(
490490
delayed(fit_grid_point)(
491-
X, y, base_estimator, parameters, train, test, self.scorer_,
492-
self.verbose, **self.fit_params)
491+
X, y, base_estimator, parameters, train, test,
492+
self.scorer_, self.verbose, **self.fit_params)
493493
for parameters in parameter_iterable
494494
for train, test in cv)
495495

@@ -498,7 +498,7 @@ def _fit(self, X, y, parameter_iterable):
498498
n_folds = len(cv)
499499

500500
scores = list()
501-
cv_scores = list()
501+
grid_scores = list()
502502
for grid_start in range(0, n_fits, n_folds):
503503
n_test_samples = 0
504504
score = 0
@@ -516,16 +516,16 @@ def _fit(self, X, y, parameter_iterable):
516516
score /= float(n_folds)
517517
scores.append((score, parameters))
518518
# TODO: shall we also store the test_fold_sizes?
519-
cv_scores.append(_CVScoreTuple(
519+
grid_scores.append(_CVScoreTuple(
520520
parameters,
521521
score,
522522
np.array(all_scores)))
523523
# Store the computed scores
524-
self.cv_scores_ = cv_scores
524+
self.grid_scores_ = grid_scores
525525

526526
# Find the best parameters by comparing on the mean validation score:
527527
# note that `sorted` is deterministic in the way it breaks ties
528-
best = sorted(cv_scores, key=lambda x: x.mean_validation_score,
528+
best = sorted(grid_scores, key=lambda x: x.mean_validation_score,
529529
reverse=True)[0]
530530
self.best_params_ = best.parameters
531531
self.best_score_ = best.mean_validation_score
@@ -630,7 +630,7 @@ class GridSearchCV(BaseSearchCV):
630630
631631
Attributes
632632
----------
633-
`cv_scores_` : list of named tuples
633+
`grid_scores_` : list of named tuples
634634
Contains scores for all parameter combinations in param_grid.
635635
Each entry corresponds to one parameter setting.
636636
Each named tuple has the attributes:
@@ -685,12 +685,6 @@ def __init__(self, estimator, param_grid, scoring=None, loss_func=None,
685685
self.param_grid = param_grid
686686
_check_param_grid(param_grid)
687687

688-
@property
689-
def grid_scores_(self):
690-
warnings.warn("grid_scores_ is deprecated and will be removed in 0.15."
691-
" Use cv_scores_ instead.", DeprecationWarning)
692-
return self.cv_scores_
693-
694688
def fit(self, X, y=None, **params):
695689
"""Run fit with all sets of parameters.
696690
@@ -789,7 +783,7 @@ class RandomizedSearchCV(BaseSearchCV):
789783
790784
Attributes
791785
----------
792-
`cv_scores_` : list of named tuples
786+
`grid_scores_` : list of named tuples
793787
Contains scores for all parameter combinations in param_grid.
794788
Each entry corresponds to one parameter setting.
795789
Each named tuple has the attributes:

sklearn/tests/test_grid_search.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def test_grid_search():
157157
assert_equal(grid_search.best_estimator_.foo_param, 2)
158158

159159
for i, foo_i in enumerate([1, 2, 3]):
160-
assert_true(grid_search.cv_scores_[i][0]
160+
assert_true(grid_search.grid_scores_[i][0]
161161
== {'foo_param': foo_i})
162162
# Smoke test the score etc:
163163
grid_search.score(X, y)
@@ -194,19 +194,19 @@ def test_grid_search_no_score():
194194
GridSearchCV, clf_no_score, {'C': Cs})
195195

196196

197-
def test_trivial_cv_scores():
197+
def test_trivial_grid_scores():
198198
"""Test search over a "grid" with only one point.
199199
200-
Non-regression test: cv_scores_ wouldn't be set by GridSearchCV.
200+
Non-regression test: grid_scores_ wouldn't be set by GridSearchCV.
201201
"""
202202
clf = MockClassifier()
203203
grid_search = GridSearchCV(clf, {'foo_param': [1]})
204204
grid_search.fit(X, y)
205-
assert_true(hasattr(grid_search, "cv_scores_"))
205+
assert_true(hasattr(grid_search, "grid_scores_"))
206206

207207
random_search = RandomizedSearchCV(clf, {'foo_param': [0]})
208208
random_search.fit(X, y)
209-
assert_true(hasattr(random_search, "cv_scores_"))
209+
assert_true(hasattr(random_search, "grid_scores_"))
210210

211211

212212
def test_no_refit():
@@ -245,7 +245,7 @@ def test_grid_search_iid():
245245
# once with iid=True (default)
246246
grid_search = GridSearchCV(svm, param_grid={'C': [1, 10]}, cv=cv)
247247
grid_search.fit(X, y)
248-
first = grid_search.cv_scores_[0]
248+
first = grid_search.grid_scores_[0]
249249
assert_equal(first.parameters['C'], 1)
250250
assert_array_almost_equal(first.cv_validation_scores, [1, 1. / 3.])
251251
# for first split, 1/4 of dataset is in test, for second 3/4.
@@ -257,7 +257,7 @@ def test_grid_search_iid():
257257
grid_search = GridSearchCV(svm, param_grid={'C': [1, 10]}, cv=cv,
258258
iid=False)
259259
grid_search.fit(X, y)
260-
first = grid_search.cv_scores_[0]
260+
first = grid_search.grid_scores_[0]
261261
assert_equal(first.parameters['C'], 1)
262262
# scores are the same as above
263263
assert_array_almost_equal(first.cv_validation_scores, [1, 1. / 3.])
@@ -471,7 +471,7 @@ def test_X_as_list():
471471
cv = KFold(n=len(X), n_folds=3)
472472
grid_search = GridSearchCV(clf, {'foo_param': [1, 2, 3]}, cv=cv)
473473
grid_search.fit(X.tolist(), y).score(X, y)
474-
assert_true(hasattr(grid_search, "cv_scores_"))
474+
assert_true(hasattr(grid_search, "grid_scores_"))
475475

476476

477477
def test_unsupervised_grid_search():
@@ -511,7 +511,7 @@ def test_param_sampler():
511511
assert_true(0 <= sample["C"] <= 1)
512512

513513

514-
def test_randomized_search_cv_scores():
514+
def test_randomized_search_grid_scores():
515515
# Make a dataset with a lot of noise to get various kind of prediction
516516
# errors across CV folds and parameter settings
517517
X, y = make_classification(n_samples=200, n_features=100, n_informative=3,
@@ -527,10 +527,10 @@ def test_randomized_search_cv_scores():
527527
search = RandomizedSearchCV(SVC(), n_iter=n_search_iter, cv=n_cv_iter,
528528
param_distributions=params, iid=False)
529529
search.fit(X, y)
530-
assert_equal(len(search.cv_scores_), n_search_iter)
530+
assert_equal(len(search.grid_scores_), n_search_iter)
531531

532532
# Check consistency of the structure of each cv_score item
533-
for cv_score in search.cv_scores_:
533+
for cv_score in search.grid_scores_:
534534
assert_equal(len(cv_score.cv_validation_scores), n_cv_iter)
535535
# Because we set iid to False, the mean_validation score is the
536536
# mean of the fold mean scores instead of the aggregate sample-wise
@@ -541,12 +541,12 @@ def test_randomized_search_cv_scores():
541541
list(sorted(params.keys())))
542542

543543
# Check the consistency with the best_score_ and best_params_ attributes
544-
sorted_cv_scores = list(sorted(search.cv_scores_,
544+
sorted_grid_scores = list(sorted(search.grid_scores_,
545545
key=lambda x: x.mean_validation_score))
546-
best_score = sorted_cv_scores[-1].mean_validation_score
546+
best_score = sorted_grid_scores[-1].mean_validation_score
547547
assert_equal(search.best_score_, best_score)
548548

549-
tied_best_params = [s.parameters for s in sorted_cv_scores
549+
tied_best_params = [s.parameters for s in sorted_grid_scores
550550
if s.mean_validation_score == best_score]
551551
assert_true(search.best_params_ in tied_best_params,
552552
"best_params_={0} is not part of the"
@@ -563,7 +563,7 @@ def test_grid_search_score_consistency():
563563
grid_search = GridSearchCV(clf, {'C': Cs}, scoring=score)
564564
grid_search.fit(X, y)
565565
cv = StratifiedKFold(n_folds=3, y=y)
566-
for C, scores in zip(Cs, grid_search.cv_scores_):
566+
for C, scores in zip(Cs, grid_search.grid_scores_):
567567
clf.set_params(C=C)
568568
scores = scores[2] # get the separate runs from grid scores
569569
i = 0
@@ -607,7 +607,7 @@ def test_grid_search_with_multioutput_data():
607607
for est in estimators:
608608
grid_search = GridSearchCV(est, est_parameters, cv=cv)
609609
grid_search.fit(X, y)
610-
for parameters, _, cv_validation_scores in grid_search.cv_scores_:
610+
for parameters, _, cv_validation_scores in grid_search.grid_scores_:
611611
est.set_params(**parameters)
612612

613613
for i, (train, test) in enumerate(cv):
@@ -620,7 +620,7 @@ def test_grid_search_with_multioutput_data():
620620
for est in estimators:
621621
random_search = RandomizedSearchCV(est, est_parameters, cv=cv)
622622
random_search.fit(X, y)
623-
for parameters, _, cv_validation_scores in random_search.cv_scores_:
623+
for parameters, _, cv_validation_scores in random_search.grid_scores_:
624624
est.set_params(**parameters)
625625

626626
for i, (train, test) in enumerate(cv):
@@ -633,7 +633,7 @@ def test_grid_search_with_multioutput_data():
633633
for est in estimators:
634634
random_search = RandomizedSearchCV(est, est_parameters, cv=cv)
635635
random_search.fit(X, y)
636-
for parameters, _, cv_validation_scores in random_search.cv_scores_:
636+
for parameters, _, cv_validation_scores in random_search.grid_scores_:
637637
est.set_params(**parameters)
638638

639639
for i, (train, test) in enumerate(cv):

0 commit comments

Comments
 (0)
0