def test_predict_example_data(test_input): """Test learn and predict.""" train, test = load_toy_cancer() _bk = Background(modes=train.modes) _dn = BoostedRDN(background=_bk, target="cancer", n_estimators=test_input) _dn.fit(train) assert_array_equal(_dn.predict(test), np.array([1.0, 1.0, 1.0, 0.0, 0.0]))
def test_predict_example_data(test_input): """Test learn and predict.""" _bk = Background(modes=example_data.train.modes, use_std_logic_variables=True) _dn = BoostedRDN(background=_bk, target="cancer", n_estimators=test_input) _dn.fit(example_data.train) assert_array_equal(_dn.predict(example_data.test), np.array([1.0, 1.0, 1.0, 0.0, 0.0]))
def test_toy_cancer_predict_after_load(test_input): """Load a ToyCancer json file and predict.""" clf = BoostedRDN() clf.from_json( "srlearn/tests/regression_tests/json/toy_cancer_{0}.json".format( test_input)) _, test = load_toy_cancer() _predictions = clf.predict(test) assert_array_equal(_predictions, np.array([1.0, 1.0, 1.0, 0.0, 0.0]))
def test_serialize_BoostedRDN(tmpdir): """Test that inference is possible after loading from json""" output_json = tmpdir.join("ToyCancerRDN.json") train, test = load_toy_cancer() bkg = Background(modes=train.modes) rdn = BoostedRDN(background=bkg, target="cancer", n_estimators=5) rdn.fit(train) rdn.to_json(output_json) # New BoostedRDN instance, loading from file, and running. rdn2 = BoostedRDN() rdn2.from_json(output_json) _predictions = rdn2.predict(test) assert len(rdn2.estimators_) == 5 assert_array_equal(_predictions, np.array([1.0, 1.0, 1.0, 0.0, 0.0]))