def test_logging(): from EvoDAG.model import EvoDAG as evodag y = cl.copy() mask = y == 0 y[mask] = 1 y[~mask] = -1 evodag(generations=np.inf, tournament_size=2, early_stopping_rounds=-1, classifier=False, seed=0, popsize=10).fit(X, y, test_set=X)
def test_regression(): from EvoDAG.model import EvoDAG as evodag x = np.linspace(-1, 1, 100) y = 4.3 * x**2 + 3.2 * x - 3.2 gp = evodag(classifier=False, popsize=10, generations=2).fit([SparseArray.fromlist(x)], y, test_set=[SparseArray.fromlist(x)]) model = gp.model yh = gp.predict([SparseArray.fromlist(x)]) assert not model._classifier yh1 = model.predict(X=[SparseArray.fromlist(x)]) spf = SparseArray.fromlist assert spf(yh).SSE(spf(yh1)) == 0
def test_ensemble_model(): from EvoDAG.model import EvoDAG as evodag from EvoDAG.model import Ensemble y = cl.copy() mask = y == 0 y[mask] = 1 y[~mask] = -1 gps = [ evodag(generations=np.inf, tournament_size=2, early_stopping_rounds=-1, classifier=False, seed=seed, popsize=10).fit(X[:-10], y[:-10], test_set=X) for seed in range(3) ] ens = Ensemble([gp.model for gp in gps]) res = [gp.decision_function(X) for gp in gps] res = np.median([x.finite().full_array() for x in res], axis=0) r2 = ens.decision_function(X) print(res, r2) assert np.fabs(res - r2).mean() == 0
def test_probability_calibration_ensemble(): class C(object): def __init__(self): pass def fit(self, X, y): self._X = X return self def predict_proba(self, X): return np.array([[0, 1], [0.5, 0.5], [1, 0]]) from EvoDAG.model import EvoDAGE as evodag model = evodag(time_limit=4, early_stopping_rounds=10, probability_calibration=C).fit(X, cl) for m in model.models: assert isinstance(m._probability_calibration, C) assert model.probability_calibration hy = model.predict_proba(X) pr = np.array([[0, 1], [0.5, 0.5], [1, 0]]) assert np.fabs(hy - pr).sum() == 0 default_nargs()