參考:http://scikit-learn.org/stable/modules/metrics.html

The sklearn.metrics.pairwise submodule
implements utilities to evaluate pairwise distances(样本对的距离) or affinity of sets of samples(样本集的相似度)。

Distance metrics are functions d(a, b) such that d(a, b) < d(a, c) if
objects a and b are considered “more similar” than objects a and c.

Kernels are measures of similarity, i.e. s(a, b) > s(a, c) if
objects a and b are considered “more similar” than objects a and c.

1、Cosine similarity

向量点积的L2-norm:

if  and  are
row vectors, their cosine similarity  is
defined as:

This kernel is a popular choice
for computing the similarity of documents represented as tf-idf vectors.

2、Linear kernel

If x and y are column vectors, their linear kernel is:

(x, y) = x_transport
* y

3、Polynomial kernel

Conceptually, the polynomial kernels
considers not only the similarity between vectors under the same dimension, but also across dimensions. When used in machine learning algorithms, this allows to account for feature interaction.

The polynomial kernel is defined as:

4、Sigmoid kernel

defined as:


5、RBF kernel

defined as:

If  the
kernel is known as the Gaussian kernel of variance .

6、Chi-squared kernel

defined as:

The chi-squared kernel is a very popular choice for training non-linear SVMs in computer
vision applications. It can be computed usingchi2_kernel and
then passed to an sklearn.svm.SVC with kernel="precomputed":

>>>

>>> from sklearn.svm import SVC
>>> from sklearn.metrics.pairwise import chi2_kernel
>>> X = [[0, 1], [1, 0], [.2, .8], [.7, .3]]
>>> y = [0, 1, 0, 1]
>>> K = chi2_kernel(X, gamma=.5)
>>> K
array([[ 1. , 0.36..., 0.89..., 0.58...],
[ 0.36..., 1. , 0.51..., 0.83...],
[ 0.89..., 0.51..., 1. , 0.77... ],
[ 0.58..., 0.83..., 0.77... , 1. ]]) >>> svm = SVC(kernel='precomputed').fit(K, y)
>>> svm.predict(K)
array([0, 1, 0, 1])

It can also be directly used as the kernel argument:

>>>

>>> svm = SVC(kernel=chi2_kernel).fit(X, y)
>>> svm.predict(X)
array([0, 1, 0, 1])

最新文章

  1. [原创]ubuntu16.04LTS使用细节
  2. angularjs自带过滤器
  3. oracle ebs应用产品安全性-交叉验证规则
  4. java之初识服务器跨域获取数据
  5. SQLServer的Login迁移脚本
  6. 当前标识(IIS APPPOOL\DefaultWebSite)没有对“C:\Windows\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files“的写访问权限
  7. 转自 处理老版PIL 到 pillow
  8. leetcode题解: Remove Duplicates from Sorted List(已排序单链表去重)
  9. uva 10892
  10. jQuery插入节点的方法
  11. hive 分区操作记录
  12. 模块化与MVC
  13. SQL作业二
  14. mysql经典面试题
  15. 51Nod1778 小Q的集合 【组合数】【Lucas定理】
  16. GCC编译器原理(三)------编译原理三:编译过程(2-1)---编译之词法分析
  17. Redis事件订阅和持久化存储
  18. ipython output logging:使用日志记录输出
  19. HDU 2722 Here We Go(relians) Again (最短路)
  20. 单点登录(SSO)问题

热门文章

  1. android开发小内容
  2. Greenplum开发
  3. 主从 binlog_format 设置关系
  4. PHP7中session_start 使用注意事项,会导致浏览器刷时页面数据不更新
  5. ubuntu+ngnix+thinkphp pathinfo配置
  6. Mac上简单常用Terminal命令
  7. Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean
  8. Github Pages另一个选择:GitCafe-Pages
  9. 洛谷——P1475 控制公司 Controlling Companies
  10. Gym - 101670H Go Northwest!(CTU Open Contest 2017 思维题+map)