SKLearn:获取每个点到决策边界的距离吗? [英] SKLearn: Getting distance of each point from decision boundary?

查看:419
本文介绍了SKLearn:获取每个点到决策边界的距离吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用SKLearn在数据上运行SVC.

I am using SKLearn to run SVC on my data.

from sklearn import svm

svc = svm.SVC(kernel='linear', C=C).fit(X, y)

我想知道如何从决策边界获得X中每个数据点的距离?

I want to know how I can get the distance of each data point in X from the decision boundary?

推荐答案

对于线性核,决策边界为y = w * x + b,从点x到决策边界的距离为y/|| w ||

For linear kernel, the decision boundary is y = w * x + b, the distance from point x to the decision boundary is y/||w||.

y = svc.decision_function(x)
w_norm = np.linalg.norm(svc.coef_)
dist = y / w_norm

对于非线性内核,无法获取绝对距离.但是您仍然可以将decision_funcion的结果用作相对距离.

For non-linear kernels, there is no way to get the absolute distance. But you can still use the result of decision_funcion as relative distance.

这篇关于SKLearn:获取每个点到决策边界的距离吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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