GA和DEAP中的染色体表示

时间:2015-12-27 00:19:30

标签: classification genetic-algorithm deap

我是DEAP的新手,我想将我的染色体表示为一组将由SVM分类器测试的特征,我现在的问题是如何在染色体上代表我的35个特征

1 个答案:

答案 0 :(得分:1)

请在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)