我有一个 KNeighborsClassifier,它根据 4 个属性对数据进行分类。我想手动加权这 4 个属性,但总是遇到“操作数不能与形状 (1,5) (4) 一起广播”。
weights : [callable] : a user-defined function which accepts an array of distances, and returns an array of the same shape containing the weights.
关于(从这里)的文档很少
这就是我现在所拥有的:
for v in result:
params = [v['a_one'], v['a_two'], v['a_three'], v['a_four']]
self.training_data['data'].append(params)
self.training_data['target'].append(v['answer'])
def get_weights(array_weights):
return [1,1,2,1]
classifier = neighbors.KNeighborsClassifier(weights=get_weights)