mojolearn.AdditiveChi2Sampler#
- class mojolearn.AdditiveChi2Sampler(*, sample_steps=2, sample_interval=None)[source]#
Bases:
_XNeighborsApproximate feature map for the additive chi-squared kernel.
A deterministic Fourier sampling of the kernel’s feature map, following scikit-learn’s
AdditiveChi2Sampler. Each input feature becomes2 * sample_steps - 1output features. Input must be non-negative; negative values raiseValueError. A scipy.sparse input gives a sparse (CSR) output. Computation is float32.- Parameters:
sample_steps (int, default 2) – Number of sampling points.
sample_interval (float or None, default None) – Sampling interval. Required when
sample_stepsis not 1, 2 or 3 (ValueErrorotherwise); by default 0.8, 0.5 or 0.4 for those.numeric_mode ({‘identical’, ‘deterministic’, ‘fast’} or None, default None) – Numeric mode for this estimator (
'fast'is Apple only). None uses the process default.
- Variables:
n_features_in_ (int) – Number of features seen in
fit.
Examples
>>> import numpy as np, mojolearn >>> X = np.random.default_rng(0).random((1000, 8), dtype=np.float32) >>> Z = mojolearn.AdditiveChi2Sampler(sample_steps=2).fit_transform(X)
Methods
fit(X[, y])Validate the input and the sampling settings.
fit_transform(X[, y])Fit to X, then transform X:
fit(X).transform(X).get_feature_names_out([input_features])Output feature names.
get_params([deep])numeric_mode_used()The numeric mode this estimator runs in.
set_params(**params)Set constructor parameters.
transform(X)Apply the approximate feature map to X.
vendor_used()The GPU backend this estimator runs on.
- fit(X, y=None)[source]#
Validate the input and the sampling settings.
- Parameters:
X (array-like or scipy.sparse matrix of shape (n_samples, n_features)) – Training data; must be non-negative (
ValueErrorotherwise).y (None) – Ignored.
- Returns:
self (AdditiveChi2Sampler) – The fitted transformer.
- transform(X)[source]#
Apply the approximate feature map to X.
- Parameters:
X (array-like or scipy.sparse matrix of shape (n_samples, n_features)) – Non-negative samples (
ValueErrorotherwise).- Returns:
X_new (Array or scipy.sparse.csr_matrix of shape (n_samples, n_features * (2 * sample_steps - 1))) – float32; sparse (CSR) when X is sparse.
- fit_transform(X, y=None)[source]#
Fit to X, then transform X:
fit(X).transform(X).- Parameters:
X (array-like or scipy.sparse matrix of shape (n_samples, n_features)) – Non-negative training data.
y (None) – Ignored.
- Returns:
X_new (Array or scipy.sparse.csr_matrix of shape (n_samples, n_features * (2 * sample_steps - 1)))
- get_feature_names_out(input_features=None)[source]#
Output feature names.
For each input name
f:additivechi2sampler_f_sqrt, then for each stepjfrom 1 the..._cos{j}and..._sin{j}names.- Parameters:
input_features (list of str or None, default None) – Input feature names; None means
x0,x1, … Its length must equaln_features_in_(ValueErrorotherwise).- Returns:
names (list of str)