我正在使用 SVM 创建模型。我想将分类器模型和使用的参数保存到 Excel 和
.json
文件中,然后打开该文件以查看所有 .json
文件中的最佳模型。
但是,当我尝试运行代码的第二部分时,出现此错误:
---------------------------------------------------------------------------
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
我没有放置任何带有“
'list'
”一词的内容,因此它不应该被覆盖。是什么原因导致成绩单无法调用?谢谢你。
您创建列表:
accuracy = []
precision = []
recall = []
f1 = []
...
并且您定义分数来保存这些列表:
scores = [accuracy, precision, recall, f1]
然后迭代这些列表:
for score in scores:
...
但是在该循环中,您可以像使用函数一样使用这些列表:
score(y_test, predictions)
实际上,您已经创建了一个与 Score 名称相同的列表,并且尝试在其上使用 svm 模型是不可能的,因此您需要更改列表变量的名称,以避免在这种情况下出现错误。由于列表对象不能用作函数