AdditiveChi2Sample (Additive Chi Squared Kernel)#
Kernel:
k(x,y) = \sum_i \frac{2 x_i y_i}{x_i + y_i}
Permite el muestreo de un kernel chi2 aditivo.
Realiza un muestreo de la transformada de Fourier del kernel a intervalos regulares.
Cada entrada en el espacio original es transformada en 2 *
sample_steps
- 1 características.
[1]:
from sklearn.datasets import load_digits
from sklearn.kernel_approximation import AdditiveChi2Sampler
from sklearn.linear_model import SGDClassifier
X, y = load_digits(return_X_y=True)
chi2sampler = AdditiveChi2Sampler(
# -------------------------------------------------------------------------
# Gives the number of (complex) sampling points. 2n+1 points for dimension.
# Typical values = {1, 2, 3}
sample_steps=2,
# -------------------------------------------------------------------------
# Sampling interval. Must be specified when sample_steps not in {1,2,3}.
sample_interval=None,
)
X_transformed = chi2sampler.fit_transform(X, y)
X_transformed.shape
[1]:
(1797, 192)
[2]:
clf = SGDClassifier(
max_iter=100,
random_state=0,
tol=1e-3,
)
clf.fit(X_transformed, y)
clf.score(X_transformed, y)
[2]:
0.9821925431274346