Scikit-learn Ridge分类器:提取类概率 [英] Scikit-learn Ridge classifier: extracting class probabilities

查看:112
本文介绍了Scikit-learn Ridge分类器:提取类概率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用sklearn的Ridge分类器,并且希望将此分类器与sklearn和其他库中的分类器结合在一起.为此,最好提取给定输入属于类别列表中每个类别的概率.目前,我正在使用model.decision_function(x)的输出压缩类,但这将返回距超平面的距离,而不是直接的概率.这些距离值从-1到1左右.

I'm currently using sklearn's Ridge classifier, and am looking to ensemble this classifier with classifiers from sklearn and other libraries. In order to do this, it would be ideal to extract the probability that a given input belongs to each class in a list of classes. Currently, I'm zipping the classes with the output of model.decision_function(x), but this returns the distance from the hyperplane as opposed to a straightforward probability. These distance values vary from around -1 to around 1.

distances = dict(zip(clf.classes_, clf.decision_function(x)[0]))  

如何将这些距离转换为更具体的概率集(一系列总计为1的正值)?我正在寻找为sklearn中的SVC实现的类似 clf.predict_proba()的东西.

How can I convert these distances to a more concrete set of probabilities (a series of positive values that sum to 1)? I'm looking for something like clf.predict_proba() that is implemented for the SVC in sklearn.

推荐答案

进一步的探索导致使用softmax函数.

Further exploration lead to using the softmax function.

d = clf.decision_function(x)[0]
probs = np.exp(d) / np.sum(np.exp(d))

这保证了0-1有界分布的总和为1.

This guarantees a 0-1 bounded distribution that sums to 1.

这篇关于Scikit-learn Ridge分类器:提取类概率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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