While working with a trainer module I used dictionary to store the parameter being observed and the corresponding accuracy of the data for the parameter value. The parameter being the key to the dictionary and the accuracy being the value.
I have used sklearn.metrics tool to calculate the accuracy here. But the result is showing the following behaviour.
def fit(self, X, Y):
acc={}
best_b = 0
for b in range(0, X.shape[1] + 1):
self.b=b
Y_Pred = self.predict(X)
acc[b]=accuracy_score(Y_Pred,Y)
print(type(acc))
best_b = max(acc, key=acc.get)
self.b = best_b
print("Best b : ", self.b, " with highest accuracy : ", acc[self.b])
Output:
<class 'dict'>
<ipython-input-184-8b55ae4bcee2> in fit(self, X, Y)
21 acc[b]=accuracy_score(Y_Pred,Y)
22 print(type(acc))
---> 23 best_b = max(acc, key=acc.get)
24 self.b = best_b
25 print("Best b : ", self.b, " with highest accuracy : ", acc[self.b])
TypeError: 'list' object is not callable
Why the dictionary is being treated as list object?