def test_few_at_least_as_good_as_default():
"""test_few.py: few performs at least as well as the default ML """
np.random.seed(1006987)
boston = load_boston()
d = np.column_stack((boston.data,boston.target))
np.random.shuffle(d)
features = d[:,0:-1]
target = d[:,-1]
print("feature shape:",boston.data.shape)
learner = FEW(generations=1, population_size=5,
ml = LassoLarsCV(), min_depth = 1, max_depth = 3,
sel = 'tournament')
learner.fit(features[:300], target[:300])
few_score = learner.score(features[:300], target[:300])
few_test_score = learner.score(features[300:],target[300:])
lasso = LassoLarsCV()
lasso.fit(features[:300], target[:300])
lasso_score = lasso.score(features[:300], target[:300])
lasso_test_score = lasso.score(features[300:],target[300:])
print("few score:",few_score,"lasso score:",lasso_score)
print("few test score:",few_test_score,"lasso test score:",
lasso_test_score)
assert round(few_score,8) >= round(lasso_score,8)
print("lasso coefficients:",lasso.coef_)
# assert False
评论列表
文章目录