如何获取Scikit-learn的svm中的训练错误? [英] How to obtain the training error in svm of Scikit-learn?

查看:96
本文介绍了如何获取Scikit-learn的svm中的训练错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题:如何在svm模块(SVC类)中获得训练错误?

我正在尝试根据所使用的训练数据(或其他功能,例如C/gamma)的数量来绘制训练集和测试集的误差图.但是,根据 SVM文档,没有此类公开的属性或返回此类数据的方法.我确实发现RandomForestClassifier确实公开了oob_score _.

解决方案

只需在训练数据上计算分数:

>>> model.fit(X_train, y_train).score(X_train, y_train)

您还可以使用sklearn.metrics模块中的任何其他性能指标.该文档在这里:

http://scikit-learn.org/stable/modules/model_evaluation.html

也:oob_score_是测试/验证分数的估计值,而不是训练分数.

My question: How do I obtain the training error in the svm module (SVC class)?

I am trying to do a plot of error of the train set and test set against the number of training data used ( or other features such as C / gamma ). However, according to the SVM documentation , there is no such exposed attribute or method to return such data. I did find that RandomForestClassifier does expose a oob_score_ though.

解决方案

Just compute the score on the training data:

>>> model.fit(X_train, y_train).score(X_train, y_train)

You can also use any other performance metrics from the sklearn.metrics module. The doc is here:

http://scikit-learn.org/stable/modules/model_evaluation.html

Also: oob_score_ is an estimate of the test / validation score, not the training score.

这篇关于如何获取Scikit-learn的svm中的训练错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆