Exemple #1
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)
Exemple #2
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)
Exemple #3
0
class TestMultiFeatureMultiOutputRegressor:
    def test_constructor(self, estimator):
        multi_feature_multi_output_regressor = MultiFeatureMultiOutputRegressor(
            estimator
        )
        assert multi_feature_multi_output_regressor.n_jobs == 1

    @given(data=data(), X_y=numpy_X_y_matrices(min_value=-10000, max_value=10000))
    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
            )

    @given(X_y=numpy_X_y_matrices(min_value=-10000, max_value=10000))
    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),
        )

    @given(X=numpy_X_matrix(min_value=-10000, max_value=10000))
    def test_error_predict_with_no_fit(self, estimator, X):
        regressor = MultiFeatureMultiOutputRegressor(estimator)
        with pytest.raises(NotFittedError):
            regressor.predict(X)

    @given(data=data(), X_y=numpy_X_y_matrices(min_value=-10000, max_value=10000))
    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
        )

    @given(
        data=data(), X_y=numpy_X_y_matrices(min_value=-10000, max_value=10000),
    )
    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

    @given(
        data=data(), X_y=numpy_X_y_matrices(min_value=-10000, max_value=10000),
    )
    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)

    @given(
        data=data(), X_y=numpy_X_y_matrices(min_value=-10000, max_value=10000),
    )
    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)
Exemple #4
0
 def test_no_infinity(self, data, shape):
     X = data.draw(numpy_X_matrix(shape, allow_nan=True, allow_infinity=False))
     assert not np.isinf(X).any()
Exemple #5
0
 def test_min_max_values(self, data, shape, min_max_values):
     min_value, max_value = min_max_values
     X = data.draw(numpy_X_matrix(shape, min_value=min_value, max_value=max_value))
     assert X.min() >= min_value
     assert X.max() <= max_value
Exemple #6
0
 def test_error_shape_0_smaller_shape_1(self, data):
     with pytest.raises(ValueError):
         data.draw(numpy_X_matrix([10, 20]))
Exemple #7
0
 def test_input_as_strategy(self, data):
     data.draw(numpy_X_matrix(shape_matrix()))
Exemple #8
0
 def test_input_as_tuples(self, data, shape):
     X = data.draw(numpy_X_matrix(shape))
     assert X.shape == shape