SkewedChi2Sampler (Skewed Chi Squared Kernel)#

Kernel:

k(x,y) = \prod_i \frac{2 \sqrt{x_i + c} \sqrt{y_i + c}}{x_i + y_i + 2c}

[1]:
from sklearn.kernel_approximation import SkewedChi2Sampler
from sklearn.linear_model import SGDClassifier

X = [
    [0, 0],
    [1, 1],
    [1, 0],
    [0, 1],
]
y = [
    0,
    0,
    1,
    1,
]


skewedChi2Sampler = SkewedChi2Sampler(
    # -------------------------------------------------------------------------
    # “skewedness” parameter of the kernel. Needs to be cross-validated.
    skewedness=0.01,
    # -------------------------------------------------------------------------
    # Number of Monte Carlo samples per original feature. Equals the
    # dimensionality of the computed feature space.
    n_components=10,
    # -------------------------------------------------------------------------
    # Pseudo-random number generator to control the generation of the random
    # weights and random offset when fitting the training data.
    random_state=0,
)

X_features = skewedChi2Sampler.fit_transform(X, y)

X_features.shape
[1]:
(4, 10)
[2]:
sgdClassifier = SGDClassifier(max_iter=100, tol=1e-3)

sgdClassifier.fit(X_features, y)

sgdClassifier.score(X_features, y)
[2]:
1.0