Ich kam in einem Python-Code in dieser Zeile und weiß nicht, wie, was sie tut:Was bedeutet diese Python-Zeile?
def update(self, instance):
"""
Perform perceptron update, if the wrong label is predicted.
Return a boolean value indicating whether an update was performed.
"""
error = 0
predicted_output = self.prediction(instance.feature_counts)
if(predicted_output==True and instance.label==False):error = 1
if(predicted_output==False and instance.label==True):error = -1
do_update = error !=0
if do_update:
for feature, count in instance.feature_counts.items():
self.weights[feature] += error*count
return do_update
Kann jemand erklären:
do_update = error !=0
Dieser den Zusammenhang war der Code ein Perzeptron Klassifikator war wie es funktioniert?
Es weist der Variablen 'do_update' einen booleschen Wert zu. Wenn 'error! = 0 ', wird' do_update' sonst 'True',' False'. –