---
metadata:
  - name: generator
    content: Diplodoc Platform v5.52.0
alternate:
  - https://catboost.ai/docs/en/concepts/python-reference_catboostranker_select_features.md
  - href: en/concepts/python-reference_catboostranker_select_features.md
    type: text/markdown
    title: Markdown version
  - href: ../llms.txt
    type: text/markdown
    title: llms.txt
---
> **Documentation Index:** Fetch the complete configuration index at https://catboost.ai/docs/en/llms.txt

# select_features

## Purpose {#purpose}

<!-- source: en/_includes/work_src/reusage-python/python__select-features__desc.md -->
Select the best features and drop harmful features from the dataset.
<!-- endsource: en/_includes/work_src/reusage-python/python__select-features__desc.md -->


## Method call format {#call-format}

```python
select_features(X,
                y=None,
                eval_set=None,
                features_for_select=None,
                num_features_to_select=None,
                algorithm=None,
                steps=None,
                shap_calc_type=None,
                train_final_model=False,
                verbose=None,
                logging_level=None,
                plot=False,
                log_cout=sys.stdout,
                log_cerr=sys.stderr)
```

## Parameters {#parameters}

### X

#### Description

The input training dataset.

{% note info %}

If a nontrivial value of the `cat_features` parameter is specified in the constructor of this class, CatBoost checks the equivalence of categorical features indices specification from the constructor parameters and in this Pool class.

{% endnote %}

**Possible types**

catboost.Pool

**Default value**

Required parameter

**Supported processing units**

<!-- source: en/_includes/work_src/reusage-python/cpu-and-gpu.md -->
CPU and GPU
<!-- endsource: en/_includes/work_src/reusage-python/cpu-and-gpu.md -->



### y

#### Description

<!-- source: en/_includes/work_src/reusage/label--short-desc-training.md -->
The target variables (in other words, the objects' label values) for the training dataset.
<!-- endsource: en/_includes/work_src/reusage/label--short-desc-training.md -->

<!-- source: en/_includes/work_src/reusage/label--detailed-desc-ranking.md -->
Must be in the form of a one-dimensional array of numeric values.
<!-- endsource: en/_includes/work_src/reusage/label--detailed-desc-ranking.md -->

{% note info %}

Do not use this parameter if the input training dataset (specified in the `X` parameter) type is catboost.Pool.

{% endnote %}

<!-- source: en/_includes/work_src/reusage/label--possible-types-1d-default-supported-processing-units.md -->
**Possible types**

- list
- numpy.ndarray
- pandas.Series
- [polars.Series](https://docs.pola.rs/api/python/stable/reference/series/index.html)

**Default value**

None

**Supported processing units**

CPU and GPU
<!-- endsource: en/_includes/work_src/reusage/label--possible-types-1d-default-supported-processing-units.md -->


### eval_set

#### Description

The validation dataset or datasets used for the following processes:
- [overfitting detector](https://catboost.ai/docs/en/concepts/overfitting-detector.md)
- the best iteration selection
- monitoring metrics' changes

**Possible types**

- catboost.Pool
- tuple (X, y)
- string (path to the dataset file)

**Default value**

None

**Supported processing units**

<!-- source: en/_includes/work_src/reusage-python/cpu-and-gpu.md -->
CPU and GPU
<!-- endsource: en/_includes/work_src/reusage-python/cpu-and-gpu.md -->


### features_for_select

#### Description

Features which participate in the selection. The following formats are supported:
- A list with indices, names, index ranges, name ranges. For example: `[0, 3, 5, 6, '10-15', 'City', 'Player1-Player11']`.
- A string with indices, names, index ranges, name ranges. Values are separated by commas, for example: `0,3,5,6,10-15,City,Player1-Player11`.

**Possible types**
- list
- string

**Default value**

Required parameter

**Supported processing units**

<!-- source: en/_includes/work_src/reusage-python/cpu-and-gpu.md -->
CPU and GPU
<!-- endsource: en/_includes/work_src/reusage-python/cpu-and-gpu.md -->



### num_features_to_select

#### Description

The number of features to select from `features_for_select`.


**Possible types**

int

**Default value**

Required parameter

**Supported processing units**

<!-- source: en/_includes/work_src/reusage-python/cpu-and-gpu.md -->
CPU and GPU
<!-- endsource: en/_includes/work_src/reusage-python/cpu-and-gpu.md -->



### steps

#### Description

The number of times for training the model. Use more steps for more accurate selection.

**Possible types**

int

**Default value**

1

**Supported processing units**

<!-- source: en/_includes/work_src/reusage-python/cpu-and-gpu.md -->
CPU and GPU
<!-- endsource: en/_includes/work_src/reusage-python/cpu-and-gpu.md -->



### algorithm

#### Description

The main algorithm is [Recursive Feature Elimination](https://scikit-learn.org/stable/modules/generated/sklearn.feature_selection.RFE.html) with variable feature importance calculation method:

- `RecursiveByPredictionValuesChange` — the fastest algorithm and the least accurate method (not recommended for ranking losses).
- `RecursiveByLossFunctionChange` — the optimal option according to accuracy/speed balance.
- `RecursiveByShapValues` — the most accurate method.

**Possible types**

EFeaturesSelectionAlgorithm

**Default value**

RecursiveByShapValues

**Supported processing units**

<!-- source: en/_includes/work_src/reusage-python/cpu-and-gpu.md -->
CPU and GPU
<!-- endsource: en/_includes/work_src/reusage-python/cpu-and-gpu.md -->


### shap_calc_type

#### Description

The method of the SHAP values calculations ordered by accuracy:

- `Approximate`
- `Regular`
- `Exact`

Used in RecursiveByLossFunctionChange and RecursiveByShapValues.

**Possible types**

EShapCalcType

**Default value**

Regular

**Supported processing units**

<!-- source: en/_includes/work_src/reusage-python/cpu-and-gpu.md -->
CPU and GPU
<!-- endsource: en/_includes/work_src/reusage-python/cpu-and-gpu.md -->


### train_final_model

#### Description

If specified, then the model with selected features will be trained after features selection.

**Possible types**

bool

**Default value**

True

**Supported processing units**

<!-- source: en/_includes/work_src/reusage-python/cpu-and-gpu.md -->
CPU and GPU
<!-- endsource: en/_includes/work_src/reusage-python/cpu-and-gpu.md -->


### verbose

_Alias:_`verbose_eval`

#### Description

<!-- source: en/_includes/work_src/reusage/python__feature-importances__verbose__short-description__list-intro.md -->
The purpose of this parameter depends on the type of the given value:
<!-- endsource: en/_includes/work_src/reusage/python__feature-importances__verbose__short-description__list-intro.md -->


- bool — Defines the logging level:
    - <q>True</q>  corresponds to the Verbose logging level
    - <q>False</q> corresponds to the Silent logging level

- int — Use the Verbose logging level and set the logging period to the value of this parameter.


{% note alert %}

Do not use this parameter with the `logging_level` parameter.

{% endnote %}

**Possible types**

- bool
- int

**Default value**

1

**Supported processing units**

<!-- source: en/_includes/work_src/reusage-python/cpu-and-gpu.md -->
CPU and GPU
<!-- endsource: en/_includes/work_src/reusage-python/cpu-and-gpu.md -->



### logging_level

#### Description

The logging level to output to stdout.

Possible values:
- Silent — Do not output any logging information to stdout.

- Verbose — Output the following data to stdout:

    - optimized metric
    - elapsed time of training
    - remaining time of training

- Info — Output additional information and the number of trees.

- Debug — Output debugging information.

**Possible types**

string

**Default value**

None (corresponds to the Verbose logging level)

**Supported processing units**

<!-- source: en/_includes/work_src/reusage-python/cpu-and-gpu.md -->
CPU and GPU
<!-- endsource: en/_includes/work_src/reusage-python/cpu-and-gpu.md -->



### plot

#### Description

Plot the following information during training:
- the metric values;
- the custom loss values;
- the loss function change during feature selection;
- the time has passed since training started;
- the remaining time until the end of training.
This [option can be used](https://catboost.ai/docs/en/features/visualization_jupyter-notebook.md) if training is performed in Jupyter notebook.

**Possible types**

bool

**Default value**

False

**Supported processing units**

<!-- source: en/_includes/work_src/reusage-python/cpu.md -->
CPU
<!-- endsource: en/_includes/work_src/reusage-python/cpu.md -->

<!-- source: en/_includes/work_src/reusage-python/python__log-params.md -->
###  log_cout

Output stream or callback for logging.

**Possible types**

- callable Python object
- python object providing the `write()` method

**Default value**

sys.stdout

###  log_cerr

Error stream or callback for logging.

**Possible types**

- callable Python object
- python object providing the `write()` method

**Default value**

sys.stderr
<!-- endsource: en/_includes/work_src/reusage-python/python__log-params.md -->


## Return value {#output-format}

Dict with four fields:
- `selected_features` — a list with indices of selected features.
- `selected_features_names` — a list with names of selected features, if feature names were specified.
- `eliminated_features` — a list with indices of eliminated features.
- `eliminated_features_names` — a list with names of eliminated features, if feature names were specified.
