示例#1
0
 def test_fit_target_to_feature_dict_working(self, data, X_y, estimator):
     X, y = X_y
     target_to_feature_dict = data.draw(
         numeric_target_to_feature_dicts(n_targets=y.shape[1], n_features=X.shape[1])
     )
     multi_feature_multi_output_regressor = MultiFeatureMultiOutputRegressor(
         estimator
     )
     multi_feature_multi_output_regressor.fit(
         X, y, target_to_features_dict=target_to_feature_dict
     )
示例#2
0
 def test_fit_bad_y(self, data, estimator, X_y):
     X, y = X_y
     y = y[:, 0].flatten()
     target_to_feature_dict = data.draw(
         numeric_target_to_feature_dicts(n_targets=1, n_features=X.shape[1])
     )
     multi_feature_multi_output_regressor = MultiFeatureMultiOutputRegressor(
         estimator
     )
     with pytest.raises(ValueError):
         multi_feature_multi_output_regressor.fit(
             X, y, target_to_features_dict=target_to_feature_dict
         )
示例#3
0
 def test_fit_target_to_feature_dict_consistent(self, data, X_y, estimator):
     X, y = X_y
     target_to_feature_dict = data.draw(
         numeric_target_to_feature_dicts(n_targets=y.shape[1], n_features=X.shape[1])
     )
     multi_feature_multi_output_regressor = MultiFeatureMultiOutputRegressor(
         estimator
     )
     multi_feature_multi_output_regressor.fit(
         X, y, target_to_features_dict=target_to_feature_dict
     )
     for i, estimator_ in enumerate(
         multi_feature_multi_output_regressor.estimators_
     ):
         expected_n_features = len(target_to_feature_dict[i])
         assert len(estimator_.coef_) == expected_n_features
示例#4
0
    def test_fit_as_multi_output_regressor_if_target_to_feature_none(
        self, estimator, X_y
    ):
        X, y = X_y
        multi_feature_multi_output_regressor = MultiFeatureMultiOutputRegressor(
            estimator
        )
        multi_feature_multi_output_regressor.fit(X, y)

        multi_output_regressor = MultiOutputRegressor(estimator)
        multi_output_regressor.fit(X, y)

        assert_almost_equal(
            multi_feature_multi_output_regressor.predict(X),
            multi_output_regressor.predict(X),
        )
示例#5
0
 def test_predict_target_to_feature_dict(self, data, X_y, estimator):
     X, y = X_y
     target_to_feature_dict = data.draw(
         numeric_target_to_feature_dicts(n_targets=y.shape[1], n_features=X.shape[1])
     )
     multi_feature_multi_output_regressor = MultiFeatureMultiOutputRegressor(
         estimator
     )
     multi_feature_multi_output_regressor.fit(
         X, y, target_to_features_dict=target_to_feature_dict
     )
     X_predict = data.draw(numpy_X_matrix([100, X.shape[1]]))
     multi_feature_multi_output_regressor.predict(X_predict)
示例#6
0
 def test_error_predict_target_to_feature_dict_wrong_X_shape(
     self, data, X_y, estimator
 ):
     X, y = X_y
     target_to_feature_dict = data.draw(
         numeric_target_to_feature_dicts(n_targets=y.shape[1], n_features=X.shape[1])
     )
     multi_feature_multi_output_regressor = MultiFeatureMultiOutputRegressor(
         estimator
     )
     multi_feature_multi_output_regressor.fit(
         X, y, target_to_features_dict=target_to_feature_dict
     )
     X_predict = data.draw(numpy_X_matrix([100, 30]))
     with pytest.raises(ValueError):
         multi_feature_multi_output_regressor.predict(X_predict)
示例#7
0
 def test_error_predict_with_no_fit(self, estimator, X):
     regressor = MultiFeatureMultiOutputRegressor(estimator)
     with pytest.raises(NotFittedError):
         regressor.predict(X)
示例#8
0
 def test_constructor(self, estimator):
     multi_feature_multi_output_regressor = MultiFeatureMultiOutputRegressor(
         estimator
     )
     assert multi_feature_multi_output_regressor.n_jobs == 1