本文整理汇总了Python中deap.tools.ParetoFront方法的典型用法代码示例。如果您正苦于以下问题:Python tools.ParetoFront方法的具体用法?Python tools.ParetoFront怎么用?Python tools.ParetoFront使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类deap.tools
的用法示例。
在下文中一共展示了tools.ParetoFront方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_update_top_pipeline_2
# 需要导入模块: from deap import tools [as 别名]
# 或者: from deap.tools import ParetoFront [as 别名]
def test_update_top_pipeline_2():
"""Assert that the TPOT _update_top_pipeline raises RuntimeError when self._pareto_front is empty."""
tpot_obj = TPOTClassifier(
random_state=42,
population_size=1,
offspring_size=2,
generations=1,
verbosity=0,
config_dict='TPOT light'
)
tpot_obj.fit(training_features, training_target)
def pareto_eq(ind1, ind2):
return np.allclose(ind1.fitness.values, ind2.fitness.values)
tpot_obj._pareto_front = ParetoFront(similar=pareto_eq)
assert_raises(RuntimeError, tpot_obj._update_top_pipeline)
示例2: main
# 需要导入模块: from deap import tools [as 别名]
# 或者: from deap.tools import ParetoFront [as 别名]
def main():
random.seed(64)
MU, LAMBDA = 50, 100
pop = toolbox.population(n=MU)
hof = tools.ParetoFront()
stats = tools.Statistics(lambda ind: ind.fitness.values)
stats.register("avg", numpy.mean, axis=0)
stats.register("std", numpy.std, axis=0)
stats.register("min", numpy.min, axis=0)
stats.register("max", numpy.max, axis=0)
algorithms.eaMuPlusLambda(pop, toolbox, mu=MU, lambda_=LAMBDA,
cxpb=0.5, mutpb=0.2, ngen=150,
stats=stats, halloffame=hof)
return pop, stats, hof
示例3: main
# 需要导入模块: from deap import tools [as 别名]
# 或者: from deap.tools import ParetoFront [as 别名]
def main():
# random.seed(64)
MU, LAMBDA = 100, 200
pop = toolbox.population(n=MU)
hof = tools.ParetoFront()
stats = tools.Statistics(lambda ind: ind.fitness.values)
stats.register("avg", numpy.mean, axis=0)
stats.register("std", numpy.std, axis=0)
stats.register("min", numpy.min, axis=0)
stats.register("max", numpy.max, axis=0)
pop, logbook = algorithms.eaMuPlusLambda(pop, toolbox, mu=MU, lambda_=LAMBDA,
cxpb=0.7, mutpb=0.3, ngen=40,
stats=stats, halloffame=hof)
return pop, logbook, hof
示例4: main
# 需要导入模块: from deap import tools [as 别名]
# 或者: from deap.tools import ParetoFront [as 别名]
def main():
random.seed(64)
NGEN = 50
MU = 50
LAMBDA = 100
CXPB = 0.7
MUTPB = 0.2
pop = toolbox.population(n=MU)
hof = tools.ParetoFront()
stats = tools.Statistics(lambda ind: ind.fitness.values)
stats.register("avg", numpy.mean, axis=0)
stats.register("std", numpy.std, axis=0)
stats.register("min", numpy.min, axis=0)
stats.register("max", numpy.max, axis=0)
algorithms.eaMuPlusLambda(pop, toolbox, MU, LAMBDA, CXPB, MUTPB, NGEN, stats,
halloffame=hof)
return pop, stats, hof
示例5: main
# 需要导入模块: from deap import tools [as 别名]
# 或者: from deap.tools import ParetoFront [as 别名]
def main():
NGEN = 40
MU = 100
LAMBDA = 200
CXPB = 0.3
MUTPB = 0.6
pop = toolbox.population(n=MU)
hof = tools.ParetoFront()
price_stats = tools.Statistics(key=lambda ind: ind.fitness.values[0])
time_stats = tools.Statistics(key=lambda ind: ind.fitness.values[1])
stats = tools.MultiStatistics(price=price_stats, time=time_stats)
stats.register("avg", numpy.mean, axis=0)
stats.register("std", numpy.std, axis=0)
stats.register("min", numpy.min, axis=0)
algorithms.eaMuPlusLambda(pop, toolbox, MU, LAMBDA, CXPB, MUTPB, NGEN,
stats, halloffame=hof)
return pop, stats, hof
示例6: test_evaluate_individuals
# 需要导入模块: from deap import tools [as 别名]
# 或者: from deap.tools import ParetoFront [as 别名]
def test_evaluate_individuals():
"""Assert that _evaluate_individuals returns operator_counts and CV scores in correct order."""
tpot_obj = TPOTClassifier(
random_state=42,
verbosity=0,
config_dict='TPOT light'
)
tpot_obj._fit_init()
def pareto_eq(ind1, ind2):
return np.allclose(ind1.fitness.values, ind2.fitness.values)
tpot_obj._pareto_front = ParetoFront(similar=pareto_eq)
tpot_obj._pbar = tqdm(total=1, disable=True)
pop = tpot_obj._toolbox.population(n=10)
pop = tpot_obj._evaluate_individuals(pop, training_features, training_target)
fitness_scores = [ind.fitness.values for ind in pop]
for deap_pipeline, fitness_score in zip(pop, fitness_scores):
operator_count = tpot_obj._operator_count(deap_pipeline)
sklearn_pipeline = tpot_obj._toolbox.compile(expr=deap_pipeline)
try:
with warnings.catch_warnings():
warnings.simplefilter('ignore')
cv_scores = model_selection.cross_val_score(sklearn_pipeline,
training_features,
training_target,
cv=5,
scoring='accuracy',
verbose=0,
error_score='raise')
mean_cv_scores = np.mean(cv_scores)
except Exception:
mean_cv_scores = -float('inf')
assert isinstance(deap_pipeline, creator.Individual)
assert np.allclose(fitness_score[0], operator_count)
assert np.allclose(fitness_score[1], mean_cv_scores)
示例7: test_evaluate_individuals_2
# 需要导入模块: from deap import tools [as 别名]
# 或者: from deap.tools import ParetoFront [as 别名]
def test_evaluate_individuals_2():
"""Assert that _evaluate_individuals returns operator_counts and CV scores in correct order with n_jobs=2"""
tpot_obj = TPOTClassifier(
n_jobs=2,
random_state=42,
verbosity=0,
config_dict='TPOT light'
)
tpot_obj._fit_init()
def pareto_eq(ind1, ind2):
return np.allclose(ind1.fitness.values, ind2.fitness.values)
tpot_obj._pareto_front = ParetoFront(similar=pareto_eq)
tpot_obj._pbar = tqdm(total=1, disable=True)
pop = tpot_obj._toolbox.population(n=10)
pop = tpot_obj._evaluate_individuals(pop, training_features, training_target)
fitness_scores = [ind.fitness.values for ind in pop]
for deap_pipeline, fitness_score in zip(pop, fitness_scores):
operator_count = tpot_obj._operator_count(deap_pipeline)
sklearn_pipeline = tpot_obj._toolbox.compile(expr=deap_pipeline)
try:
with warnings.catch_warnings():
warnings.simplefilter('ignore')
cv_scores = model_selection.cross_val_score(sklearn_pipeline,
training_features,
training_target,
cv=5,
scoring='accuracy',
verbose=0,
error_score='raise')
mean_cv_scores = np.mean(cv_scores)
except Exception:
mean_cv_scores = -float('inf')
assert isinstance(deap_pipeline, creator.Individual)
assert np.allclose(fitness_score[0], operator_count)
assert np.allclose(fitness_score[1], mean_cv_scores)
示例8: test_PolynomialFeatures_exception
# 需要导入模块: from deap import tools [as 别名]
# 或者: from deap.tools import ParetoFront [as 别名]
def test_PolynomialFeatures_exception():
"""Assert that TPOT allows only one PolynomialFeatures operator in a pipeline."""
tpot_obj._pbar = tqdm(total=1, disable=True)
def pareto_eq(ind1, ind2):
return np.allclose(ind1.fitness.values, ind2.fitness.values)
tpot_obj._pareto_front = ParetoFront(similar=pareto_eq)
# pipeline with one PolynomialFeatures operator
pipeline_string_1 = (
'LogisticRegression(PolynomialFeatures'
'(input_matrix, PolynomialFeatures__degree=2, PolynomialFeatures__include_bias=False, '
'PolynomialFeatures__interaction_only=False), LogisticRegression__C=10.0, '
'LogisticRegression__dual=False, LogisticRegression__penalty=l2)'
)
# pipeline with two PolynomialFeatures operator
pipeline_string_2 = (
'LogisticRegression(PolynomialFeatures'
'(PolynomialFeatures(input_matrix, PolynomialFeatures__degree=2, '
'PolynomialFeatures__include_bias=False, PolynomialFeatures__interaction_only=False), '
'PolynomialFeatures__degree=2, PolynomialFeatures__include_bias=False, '
'PolynomialFeatures__interaction_only=False), LogisticRegression__C=10.0, '
'LogisticRegression__dual=False, LogisticRegression__penalty=l2)'
)
# make a list for _evaluate_individuals
pipelines = []
pipelines.append(creator.Individual.from_string(pipeline_string_1, tpot_obj._pset))
pipelines.append(creator.Individual.from_string(pipeline_string_2, tpot_obj._pset))
for pipeline in pipelines:
initialize_stats_dict(pipeline)
pop = tpot_obj._evaluate_individuals(pipelines, pretest_X, pretest_y)
fitness_scores = [ind.fitness.values for ind in pop]
assert fitness_scores[0][0] == 2
assert fitness_scores[1][0] == 5000.0