def test_predict_proba_test_data(): """Assert arrays are almost equal on output of predict_proba()""" _bk = Background(modes=example_data.train.modes, use_std_logic_variables=True) _dn = RDN(background=_bk, target="cancer", n_estimators=5) _dn.fit(example_data.train) assert_array_almost_equal( _dn.predict_proba(example_data.test), np.array([0.74, 0.74, 0.74, 0.25, 0.25]), decimal=2, )
target='cancer', max_tree_depth=2, node_size=2, n_estimators=20, ) clf.fit(example_data.train) x = np.arange(1, 21) y_pos = [] y_neg = [] thresholds = [] for n_trees in x: clf.set_params(n_estimators=n_trees) probs = clf.predict_proba(example_data.test) thresholds.append(clf.threshold_) y_pos.append(np.mean(probs[np.nonzero(clf.classes_)])) y_neg.append(np.mean(probs[clf.classes_ == 0])) thresholds = np.array(thresholds) y_pos = np.array(y_pos) y_neg = np.array(y_neg) plt.plot(x, y_pos, "b-", label="Mean Probability of positive examples") plt.plot(x, y_neg, "r-", label="Mean Probability of negative examples") plt.plot(x, thresholds, "k--", label="Margin") plt.title("Class Probability vs. Number Trees") plt.xlabel("Number of Trees") plt.ylabel("Probability of belonging to Positive Class")
test_db = Database() test_db.pos = [ "father(elizabeth,mrbennet).", "father(jane,mrbennet).", "father(charlotte,mrlucas).", ] test_db.neg = [ "father(charlotte,mrsbennet).", "father(jane,mrlucas).", "father(mrsbennet,mrbennet).", "father(jane,elizabeth).", ] test_db.facts = [ "male(mrbennet).", "male(mrlucas).", "male(darcy).", "childof(mrbennet,elizabeth).", "childof(mrsbennet,elizabeth).", "childof(mrbennet,jane).", "childof(mrsbennet,jane).", "childof(mrlucas,charlotte).", "childof(mrslucas,charlotte).", "siblingof(jane,elizabeth).", "siblingof(elizabeth,jane).", ] print(clf.predict_proba(test_db))