diff --git a/sklearn/ensemble/bagging.py b/sklearn/ensemble/bagging.py index cc7e1b95e89b3..7ea3030bdf120 100644 --- a/sklearn/ensemble/bagging.py +++ b/sklearn/ensemble/bagging.py @@ -773,8 +773,8 @@ def decision_function(self, X): if self.n_features_ != X.shape[1]: raise ValueError("Number of features of the model must " - "match the input. Model n_features is {1} and " - "input n_features is {2} " + "match the input. Model n_features is {0} and " + "input n_features is {1} " "".format(self.n_features_, X.shape[1])) # Parallel loop diff --git a/sklearn/ensemble/tests/test_bagging.py b/sklearn/ensemble/tests/test_bagging.py index c0a46d6c15036..e71462daa3a14 100644 --- a/sklearn/ensemble/tests/test_bagging.py +++ b/sklearn/ensemble/tests/test_bagging.py @@ -19,6 +19,7 @@ from sklearn.utils.testing import assert_false from sklearn.utils.testing import assert_warns from sklearn.utils.testing import assert_warns_message +from sklearn.utils.testing import assert_raise_message from sklearn.dummy import DummyClassifier, DummyRegressor from sklearn.model_selection import GridSearchCV, ParameterGrid @@ -449,6 +450,13 @@ def test_parallel_classification(): decisions2 = ensemble.decision_function(X_test) assert_array_almost_equal(decisions1, decisions2) + X_err = np.hstack((X_test, np.zeros((X_test.shape[0], 1)))) + assert_raise_message(ValueError, "Number of features of the model " + "must match the input. Model n_features is {0} " + "and input n_features is {1} " + "".format(X_test.shape[1], X_err.shape[1]), + ensemble.decision_function, X_err) + ensemble = BaggingClassifier(SVC(decision_function_shape='ovr'), n_jobs=1, random_state=0).fit(X_train, y_train) diff --git a/sklearn/multiclass.py b/sklearn/multiclass.py index 3ca3b1ad42a28..a8510cf0a0a85 100644 --- a/sklearn/multiclass.py +++ b/sklearn/multiclass.py @@ -721,7 +721,7 @@ def fit(self, X, y): """ X, y = check_X_y(X, y) if self.code_size <= 0: - raise ValueError("code_size should be greater than 0, got {1}" + raise ValueError("code_size should be greater than 0, got {0}" "".format(self.code_size)) _check_estimator(self.estimator) diff --git a/sklearn/tests/test_multiclass.py b/sklearn/tests/test_multiclass.py index 7008fff41aaa1..45222a1c12a68 100644 --- a/sklearn/tests/test_multiclass.py +++ b/sklearn/tests/test_multiclass.py @@ -704,6 +704,9 @@ def test_ecoc_float_y(): ovo = OutputCodeClassifier(LinearSVC()) assert_raise_message(ValueError, "Unknown label type", ovo.fit, X, y) + ovo = OutputCodeClassifier(LinearSVC(), code_size=-1) + assert_raise_message(ValueError, "code_size should be greater than 0," + " got -1", ovo.fit, X, y) def test_pairwise_indices():