在SVM中列表对象不可调用

我试图在Python中使用分层K折交叉验证来运行这个SVM,但是我不断得到如下错误

from sklearn.model_selection import train_test_splitfrom sklearn.svm import SVCfrom sklearn.utils import shufflefrom sklearn import preprocessingfrom sklearn.preprocessing import MinMaxScalerfrom sklearn.model_selection import StratifiedKFoldfrom sklearn.metrics import accuracy_score, zero_one_loss, confusion_matriximport pandas as pdimport numpy as npz = pd.read_csv('/home/User/datasets/gtzan.csv', header=0)X = z.iloc[:, :-1]y = z.iloc[:, -1:]X = np.array(X)y = np.array(y)# Performing standard scalingscaler = preprocessing.MinMaxScaler()X_scaled = scaler.fit_transform(X)# Defining the SVM with 'rbf' kernelsvc = SVC(kernel='rbf', C=100, random_state=50)#X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.10, shuffle=True)skf = StratifiedKFold(n_splits=10, shuffle=True)accuracy_score = []#skf.get_n_splits(X, y)for train_index, test_index in skf.split(X, y):    X_train, X_test = X_scaled[train_index], X_scaled[test_index]    y_train, y_test = y[train_index], y[test_index]    # Training the model    svc.fit(X_train, np.ravel(y_train))    # Prediction on test dataste    y_pred = svc.predict(X_test)    # Obtaining the accuracy scores of the model    score = accuracy_score(y_test, y_pred)    accuracy_score.append(score)# Print the accuarcy of the svm modelprint('accuracy score: %0.3f' % np.mean(accuracy_score))

然而,它给我带来了如下错误

Traceback (most recent call last):  File "/home/User/Test_SVM.py", line 55, in <module>    score = accuracy_score(y_test, y_pred)TypeError: 'list' object is not callable

是什么让这个分数列表不可调用,我该如何修复这个错误?


回答:

accuracy_score在我代码中是一个列表,我也在调用同一个列表作为函数,这覆盖了函数accuarcy_score的现有功能。将列表名称更改为acc_score解决了这个问题。

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注