def test__clf_with_no_proba_fail(): X, y = iris_data() clf = OneRClassifier() clf.fit(X, y) x_ref = X[15] s = ("Your `model` does not support " "`predict_proba`. Set `y_desired_proba` " " to `None` to use `predict`instead.") assert_raises(AttributeError, s, create_counterfactual, x_ref, 2, clf, X, 1., 100, 123)
def test_iris_quartiles_resolve_ties_chi_squared_2(): # tests with duplicate column oner = OneRClassifier(resolve_ties='chi-squared') Xd_traintemp = np.zeros((Xd_train.shape[0], Xd_train.shape[1]+1)) Xd_traintemp[:, 0] = Xd_train[:, 2] Xd_traintemp[:, 1] = Xd_train[:, 0] Xd_traintemp[:, 2] = Xd_train[:, 1] Xd_traintemp[:, 3] = Xd_train[:, 2] Xd_traintemp[:, 4] = Xd_train[:, 3] oner.fit(Xd_traintemp, y_train) assert oner.feature_idx_ == 0 assert oner.prediction_dict_['total error'] == 16 assert round(oner.score(Xd_traintemp, y_train), 4) == 0.8571
def test_iris_quartiles_resolve_ties_first(): oner = OneRClassifier() oner.fit(Xd_train, y_train) assert oner.feature_idx_ == 2 assert oner.prediction_dict_['total error'] == 16 assert round(oner.score(Xd_train, y_train), 4) == 0.8571 assert round(oner.score(Xd_test, y_test), 4) == 0.8421
def test_iris_quartiles_resolve_ties_chi_squared_1(): oner = OneRClassifier(resolve_ties='chi-squared') oner.fit(Xd_train, y_train) assert oner.feature_idx_ == 2 assert oner.prediction_dict_['total error'] == 16 assert round(oner.score(Xd_train, y_train), 4) == 0.8571 assert round(oner.score(Xd_test, y_test), 4) == 0.8421 np.testing.assert_almost_equal(oner.p_value_, 0.0, decimal=7)
def test__clf_with_no_proba_pass(): X, y = iris_data() clf = OneRClassifier() clf.fit(X, y) x_ref = X[15] res = create_counterfactual(x_reference=x_ref, y_desired=2, model=clf, X_dataset=X, y_desired_proba=None, lammbda=100, random_seed=123) assert clf.predict(x_ref.reshape(1, -1)) == 0 assert clf.predict(res.reshape(1, -1)) == 2