sklearn: OneVsRestClassifier实现多分类 + Grid_Search获取模型的最佳参数

一,sklearn分类器

单一分类器 & 集成分类器 https://www.cnblogs.com/hhh5460/p/5132203.html

使用sklearn https://www.jianshu.com/p/516f009c0875

sklearn通过OneVsRestClassifier实现svm.SVC的多分类 https://blog.csdn.net/xiaodongxiexie/article/details/76229042

二,Grid_Search获取模型最佳参数

https://blog.csdn.net/u012897374/article/details/74999940

三,对OneVsRestClassifier策略的模型执行网格搜索

https://ask.helplib.com/python/post_12965072

当在网格搜索中使用嵌套估计量时,可以使用 __ 作为分隔符来确定参数的范围。这种情况下,SVC模型作为名为 estimator的属性存储在 OneVsRestClassifier 模型中:

from sklearn.datasets import load_iris
from sklearn.multiclass import OneVsRestClassifier
from sklearn.svm import SVC
from sklearn.grid_search import GridSearchCV
from sklearn.metrics import f1_score
iris = load_iris()
model_to_set = OneVsRestClassifier(SVC(kernel="poly"))
parameters = {
"estimator__C": [1,2,4,8],
"estimator__kernel": ["poly","rbf"],
"estimator__degree":[1, 2, 3, 4],
}
model_tunning = GridSearchCV(model_to_set, param_grid=parameters,
 score_func=f1_score)
model_tunning.fit(iris.data, iris.target)
print model_tunning.best_score_
print model_tunning.best_params_

 

  • 10
    点赞
  • 45
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值