mojolearn.SkewedChi2Sampler#
- class mojolearn.SkewedChi2Sampler(*, skewedness=1.0, n_components=100, random_state=None)[source]#
Bases:
_XNeighborsApproximate feature map for the skewed chi-squared kernel.
Monte Carlo approximation of the kernel’s feature map, following scikit-learn’s
SkewedChi2Sampler. The random weights and offsets are drawn from mojolearn’s counter-based generator seeded byrandom_state: the same distribution as scikit-learn, reproducible for an int seed, but not scikit-learn’s exact numbers. Computation is float32. Input values at or below-skewednessraiseValueError.- Parameters:
skewedness (float, default 1.0) – Skewedness parameter of the kernel.
n_components (int, default 100) – Number of Monte Carlo samples per feature (output dimension); at least 1.
random_state (int, numpy.random.RandomState or None, default None) – Seed for the weights and offsets. A RandomState or None contributes one draw that seeds the generator. Anything else raises
ValueError.numeric_mode ({‘identical’, ‘deterministic’, ‘fast’} or None, default None) – Numeric mode for this estimator (
'fast'is Apple only). None uses the process default.
- Variables:
Examples
>>> import numpy as np, mojolearn >>> X = np.random.default_rng(0).random((1000, 8), dtype=np.float32) >>> Z = mojolearn.SkewedChi2Sampler(n_components=64, random_state=0).fit_transform(X)
Methods
fit(X[, y])Draw the random weights and offsets.
fit_transform(X[, y])Fit to X, then transform X:
fit(X).transform(X).get_feature_names_out([input_features])Output feature names:
skewedchi2sampler0,skewedchi2sampler1, ...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.
Attributes
Random projection weights, shape (n_features, n_components).
- fit(X, y=None)[source]#
Draw the random weights and offsets.
- Parameters:
X (array-like or scipy.sparse matrix of shape (n_samples, n_features)) – Training data; only its number of features is used.
y (None) – Ignored.
- Returns:
self (SkewedChi2Sampler) – The fitted transformer.
- Raises:
ValueError – If X has no features,
n_componentsis below 1, orrandom_stateis not an int, a numpy RandomState or None.
- property random_weights_#
Random projection weights, shape (n_features, n_components).
- transform(X)[source]#
Apply the approximate feature map to X.
- Parameters:
X (array-like or scipy.sparse matrix of shape (n_samples, n_features)) – Samples; every value must be greater than
-skewedness(ValueErrorotherwise). Sparse input is densified.- Returns:
X_new (Array of shape (n_samples, n_components), float32)