mojolearn.RFE#
- class mojolearn.RFE(estimator, *, n_features_to_select=None, step=1, verbose=0, importance_getter='auto')[source]#
Bases:
_SelectorMixinFeature ranking with recursive feature elimination.
Follows scikit-learn’s
RFE. The estimator is fitted on the current features, thestepweakest are removed, and the process repeats untiln_features_to_selectremain. Importance is the squaredcoef_(summed over rows when 2-D) orfeature_importances_. Ties are broken by a stable sort: of two equally weak columns, the lower index is removed first (scikit-learn leaves the order unspecified).The estimator is cloned with
type(estimator)(**estimator.get_params())and fitted on float32 data.predict,predict_proba,decision_functionandscoreapply the final estimator to the selected columns.- Parameters:
estimator (object) – Estimator with
fitthat exposescoef_orfeature_importances_(ValueErrorotherwise, withimportance_getter='auto').n_features_to_select (int or float, default None) – Number of features to keep, or a fraction of them when a float in
(0, 1). None keeps half.step (int or float, default 1) – Number of features removed per iteration, or a fraction of the features when a float in
(0, 1). Must be greater than 0.verbose (int, default 0) – Accepted for scikit-learn compatibility.
importance_getter (‘auto’, str or callable, default ‘auto’) –
'auto'usescoef_orfeature_importances_; a dotted attribute path or a callable taking the estimator picks the importances instead (they are squared).
- Variables:
estimator_ (object) – Estimator fitted on the selected features.
n_features_ (int) – Number of selected features.
ranking_ (array of int64) – Rank of each feature; selected features have rank 1.
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, 10), dtype=np.float32) >>> y = (X[:, 0] + X[:, 1] > 1).astype(np.int64) >>> rfe = mojolearn.RFE(mojolearn.LinearDiscriminantAnalysis(), n_features_to_select=3).fit(X, y) >>> rfe.support_
- __init__(estimator, *, n_features_to_select=None, step=1, verbose=0, importance_getter='auto')[source]#
Methods
decision_function(X)fit(X, y, **fit_params)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.
predict(X)predict_proba(X)score(X, y)set_params(**params)Set constructor parameters.
transform(X)Keep only the selected columns of
X.