【发布时间】:2016-04-01 07:09:33
【问题描述】:
我是 DEAP 的新手,我想将我的染色体表示为一组将由 SVM 分类器测试的特征,我现在的问题是如何在染色体中表示我的 35 个特征
【问题讨论】:
-
@Gabriel IIharco 在 python 中
标签: classification genetic-algorithm deap
我是 DEAP 的新手,我想将我的染色体表示为一组将由 SVM 分类器测试的特征,我现在的问题是如何在染色体中表示我的 35 个特征
【问题讨论】:
标签: classification genetic-algorithm deap
请找到这个 Deap 文档的链接。 您将在此处找到示例: https://deap.readthedocs.io/en/master/examples/index.html
你也可以在这里找到人口的表示方法。
https://deap.readthedocs.io/en/master/tutorials/basic/part1.html
import random
from deap import base
from deap import creator
from deap import tools
creator.create("FitnessMax", base.Fitness, weights=(1.0,))
creator.create("Individual", list, fitness=creator.FitnessMax)
toolbox = base.Toolbox()
# Attribute generator
# define 'attr_bool' to be an attribute ('gene')
# which corresponds to integers sampled uniformly
# from the range [0,1] (i.e. 0 or 1 with equal
# probability)
toolbox.register("attr_bool", random.randint, 0, 1)
# Structure initializers
# define 'individual' to be an individual
# consisting of 100 'attr_bool' elements ('genes')
toolbox.register("individual", tools.initRepeat, creator.Individual,
toolbox.attr_bool, 100)
# define the population to be a list of individuals
toolbox.register("population", tools.initRepeat, list, toolbox.individual)
【讨论】: