python内核_Python中的内核方法(kernel methods in Python)

Python中的内核方法(kernel methods in Python)

from scipy.spatial.distance import pdist, squareform

X = loaddata() # this is an NxD matrix, where N is number of items and D its dimensions

pairwise_dists = squareform(pdist(X, 'euclidean'))

K = scip.exp(pairwise_dists / s**2)

如果输入是有向图的加权邻接矩阵,那么如何实现上面的Guassin内核?

from scipy.spatial.distance import pdist, squareform

X = loaddata() # this is an NxD matrix, where N is number of items and D its dimensions

pairwise_dists = squareform(pdist(X, 'euclidean'))

K = scip.exp(pairwise_dists / s**2)

How one can implement the above Guassin kernel, if the input is a weighted adjacency matrix for a directed graph?

原文:https://stackoverflow.com/questions/19256082

2019-12-24 05:01

满意答案

如果您已经有距离矩阵,则可以简单地申请

K = scip.exp(YOUR_DISTANCE_HERE / s**2)

但是,它可能不再是内核 。 并非所有“相似性得分”都是有效的内核。 如果您的距离是有效的Mahalanobis距离,那么您有一个保证,一切都会好的。 如果是“任何”距离 - 任何事情都可能发生。

Usinig无效内核可能导致:

优化过程崩溃

找到次优解决方案(不好的解决方案)

做任何事情 ,完全没有保证。

也许你应该考虑与高斯核和热扩散有一定密切相关的

If you already have your distance matrix, you could simply apply

K = scip.exp(YOUR_DISTANCE_HERE / s**2)

However, it may no longer be a kernel. Not all "similarity scores" are valid kernels. If your distances is a valid Mahalanobis distance then you have a guarantee, that everything will be ok. In case of "any" distance - anything can happen.

Usinig invalid kernel may lead to:

Optimization process crash

Finding suboptimal sol

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值