當前位置: 首頁>>代碼示例>>Python>>正文


Python tools.ParetoFront方法代碼示例

本文整理匯總了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) 
開發者ID:EpistasisLab,項目名稱:tpot,代碼行數:20,代碼來源:tpot_tests.py

示例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 
開發者ID:DEAP,項目名稱:deap,代碼行數:19,代碼來源:kursawefct.py

示例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 
開發者ID:DEAP,項目名稱:deap,代碼行數:18,代碼來源:evoknn.py

示例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 
開發者ID:DEAP,項目名稱:deap,代碼行數:22,代碼來源:knapsack.py

示例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 
開發者ID:DEAP,項目名稱:deap,代碼行數:23,代碼來源:xkcd.py

示例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) 
開發者ID:EpistasisLab,項目名稱:tpot,代碼行數:41,代碼來源:tpot_tests.py

示例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) 
開發者ID:EpistasisLab,項目名稱:tpot,代碼行數:42,代碼來源:tpot_tests.py

示例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 
開發者ID:EpistasisLab,項目名稱:tpot,代碼行數:40,代碼來源:tpot_tests.py


注:本文中的deap.tools.ParetoFront方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。