'list' object is not callable for checking score accuracy?

I am creating a model using SVM. I wanted to save the classifier model and the parameters that was used into an excel and .json file, which will then be opened to see the best model out of all the .json files.

However, I got this error when I tried to run the second part of the code:

--------------------------------------------------------------------------- TypeError                                 Traceback (most recent call last) <ipython-input-4-9fd85866127d> in <module>      88 for x in func:      89     count=count+1 ---> 90     train_val(x[0],x[1],x[2],count)      91     end_time = time.time()  <ipython-input-4-9fd85866127d> in train_val(kernel, c, gamma, count)      43             scoring.append(score(y_test, predictions))      44         else: ---> 45             scoring.append(score(y_test, predictions,average='macro'))      46       47     # saving kernel that is used to the list  TypeError: 'list' object is not callable 

I didn’t put anything that has the word 'list' so it shouldn’t have been overridden. What makes the score list uncallable? Thank you.

Add Comment
1 Answer(s)

You create lists:

accuracy = [] precision = [] recall = [] f1 = [] ... 

and you define scores to hold these lists:

scores = [accuracy, precision, recall, f1] 

Then you iterate over these lists:

for score in scores:    ... 

But inside that loop you use these lists as if they’re functions:

score(y_test, predictions) 
Answered on July 16, 2020.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.