Esempio n. 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)
Esempio n. 2
0
 def test_fit_bad_y(self, data, estimator, X_y):
     X, y = X_y
     y = y[:, 0].flatten()
     target_to_features_dict = data.draw(
         numeric_target_to_features_dicts(n_targets=1,
                                          n_features=X.shape[1]))
     multi_feature_multi_output_regressor = MultiFeatureMultiOutputRegressor(
         estimator, target_to_features_dict=target_to_features_dict)
     with pytest.raises(ValueError):
         multi_feature_multi_output_regressor.fit(X, y)
Esempio n. 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
Esempio n. 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),
        )
Esempio n. 5
0
 def test_predict_target_to_features_dict(self, data, X_y, estimator):
     X, y = X_y
     target_to_features_dict = data.draw(
         numeric_target_to_features_dicts(n_targets=y.shape[1],
                                          n_features=X.shape[1]))
     multi_feature_multi_output_regressor = MultiFeatureMultiOutputRegressor(
         estimator)
     multi_feature_multi_output_regressor.target_to_features_dict = (
         target_to_features_dict)
     multi_feature_multi_output_regressor.fit(X, y)
     X_predict = data.draw(numpy_X_matrices([100, X.shape[1]]))
     multi_feature_multi_output_regressor.predict(X_predict)
Esempio n. 6
0
 def test_error_predict_target_to_features_dict_wrong_X_shape(
         self, data, X_y, estimator):
     X, y = X_y
     target_to_features_dict = data.draw(
         numeric_target_to_features_dicts(n_targets=y.shape[1],
                                          n_features=X.shape[1]))
     multi_feature_multi_output_regressor = MultiFeatureMultiOutputRegressor(
         estimator, target_to_features_dict=target_to_features_dict)
     multi_feature_multi_output_regressor.fit(X, y)
     X_predict = data.draw(numpy_X_matrices([100, 30]))
     with pytest.raises(ValueError):
         multi_feature_multi_output_regressor.predict(X_predict)
Esempio n. 7
0
 def test_constructor(self, estimator):
     multi_feature_multi_output_regressor = MultiFeatureMultiOutputRegressor(
         estimator)
     assert multi_feature_multi_output_regressor.n_jobs == 1
Esempio n. 8
0
 def test_error_predict_with_no_fit(self, estimator, X):
     regressor = MultiFeatureMultiOutputRegressor(estimator)
     with pytest.raises(NotFittedError):
         regressor.predict(X)