本文整理匯總了Python中tpot.TPOTClassifier._combine_individual_stats方法的典型用法代碼示例。如果您正苦於以下問題:Python TPOTClassifier._combine_individual_stats方法的具體用法?Python TPOTClassifier._combine_individual_stats怎麽用?Python TPOTClassifier._combine_individual_stats使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tpot.TPOTClassifier
的用法示例。
在下文中一共展示了TPOTClassifier._combine_individual_stats方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_mut_operator_stats_update
# 需要導入模塊: from tpot import TPOTClassifier [as 別名]
# 或者: from tpot.TPOTClassifier import _combine_individual_stats [as 別名]
def test_mut_operator_stats_update():
"""Asserts that self._random_mutation_operator updates stats as expected."""
tpot_obj = TPOTClassifier()
tpot_obj._fit_init()
ind = creator.Individual.from_string(
'KNeighborsClassifier('
'BernoulliNB(input_matrix, BernoulliNB__alpha=10.0, BernoulliNB__fit_prior=False),'
'KNeighborsClassifier__n_neighbors=10, '
'KNeighborsClassifier__p=1, '
'KNeighborsClassifier__weights=uniform'
')',
tpot_obj._pset
)
initialize_stats_dict(ind)
ind.statistics["crossover_count"] = random.randint(0, 10)
ind.statistics["mutation_count"] = random.randint(0, 10)
# set as evaluated pipelines in tpot_obj.evaluated_individuals_
tpot_obj.evaluated_individuals_[str(ind)] = tpot_obj._combine_individual_stats(2, 0.99, ind.statistics)
for _ in range(10):
offspring, = tpot_obj._random_mutation_operator(ind)
assert offspring.statistics['crossover_count'] == ind.statistics['crossover_count']
assert offspring.statistics['mutation_count'] == ind.statistics['mutation_count'] + 1
assert offspring.statistics['predecessor'] == (str(ind),)
ind = offspring
示例2: test_mate_operator_stats_update
# 需要導入模塊: from tpot import TPOTClassifier [as 別名]
# 或者: from tpot.TPOTClassifier import _combine_individual_stats [as 別名]
def test_mate_operator_stats_update():
"""Assert that self._mate_operator updates stats as expected."""
tpot_obj = TPOTClassifier()
tpot_obj._fit_init()
ind1 = creator.Individual.from_string(
'KNeighborsClassifier('
'BernoulliNB(input_matrix, BernoulliNB__alpha=10.0, BernoulliNB__fit_prior=False),'
'KNeighborsClassifier__n_neighbors=10, '
'KNeighborsClassifier__p=1, '
'KNeighborsClassifier__weights=uniform'
')',
tpot_obj._pset
)
ind2 = creator.Individual.from_string(
'KNeighborsClassifier('
'BernoulliNB(input_matrix, BernoulliNB__alpha=10.0, BernoulliNB__fit_prior=True),'
'KNeighborsClassifier__n_neighbors=10, '
'KNeighborsClassifier__p=2, '
'KNeighborsClassifier__weights=uniform'
')',
tpot_obj._pset
)
initialize_stats_dict(ind1)
initialize_stats_dict(ind2)
# Randomly mutate the statistics
ind1.statistics["crossover_count"] = random.randint(0, 10)
ind1.statistics["mutation_count"] = random.randint(0, 10)
ind2.statistics["crossover_count"] = random.randint(0, 10)
ind2.statistics["mutation_count"] = random.randint(0, 10)
# set as evaluated pipelines in tpot_obj.evaluated_individuals_
tpot_obj.evaluated_individuals_[str(ind1)] = tpot_obj._combine_individual_stats(2, 0.99, ind1.statistics)
tpot_obj.evaluated_individuals_[str(ind2)] = tpot_obj._combine_individual_stats(2, 0.99, ind2.statistics)
# Doing 10 tests
for _ in range(10):
offspring1, offspring2 = tpot_obj._mate_operator(ind1, ind2)
assert offspring1.statistics['crossover_count'] == ind1.statistics['crossover_count'] + ind2.statistics['crossover_count'] + 1
assert offspring1.statistics['mutation_count'] == ind1.statistics['mutation_count'] + ind2.statistics['mutation_count']
assert offspring1.statistics['predecessor'] == (str(ind1), str(ind2))
# Offspring replaces on of the two predecessors
# Don't need to worry about cloning
if random.random() < 0.5:
ind1 = offspring1
else:
ind2 = offspring1