mojolearn.VarianceThreshold#

class mojolearn.VarianceThreshold(threshold=0.0)#

Feature selector that removes low-variance features.

Follows scikit-learn’s VarianceThreshold. Fit computes each column’s population variance over its non-NaN values and keeps the columns whose variance is greater than threshold. With the default threshold of 0, a constant column has variance exactly 0 and is removed. Fit raises ValueError when no column passes.

Parameters:

threshold (float, default 0.0) – Columns with variance at or below this are removed.

Variables:
  • variances_ (array of shape (n_features,)) – Variance of each column.

  • n_features_in_ (int) – Number of columns seen in fit.

  • numeric_mode_ (str) – Numeric mode the estimator was fitted in; transform runs in the same mode.

Examples

>>> import numpy as np, mojolearn
>>> X = np.array([[0, 2, 0, 3], [0, 1, 4, 3], [0, 1, 1, 3]], dtype=np.float32)
>>> mojolearn.VarianceThreshold().fit_transform(X)

See also

User guide: Preprocessing

Choosing an estimator

Methods

fit(X[, y])

fit_transform(X[, y])

Fit to X, then transform X.

get_params([deep])

Return the constructor parameters as a dict.

get_support([indices])

Return the selected features.

set_params(**params)

Set constructor parameters.

transform(X)

Keep only the selected columns of X.

fit_transform(X, y=None, **fit_params)#

Fit to X, then transform X.

Returns:

array – The transformed data.

get_params(deep=True)#

Return the constructor parameters as a dict.

Parameters:

deep (bool, default True) – Accepted for scikit-learn compatibility.

Returns:

dict – Parameter names mapped to their values.

get_support(indices=False)#

Return the selected features.

Parameters:

indices (bool, default False) – Return the indices of the selected columns instead of a boolean mask.

Returns:

list – Boolean mask over the input columns, or the selected column indices.

set_params(**params)#

Set constructor parameters.

An unknown parameter name raises ValueError.

Returns:

self

transform(X)#

Keep only the selected columns of X.

Raises ValueError when no column is selected.

Parameters:

X (array-like of shape (n_samples, n_features)) – Data with the columns seen in fit.

Returns:

array of shape (n_samples, n_selected_features) – The selected columns, float32.