def test_fit_target_to_feature_dict_working(self, data, X_y, estimator): X, y = X_y X_train, y_train, X_test, y_test = FeatureSplitter().transform(X, y) target_to_feature_dict = data.draw( str_target_to_feature_dicts(targets=y.columns, features=X.columns) ) multi_feature_gar = MultiFeatureGAR(estimator) multi_feature_gar.fit(X_train, y_train, target_to_features_dict=target_to_feature_dict)
def test_predict_target_to_feature_dict_explainable( self, data, X_y, estimator): X, y = X_y X_train, y_train, X_test, y_test = FeatureSplitter().transform(X, y) target_to_feature_dict = data.draw( str_target_to_feature_dicts(targets=y.columns, features=X.columns)) multi_feature_gar = MultiFeatureGAR(estimator, explainer_type="shap") multi_feature_gar.target_to_features_dict = target_to_feature_dict multi_feature_gar.fit(X_train, y_train) multi_feature_gar.predict(X_test)
def test_fit_target_to_feature_dict_consistent(self, data, X_y, estimator): X, y = X_y X_train, y_train, X_test, y_test = FeatureSplitter().transform(X, y) target_to_feature_dict = data.draw( str_target_to_feature_dicts(targets=y.columns, features=X.columns) ) multi_feature_gar = MultiFeatureGAR(estimator) multi_feature_gar.fit(X_train, y_train, target_to_features_dict=target_to_feature_dict) for i, estimator_ in enumerate(multi_feature_gar.estimators_): expected_n_features = len(target_to_feature_dict[y.columns[i]]) assert len(estimator_.coef_) == expected_n_features
def test_error_predict_target_to_feature_dict_wrong_X_shape( self, data, X_y, estimator): X, y = X_y X_train, y_train, X_test, y_test = FeatureSplitter().transform(X, y) target_to_feature_dict = data.draw( str_target_to_feature_dicts(targets=y.columns, features=X.columns)) multi_feature_gar = MultiFeatureGAR( estimator, target_to_features_dict=target_to_feature_dict) multi_feature_gar.fit(X_train, y_train) X_test = X_test.iloc[:, :2] with pytest.raises(ValueError): multi_feature_gar.predict(X_test)
def test_fit_as_multi_output_regressor_if_target_to_feature_none( self, estimator, X_y ): X, y = X_y X_train, y_train, X_test, y_test = FeatureSplitter().transform(X, y) multi_feature_gar = MultiFeatureGAR(estimator) multi_feature_gar.fit(X_train, y_train) gar = GAR(estimator) gar.fit(X_train, y_train) pd.testing.assert_frame_equal( multi_feature_gar.predict(X_test), gar.predict(X_test), )