Class: RFE
Feature ranking with recursive feature elimination.
Given an external estimator that assigns weights to features (e.g., the coefficients of a linear model), the goal of recursive feature elimination (RFE) is to select features by recursively considering smaller and smaller sets of features. First, the estimator is trained on the initial set of features and the importance of each feature is obtained either through any specific attribute or callable. Then, the least important features are pruned from current set of features. That procedure is recursively repeated on the pruned set until the desired number of features to select is eventually reached.
Read more in the User Guide.
Constructors
new RFE()
new RFE(
opts
?):RFE
Parameters
Parameter | Type | Description |
---|---|---|
opts ? | object | - |
opts.estimator ? | any | A supervised learning estimator with a fit method that provides information about feature importance (e.g. coef_ , feature_importances_ ). |
opts.importance_getter ? | string | If ‘auto’, uses the feature importance either through a coef_ or feature_importances_ attributes of estimator. Also accepts a string that specifies an attribute name/path for extracting feature importance (implemented with attrgetter ). For example, give regressor_.coef_ in case of TransformedTargetRegressor or named_steps.clf.feature_importances_ in case of class:~sklearn.pipeline.Pipeline with its last step named clf . If callable , overrides the default feature importance getter. The callable is passed with the fitted estimator and it should return importance for each feature. |
opts.n_features_to_select ? | number | The number of features to select. If undefined , half of the features are selected. If integer, the parameter is the absolute number of features to select. If float between 0 and 1, it is the fraction of features to select. |
opts.step ? | number | If greater than or equal to 1, then step corresponds to the (integer) number of features to remove at each iteration. If within (0.0, 1.0), then step corresponds to the percentage (rounded down) of features to remove at each iteration. |
opts.verbose ? | number | Controls verbosity of output. |
Returns RFE
Defined in generated/feature_selection/RFE.ts:25
Properties
Property | Type | Default value | Defined in |
---|---|---|---|
_isDisposed | boolean | false | generated/feature_selection/RFE.ts:23 |
_isInitialized | boolean | false | generated/feature_selection/RFE.ts:22 |
_py | PythonBridge | undefined | generated/feature_selection/RFE.ts:21 |
id | string | undefined | generated/feature_selection/RFE.ts:18 |
opts | any | undefined | generated/feature_selection/RFE.ts:19 |
Accessors
estimator_
Get Signature
get estimator_():
Promise
<any
>
The fitted estimator used to select features.
Returns Promise
<any
>
Defined in generated/feature_selection/RFE.ts:580
feature_names_in_
Get Signature
get feature_names_in_():
Promise
<ArrayLike
>
Names of features seen during fit. Defined only when X
has feature names that are all strings.
Returns Promise
<ArrayLike
>
Defined in generated/feature_selection/RFE.ts:648
n_features_
Get Signature
get n_features_():
Promise
<number
>
The number of selected features.
Returns Promise
<number
>
Defined in generated/feature_selection/RFE.ts:602
n_features_in_
Get Signature
get n_features_in_():
Promise
<number
>
Number of features seen during fit. Only defined if the underlying estimator exposes such an attribute when fit.
Returns Promise
<number
>
Defined in generated/feature_selection/RFE.ts:625
py
Get Signature
get py():
PythonBridge
Returns PythonBridge
Set Signature
set py(
pythonBridge
):void
Parameters
Parameter | Type |
---|---|
pythonBridge | PythonBridge |
Returns void
Defined in generated/feature_selection/RFE.ts:65
ranking_
Get Signature
get ranking_():
Promise
<ArrayLike
>
The feature ranking, such that ranking_\[i\]
corresponds to the ranking position of the i-th feature. Selected (i.e., estimated best) features are assigned rank 1.
Returns Promise
<ArrayLike
>
Defined in generated/feature_selection/RFE.ts:671
support_
Get Signature
get support_():
Promise
<ArrayLike
>
The mask of selected features.
Returns Promise
<ArrayLike
>
Defined in generated/feature_selection/RFE.ts:693
Methods
decision_function()
decision_function(
opts
):Promise
<any
>
Compute the decision function of X
.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | any [] | The input samples. Internally, it will be converted to dtype=np.float32 and if a sparse matrix is provided to a sparse csr_matrix . |
Returns Promise
<any
>
Defined in generated/feature_selection/RFE.ts:133
dispose()
dispose():
Promise
<void
>
Disposes of the underlying Python resources.
Once dispose()
is called, the instance is no longer usable.
Returns Promise
<void
>
Defined in generated/feature_selection/RFE.ts:116
fit()
fit(
opts
):Promise
<any
>
Fit the RFE model and then the underlying estimator on the selected features.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.fit_params ? | any | Additional parameters passed to the fit method of the underlying estimator. |
opts.X ? | ArrayLike | The training input samples. |
opts.y ? | ArrayLike | The target values. |
Returns Promise
<any
>
Defined in generated/feature_selection/RFE.ts:165
fit_transform()
fit_transform(
opts
):Promise
<any
[]>
Fit to data, then transform it.
Fits transformer to X
and y
with optional parameters fit_params
and returns a transformed version of X
.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.fit_params ? | any | Additional fit parameters. |
opts.X ? | ArrayLike [] | Input samples. |
opts.y ? | ArrayLike | Target values (undefined for unsupervised transformations). |
Returns Promise
<any
[]>
Defined in generated/feature_selection/RFE.ts:208
get_feature_names_out()
get_feature_names_out(
opts
):Promise
<any
>
Mask feature names according to selected features.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.input_features ? | any | Input features. |
Returns Promise
<any
>
Defined in generated/feature_selection/RFE.ts:250
get_metadata_routing()
get_metadata_routing(
opts
):Promise
<any
>
Raise NotImplementedError
.
This estimator does not support metadata routing yet.
Parameters
Parameter | Type |
---|---|
opts | object |
Returns Promise
<any
>
Defined in generated/feature_selection/RFE.ts:284
get_support()
get_support(
opts
):Promise
<any
>
Get a mask, or integer index, of the features selected.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.indices ? | boolean | If true , the return value will be an array of integers, rather than a boolean mask. |
Returns Promise
<any
>
Defined in generated/feature_selection/RFE.ts:310
init()
init(
py
):Promise
<void
>
Initializes the underlying Python resources.
This instance is not usable until the Promise
returned by init()
resolves.
Parameters
Parameter | Type |
---|---|
py | PythonBridge |
Returns Promise
<void
>
Defined in generated/feature_selection/RFE.ts:78
inverse_transform()
inverse_transform(
opts
):Promise
<any
>
Reverse the transformation operation.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | any | The input samples. |
Returns Promise
<any
>
Defined in generated/feature_selection/RFE.ts:344
predict()
predict(
opts
):Promise
<any
>
Reduce X to the selected features and predict using the estimator.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | any | The input samples. |
Returns Promise
<any
>
Defined in generated/feature_selection/RFE.ts:376
predict_log_proba()
predict_log_proba(
opts
):Promise
<any
[]>
Predict class log-probabilities for X.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | any | The input samples. |
Returns Promise
<any
[]>
Defined in generated/feature_selection/RFE.ts:408
predict_proba()
predict_proba(
opts
):Promise
<any
[]>
Predict class probabilities for X.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | any [] | The input samples. Internally, it will be converted to dtype=np.float32 and if a sparse matrix is provided to a sparse csr_matrix . |
Returns Promise
<any
[]>
Defined in generated/feature_selection/RFE.ts:440
score()
score(
opts
):Promise
<number
>
Reduce X to the selected features and return the score of the estimator.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.fit_params ? | any | Parameters to pass to the score method of the underlying estimator. |
opts.X ? | any | The input samples. |
opts.y ? | any | The target values. |
Returns Promise
<number
>
Defined in generated/feature_selection/RFE.ts:472
set_output()
set_output(
opts
):Promise
<any
>
Set output container.
See Introducing the set_output API for an example on how to use the API.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.transform ? | "default" | "pandas" | "polars" | Configure output of transform and fit_transform . |
Returns Promise
<any
>
Defined in generated/feature_selection/RFE.ts:516
transform()
transform(
opts
):Promise
<any
>
Reduce X to the selected features.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | any | The input samples. |
Returns Promise
<any
>
Defined in generated/feature_selection/RFE.ts:548