我的代码是遗传算法。我的问题是: 我想要回报最好的个人,最差和平均。所有我想用列表的索引。示例:最佳价值=高利率。最差值=最小指数。我不知道怎么。这是我的代码:
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]
我不知道如何拍摄并返回这些值。希望您能够帮助我。非常感谢你
答案 0 :(得分:0)
您有此错误,因为您在未传递任何列表的情况下调用该方法(在这种情况下为人口)。