我的代码是遗传算法。我的问题是: 我要回报最好的个人,最差的和一般的。我要做的就是列表的索引。示例:最佳值=高比率更多。最差值=最小索引。我不知道怎么做。这是我的代码:
def selecciona_mejor_peor_medio(self, population):
list = []
cont = 0
arff = self.arff_reader_class
attributes_list = []
attributes_counter = []
for element in list:
if element[len(element)-1] in arff.consequences:
temporal_rule = element
# We take the first attribute
for attribute in element:
# Seek other sets that start with the same item and group them into lists.
# Subsequently removed from the initial list to avoid repeating values
for rule_list in self.population_my_method:
for rule in rule_list:
cont_attribute = 0
for rule_attribute in rule:
if rule_attribute == attribute:
cont_attribute += 1
if cont_attribute == len(element):
cont += 1
attributes_counter.append(cont)
# Find the index of the highest value, medium and low
peor = attributes_counter.index(min(attributes_counter))
mejor = attributes_counter.index(max(attributes_counter))
index, value = max(enumerate(list), key=operator.itemgetter(1))
# With the rates you get the values at the population
if mejor > list[cont]:
return mejor
elif peor < list[cont]:
return peor
else:
return list[cont]
我不知道如何获取和返回这些值。希望你能帮助我。非常感谢
出现此错误是因为调用方法时没有传递任何列表(在本例中是填充)。在
相关问题 更多 >
编程相关推荐