mojolearn.SkewedChi2Sampler#

class mojolearn.SkewedChi2Sampler(*, skewedness=1.0, n_components=100, random_state=None)[source]#

Bases: _XNeighbors

Approximate 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 by random_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 -skewedness raise ValueError.

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:
  • random_weights_ (Array of shape (n_features, n_components)) – Random projection weights.

  • random_offset_ (Array of shape (n_components,)) – Random offsets.

  • 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.SkewedChi2Sampler(n_components=64, random_state=0).fit_transform(X)
__init__(*, skewedness=1.0, n_components=100, random_state=None)[source]#

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_weights_

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_components is below 1, or random_state is 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 (ValueError otherwise). Sparse input is densified.

Returns:

X_new (Array of shape (n_samples, n_components), float32)

fit_transform(X, y=None)[source]#

Fit to X, then transform X: fit(X).transform(X).

Parameters:
  • X (array-like of shape (n_samples, n_features)) – Training data.

  • y (None) – Ignored.

Returns:

X_new (Array of shape (n_samples, n_components), float32)

get_feature_names_out(input_features=None)[source]#

Output feature names: skewedchi2sampler0, skewedchi2sampler1, …

Parameters:

input_features (None) – Ignored.

Returns:

names (list of str)