GA和DEAP中的染色体表示

问题描述 投票:0回答:1

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

classification genetic-algorithm deap
1个回答
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)
© www.soinside.com 2019 - 2024. All rights reserved.