Пример #1
0
def test_predict():
    from EvoDAG import RootGP
    y = cl.copy()
    mask = y == 0
    y[mask] = 1
    y[~mask] = -1
    function_set = [
        x for x in RootGP()._function_set if x.regression and x.nargs
    ]
    gp = RootGP(generations=np.inf,
                tournament_size=2,
                function_set=function_set,
                early_stopping_rounds=-1,
                classifier=False,
                remove_raw_inputs=False,
                seed=0,
                popsize=10).fit(X[:-10], y[:-10], test_set=X[-10:])
    es = gp.population.estopping
    assert gp.decision_function().SSE(es.hy_test) == 0
    hy_test = es.hy_test
    assert gp.decision_function(X=X[-10:]).SSE(hy_test) == 0
    hy = gp.decision_function(X=X[-10:])
    _ = gp.predict(X=X[-10:])
    assert SparseArray.fromlist(_).SSE(hy) == 0
    assert len(gp.Xtest)
Пример #2
0
def test_multiclass_predict():
    from EvoDAG import RootGP
    y = cl.copy()
    y[y == 0] = 3
    gp = RootGP(generations=np.inf,
                tournament_size=2,
                early_stopping_rounds=-1,
                seed=0,
                popsize=100).fit(X, y, test_set=X)
    d = gp.predict()
    assert np.unique(d).shape[0] == np.unique(y).shape[0]
    assert np.all(np.unique(d) == np.unique(y))
Пример #3
0
def test_regression():
    from EvoDAG import RootGP
    x = np.linspace(-1, 1, 100)
    y = 4.3 * x**2 + 3.2 * x - 3.2
    gp = RootGP(classifier=False, popsize=10,
                generations=2).fit([SparseArray.fromlist(x)],
                                   y,
                                   test_set=[SparseArray.fromlist(x)])
    model = gp.model()
    yh = gp.predict()
    assert not model._classifier
    yh1 = model.predict(X=[SparseArray.fromlist(x)])
    spf = SparseArray.fromlist
    assert spf(yh).SSE(spf(yh1)) == 0
Пример #4
0
def test_regression():
    from EvoDAG import RootGP
    from EvoDAG.sparse_array import SparseArray
    x = np.linspace(-1, 1, 100)
    y = 4.3*x**2 + 3.2 * x - 3.2
    gp = RootGP(classifier=False,
                popsize=10,
                generations=2).fit([SparseArray.fromlist(x)], y,
                                   test_set=[SparseArray.fromlist(x)])
    model = gp.model()
    yh = gp.predict()
    assert not model._classifier
    yh1 = model.predict(X=[SparseArray.fromlist(x)])
    spf = SparseArray.fromlist
    assert spf(yh).SSE(spf(yh1)) == 0
Пример #5
0
def test_RSE():
    from EvoDAG import RootGP
    from EvoDAG.utils import RSE as rse
    x = np.linspace(-1, 1, 100)
    y = 4.3 * x**2 + 3.2 * x - 3.2
    y[10:12] = 0
    gp = RootGP(classifier=False, popsize=10,
                generations=2).fit([SparseArray.fromlist(x)],
                                   y,
                                   test_set=[SparseArray.fromlist(x)])
    model = gp.model()
    yh = gp.predict()
    assert not model._classifier
    model.predict(X=[SparseArray.fromlist(x)])
    gp._mask = SparseArray.fromlist([2] * yh.shape[0])
    gp._bagging_fitness.fitness_vs(model._hist[-1])
    print(rse(y, yh), model._hist[-1].fitness_vs)
    assert_almost_equals(rse(y, yh), -model._hist[-1].fitness_vs)
Пример #6
0
def test_predict():
    from EvoDAG import RootGP
    y = cl.copy()
    mask = y == 0
    y[mask] = 1
    y[~mask] = -1
    gp = RootGP(generations=np.inf,
                tournament_size=2,
                early_stopping_rounds=-1,
                seed=0,
                popsize=10).fit(X[:-10], y[:-10], test_set=X[-10:])
    es = gp.population.estopping
    assert gp.decision_function().SSE(es.hy_test.boundaries()) == 0
    hy_test = es.hy_test.boundaries()
    assert gp.decision_function(X=X[-10:]).SSE(hy_test) == 0
    hy = gp.decision_function(X=X[-10:])
    _ = gp.predict(X=X[-10:])
    assert SparseArray.fromlist(_).SSE(hy.sign()) == 0
    assert len(gp.Xtest)
Пример #7
0
def test_RSE():
    from EvoDAG import RootGP
    from EvoDAG.sparse_array import SparseArray
    from EvoDAG.utils import RSE as rse
    x = np.linspace(-1, 1, 100)
    y = 4.3*x**2 + 3.2 * x - 3.2
    y[10:12] = 0
    gp = RootGP(classifier=False,
                popsize=10,
                generations=2).fit([SparseArray.fromlist(x)], y,
                                   test_set=[SparseArray.fromlist(x)])
    model = gp.model()
    yh = gp.predict()
    assert not model._classifier
    model.predict(X=[SparseArray.fromlist(x)])
    gp._mask = SparseArray.fromlist([2] * yh.shape[0])
    gp.fitness_vs(model._hist[-1])
    print(rse(y, yh), model._hist[-1].fitness_vs)
    assert_almost_equals(rse(y, yh),
                         -model._hist[-1].fitness_vs)