“ SVC”对象没有属性“ SVC”

克里斯蒂娜(Christina)

我正在一个简单的循环中挣扎:

for kernel in ('linear','poly', 'rbf'):
    svm = svm.SVC(kernel=kernel, C=1)
    svm.fit(trainingdata_without_labels, trainingdata_labels)

    predicted_labels = svm.predict(testdata_without_labels)
    print("testing success ratio with "+ kernel + "kernel :" + str(accuracy_score(testdata_labels, predicted_labels)))

它在第一个循环中工作正常,但随后我得到:

AttributeError:“ SVC”对象没有属性“ SVC”

我真的很想了解我的错误。

在此先感谢<3

IMB

您正在用第一个循环覆盖svm。

尝试更改分类器的名称,例如:

for kernel in ('linear','poly', 'rbf'):
    classifier_svm = svm.SVC(kernel=kernel, C=1)
    classifier_svm.fit(trainingdata_without_labels, trainingdata_labels)

    predicted_labels = classifier_svm.predict(testdata_without_labels)
    print("testing success ratio with "+ kernel + "kernel :" + str(accuracy_score(testdata_labels, predicted_labels)))

此外,我认为您尝试做的事情是找到最佳内核,使用GridSearchCV可以更轻松地解决该问题:

from sklearn.model_selection import GridSearchCV
from sklearn.metrics import classification_report
from sklearn.svm import SVC


tuned_parameters = [{'kernel': ['linear', 'poly', 'rbf'],
                     'C': [1]}
                   ]

clf = GridSearchCV(SVC(), tuned_parameters, scoring='accuracy')
clf.fit(trainingdata_without_labels, trainingdata_labels)


print("Best parameters set found on development set:\n")
print(clf.best_params_)
print("\nGrid scores on development set:\n")
means = clf.cv_results_['mean_test_score']
stds = clf.cv_results_['std_test_score']
for mean, std, params in zip(means, stds, clf.cv_results_['params']):
    print("%0.3f (+/-%0.03f) for %r"
          % (mean, std * 2, params))

print("\nDetailed classification report:\n")
print("The model is trained on the full development set.")
print("The scores are computed on the full evaluation set.")

y_true, y_pred = testdata_labels, clf.predict(testdata_without_labels)

print(classification_report(y_true, y_pred))

使用此代码段,您将使用3个内核训练模型,并进行5倍交叉验证。最后计算测试变量的分类报告(精确度,召回率,f1-分数)。最终报告应如下所示(每行将是一个可在您的数据中进行预测的类):

                precision    recall  f1-score   support

           0       1.00      1.00      1.00        27
           1       0.95      1.00      0.97        35
           2       1.00      1.00      1.00        36
           3       1.00      1.00      1.00        29
           4       1.00      1.00      1.00        30
           5       0.97      0.97      0.97        40
           6       1.00      0.98      0.99        44
           7       1.00      1.00      1.00        39
           8       1.00      0.97      0.99        39
           9       0.98      0.98      0.98        41

    accuracy                           0.99       360
   macro avg       0.99      0.99      0.99       360
weighted avg       0.99      0.99      0.99       360

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

更新scikit-learn:'SVC'对象没有属性'_probA'?

来自分类Dev

没有.svc的WCF服务相对uri

来自分类Dev

没有.svc的WCF服务相对uri

来自分类Dev

没有SVC文件的WCF依赖项注入

来自分类Dev

具有多个SVC的WCF Web配置

来自分类Dev

从Google cloudrun svc到cloudrun svc的加密链接

来自分类Dev

odata服务的URL后缀“ .svc”

来自分类Dev

如何连接到SVC端点?

来自分类Dev

ARM CPU模式SVC指令

来自分类Dev

WCF Web Config with Multiple SVC

来自分类Dev

SVC无法在MNIST上解析

来自分类Dev

sklearn LinearSVC是SVM还是SVC?

来自分类Dev

ARM CPU模式SVC指令

来自分类Dev

SVC主机消耗99%的CPU

来自分类Dev

如何为没有SVC文件的自托管WCF服务指定ServiceHostFactory

来自分类Dev

如何在IIS中托管没有SVC文件的WCF服务

来自分类Dev

SVC scikit预测奇数和偶数

来自分类Dev

sklearn的SVC评分方法需要哪种输入?

来自分类Dev

ARM汇编代码和SVC编号

来自分类Dev

是否立即引发PendSV / SVC异常?

来自分类Dev

IIS服务器的.svc处理程序

来自分类Dev

通过使用svc调用实现fork()实现

来自分类Dev

IIS w3svc错误

来自分类Dev

提高单个样本的SVC预测性能

来自分类Dev

什么时候应该使用LinearSVC或SVC?

来自分类Dev

伽玛SVC sklearn的默认值

来自分类Dev

Azure“ Kudu”中的.SVC文件为空

来自分类Dev

SVC Sigmoid内核无法正常工作

来自分类Dev

sklearn SVC是否自动完成标签编码?