additive_chi2_kernel#
- sklearn.metrics.pairwise.additive_chi2_kernel(X, Y=None)[source]#
计算 X 和 Y 中的观测值之间的加性卡方核。
在X和Y的每对行之间计算卡方核。X和Y必须是非负数。该核最常用于直方图。
卡方核由以下公式给出
k(x, y) = -Sum [(x - y)^2 / (x + y)]
它可以被解释为每个条目的加权差。
在用户指南中阅读更多内容。
- 参数:
- X形状为 (n_samples_X, n_features) 的类数组对象
特征数组。
- Y形状为 (n_samples_Y, n_features) 的类数组对象, default=None
可选的第二个特征数组。如果为
None,则使用Y=X。
- 返回:
- kernel形状为 (n_samples_X, n_samples_Y) 的类数组对象
核矩阵。
另请参阅
chi2_kernel核的指数形式,通常更可取。
sklearn.kernel_approximation.AdditiveChi2Sampler该核的傅立叶近似。
注意事项
作为距离的负值,此核仅是条件正定的。
References
Zhang, J. and Marszalek, M. and Lazebnik, S. and Schmid, C. Local features and kernels for classification of texture and object categories: A comprehensive study International Journal of Computer Vision 2007 https://hal.archives-ouvertes.fr/hal-00171412/document
示例
>>> from sklearn.metrics.pairwise import additive_chi2_kernel >>> X = [[0, 0, 0], [1, 1, 1]] >>> Y = [[1, 0, 0], [1, 1, 0]] >>> additive_chi2_kernel(X, Y) array([[-1., -2.], [-2., -1.]])