def test_few_fit_shapes():
"""test_few.py: fit and predict return correct shapes """
np.random.seed(202)
# load example data
boston = load_boston()
d = pd.DataFrame(data=boston.data)
print("feature shape:",boston.data.shape)
learner = FEW(generations=1, population_size=5,
mutation_rate=0.2, crossover_rate=0.8,
ml = LassoLarsCV(), min_depth = 1, max_depth = 3,
sel = 'epsilon_lexicase', tourn_size = 2,
random_state=0, verbosity=0,
disable_update_check=False, fit_choice = 'mse')
score = learner.fit(boston.data[:300], boston.target[:300])
print("learner:",learner._best_estimator)
yhat_test = learner.predict(boston.data[300:])
test_score = learner.score(boston.data[300:],boston.target[300:])
print("train score:",score,"test score:",test_score,
"test r2:",r2_score(boston.target[300:],yhat_test))
assert yhat_test.shape == boston.target[300:].shape
评论列表
文章目录