mojolearn.SelectKBest#
- class mojolearn.SelectKBest(score_func=<function f_classif>, *, k=10)[source]#
Bases:
_SelectorMixinSelect the features with the
khighest scores.Follows scikit-learn’s
SelectKBest. Fit callsscore_func(X, y)and keeps thekcolumns with the highest scores. NaN scores rank lowest. Among tied scores the later column is kept, as with scikit-learn’s stable sort.score_funcmay be f_classif(), chi2(), f_regression(), or any callable returning scores or a(scores, pvalues)pair.- Parameters:
score_func (callable, default f_classif) – Function of
(X, y)returning the scores.k (int or ‘all’, default 10) – Number of columns to keep,
0 <= k <= n_features(ValueErrorotherwise), or'all'.
- Variables:
scores_ (array of shape (n_features,)) – Score of each column.
pvalues_ (array of shape (n_features,) or None) – p-value of each column, when
score_funcreturns them.n_features_in_ (int) – Number of columns seen in fit.
numeric_mode_ (str) – Numeric mode at fit time; transform runs in the same mode.
Examples
>>> import numpy as np, mojolearn >>> rng = np.random.default_rng(0) >>> X = rng.random((1000, 20), dtype=np.float32) >>> y = (X[:, 3] > 0.5).astype(np.int64) >>> Xt = mojolearn.SelectKBest(mojolearn.f_classif, k=5).fit_transform(X, y)
Methods
fit(X[, y])fit_transform(X[, y])Fit to
X, then transformX.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.