Compute the exponential chi-squared kernel between X and Y.
The chi-squared kernel is computed between each pair of rows in X and Y. X and Y have to be non-negative. This kernel is most commonly applied to histograms.
The chi-squared kernel is given by:
k(x, y) = exp(-gamma Sum [(x - y)^2 / (x + y)])
It can be interpreted as a weighted difference per entry.
Read more in the User Guide.
A feature array.
An optional second feature array. If None, uses Y=X.
Scaling parameter of the chi2 kernel.
The kernel matrix.
See also
additive_chi2_kernelThe additive version of this kernel.
sklearn.kernel_approximation.AdditiveChi2SamplerA Fourier approximation to the additive version of this kernel.
>>> 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...]])
© 2007–2025 The scikit-learn developers
Licensed under the 3-clause BSD License.
https://scikit-learn.org/1.6/modules/generated/sklearn.metrics.pairwise.chi2_kernel.html