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]))
Esempio n. 2
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]))