用python计算准确率_Python下的scikit-learn预测准确率计算(代码实例)

本文介绍了使用SVM(支持向量机)进行分类器训练,通过train_test_split划分数据集,探讨了不同参数下模型的性能,并计算了训练集和测试集的准确率。同时,详细展示了决策函数和预测结果,以及使用classification_report输出的详细性能指标。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.评价

x_train, x_test, y_train, y_test = train_test_split(x, y, random_state=1, train_size=0.6)

# 分类器

clf = svm.svc(c=0.1, kernel='linear', decision_function_shape='ovr')

# clf = svm.svc(c=0.8, kernel='rbf', gamma=20, decision_function_shape='ovr')

clf.fit(x_train, y_train.ravel())

# 准确率

print clf.score(x_train, y_train) # 精度

print '训练集准确率:', accuracy_score(y_train, clf.predict(x_train))

print clf.score(x_test, y_test)

print '测试集准确率:', accuracy_score(y_test, clf.predict(x_test))

# decision_function

print 'decision_function:\n', clf.decision_function(x_train) #计算样本点到分割超平面的函数距离

print '\npredict:\n', clf.predict(x_train)

from sklearn.metrics import classification_report

# 输出更加详细的其他评价分类性能的指标。

print classification_report(y_test, y_count_predict, target_names = news.target_names)

按类别输出 准确率,召回率

希望与广大网友互动??

点此进行留言吧!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值