additive_chi2_kernel#

sklearn.metrics.pairwise.additive_chi2_kernel(X,Y=None)[source]#

Compute the additive chi-squared kernel between observations in X and Y.

The chi-squared kernel is computed between each pair of rows in X and Y. Xand Y have to be non-negative. This kernel is most commonly applied tohistograms.

The chi-squared kernel is given by:

k(x, y) = -Sum [(x - y)^2 / (x + y)]

It can be interpreted as a weighted difference per entry.

Read more in theUser Guide.

Parameters:
Xarray-like of shape (n_samples_X, n_features)

A feature array.

Yarray-like of shape (n_samples_Y, n_features), default=None

An optional second feature array. IfNone, usesY=X.

Returns:
kernelarray-like of shape (n_samples_X, n_samples_Y)

The kernel matrix.

See also

chi2_kernel

The exponentiated version of the kernel, which is usually preferable.

sklearn.kernel_approximation.AdditiveChi2Sampler

A Fourier approximation to this kernel.

Notes

As the negative of a distance, this kernel is only conditionally positivedefinite.

References

Examples

>>>fromsklearn.metrics.pairwiseimportadditive_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.]])

This Page