卡方核#
- sklearn.metrics.pairwise.chi2_kernel(X, Y=None, gamma=1.0)[source]#
- 计算 X 和 Y 之间的指数卡方核。 - 卡方核是在 X 和 Y 中每一对行之间计算的。X 和 Y 必须是非负的。此核最常应用于直方图。 - 卡方核由下式给出 - k(x, y) = exp(-gamma Sum [(x - y)^2 / (x + y)]) - 它可以解释为每个条目的加权差异。 - 在用户指南中了解更多信息。 - 参数:
- X形状为 (n_samples_X, n_features) 的类数组
- 特征数组。 
- Y形状为 (n_samples_Y, n_features) 的类数组,默认为 None
- 可选的第二个特征数组。如果为 - None,则使用- Y=X。
- gamma浮点数,默认值=1
- χ²核的缩放参数。 
 
- 返回值:
- kernel形状为 (n_samples_X, n_samples_Y) 的ndarray
- 核矩阵。 
 
 - 参见 - 加性卡方核
- 此核的加法版本。 
- sklearn.kernel_approximation.AdditiveChi2Sampler
- 此核加法版本的傅里叶逼近。 
 - 参考文献 - 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 chi2_kernel >>> X = [[0, 0, 0], [1, 1, 1]] >>> Y = [[1, 0, 0], [1, 1, 0]] >>> chi2_kernel(X, Y) array([[0.36..., 0.13...], [0.13..., 0.36...]]) 
