參考: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])

scikit-learn:4.7. Pairwise metrics, Affinities and Kernels的更多相关文章

  1. scikit learn 模块 调参 pipeline+girdsearch 数据举例:文档分类 (python代码)

    scikit learn 模块 调参 pipeline+girdsearch 数据举例:文档分类数据集 fetch_20newsgroups #-*- coding: UTF-8 -*- import ...

  2. (原创)(四)机器学习笔记之Scikit Learn的Logistic回归初探

    目录 5.3 使用LogisticRegressionCV进行正则化的 Logistic Regression 参数调优 一.Scikit Learn中有关logistics回归函数的介绍 1. 交叉 ...

  3. (原创)(三)机器学习笔记之Scikit Learn的线性回归模型初探

    一.Scikit Learn中使用estimator三部曲 1. 构造estimator 2. 训练模型:fit 3. 利用模型进行预测:predict 二.模型评价 模型训练好后,度量模型拟合效果的 ...

  4. Scikit Learn: 在python中机器学习

    转自:http://my.oschina.net/u/175377/blog/84420#OSC_h2_23 Scikit Learn: 在python中机器学习 Warning 警告:有些没能理解的 ...

  5. Scikit Learn

    Scikit Learn Scikit-Learn简称sklearn,基于 Python 语言的,简单高效的数据挖掘和数据分析工具,建立在 NumPy,SciPy 和 matplotlib 上.

  6. Query意图分析:记一次完整的机器学习过程(scikit learn library学习笔记)

    所谓学习问题,是指观察由n个样本组成的集合,并根据这些数据来预测未知数据的性质. 学习任务(一个二分类问题): 区分一个普通的互联网检索Query是否具有某个垂直领域的意图.假设现在有一个O2O领域的 ...

  7. Learning to Rank:Point-wise、Pair-wise 和 List-wise区别

    机器学习的 ranking 技术——learning2rank,包括 pointwise.pairwise.listwise 三大类型. [Ref-1]给出的: <Point wise rank ...

  8. OpenShift实战(五):OpenShift容器监控Metrics

    1.创建持久化metric pv卷 [root@master1 pv]# cat metrics.json apiVersion: v1 kind: PersistentVolume metadata ...

  9. 如何使用scikit—learn处理文本数据

    答案在这里:http://www.tuicool.com/articles/U3uiiu http://scikit-learn.org/stable/modules/feature_extracti ...

随机推荐

  1. 关于微信小程序:scroll-view,backgroundTextStyle

    踩过的坑mark下 1.滚动列表最好不要用scroll-view组件,这个组件有不少问题,比如触顶操作触发了,会连续好几次执行触发函数,得用一个开关变量和定时器配合来控制,一般情况下view组件就够用 ...

  2. DatePickerDialog日期对话框以及回调函数的用法

    DatePickerDialog类的实例化需要用到回调接口,如下定义: android.app.DatePickerDialog.DatePickerDialog(Context context, O ...

  3. 三维重建:GitHub百度Apollo 2.0

    GitHub:https://github.com/ApolloAuto/apollo 1. 关于Apollo的数据:Apollo的数据会如何开放? 自动驾驶数据将包括具有高分辨率图像和像素级别标注的 ...

  4. java学习_5_23

    Collection接口中定义的方法如下,所有继承自Collection接口的接口(List,Set)的实现类均实现了这些方法. List容器是有序.可重复的,常用的实现类:ArrayList,Lin ...

  5. JAVA基础——集合浅析

    Java  集合      数组是一种很常见的数据结构,开始接触编程的时候多数程序都和数组相关.刚开始接触Java时也是一直使用数组写一些程序,后来越来越觉得数组这东西没法满足需求了,这时一位“前辈” ...

  6. 框架学习八:二维码(Zxing)

    本文转自夏神:http://blog.csdn.net/xiaanming/article/details/10163203 一.用什么 二维码扫描用的google的开源框架Zxing. 二.下载 地 ...

  7. [Java小程序]聊天室——Socket和ServerSocket的使用

    这段小代码是因为担任Java助教给刚学习Java的本科大二的小学弟小学妹们指导,他们的实验作业就是编写一个Java聊天室客户端和服务器,为了避免出纰漏,自己事先写了一下. 客户端Ui代码: packa ...

  8. Linux学习笔记(二) 文件管理

    了解 Linux 系统基本的文件管理命令可以帮助我们更好的使用 Linux 系统,以下介绍几个常用的文件管理命令 1.pwd pwd 是 Print Working Directory 的简写,用于显 ...

  9. 信息的表示和处理 及 CS:APP 15213 datalab

    信息的表示和处理 在通用计算机中中,字节作为最为最小 的可寻址的内存单元,而不是访问内存中单独的位. 寻址和字节顺序 big endian (大端法),数据最高字节部分地址在地址处,和人的感觉逻辑相似 ...

  10. python爬取豆瓣小组700+话题加回复啦啦啦python open file with a variable name

    需求:爬取豆瓣小组所有话题(话题title,内容,作者,发布时间),及回复(最佳回复,普通回复,回复_回复,翻页回复,0回复) 解决:1. 先爬取小组下,所有的主题链接,通过定位nextpage翻页获 ...