---
metadata:
  - name: generator
    content: Diplodoc Platform v5.52.0
alternate:
  - https://catboost.ai/docs/en/concepts/python-reference_utils_quantize.md
  - href: en/concepts/python-reference_utils_quantize.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

# quantize

<!-- source: en/_includes/work_src/reusage-python/pool__quantize__div.md -->
Create a pool from a file and quantize it while loading the data. This compresses the size of the initial dataset and provides an opportunity to load huge datasets that can not be loaded to RAM otherwise.
{% note info %}

The input data should contain only numerical features (other types are not currently supported).

{% endnote %}

This method gives an identical result to implementing the following code but is less RAM consuming:
```python
pool = Pool(filename, **some_pool_load_params)
pool.quantize(**some_quantization_params)
return pool
```
<!-- endsource: en/_includes/work_src/reusage-python/pool__quantize__div.md -->

## Method call format {#call-format}

```python
quantize(data_path,
         column_description=None,
         pairs=None,
         graph=None,
         delimiter='\t',
         has_header=False,
         feature_names=None,
         thread_count=-1,
         ignored_features=None,
         per_float_feature_quantization=None,
         border_count=None,
         max_bin=None,
         feature_border_type=None,
         nan_mode=None,
         input_borders=None,
         task_type=None,
         used_ram_limit=None,
         random_seed=None)
```

## Parameters {#parameters}

### data_path

#### Description

The path to the input file that contains the dataset.

<!-- source: en/_includes/work_src/reusage-formats/files-internal__desc__full.md -->
Format:
```
[scheme://]<path>
```

- `scheme` (optional) defines the type of the input dataset. Possible values:

    - `quantized://` — catboost.Pool [quantized](https://catboost.ai/docs/en/concepts/python-reference_pool_quantized.md) pool.
    - `libsvm://` — dataset in the [extended libsvm format](https://catboost.ai/docs/en/concepts/input-data_libsvm.md).

    If omitted, a dataset in the [Native CatBoost Delimiter-separated values format](https://catboost.ai/docs/en/concepts/input-data_values-file.md) is expected.

- `path` defines the path to the dataset file.
<!-- endsource: en/_includes/work_src/reusage-formats/files-internal__desc__full.md -->

**Possible types**

string

**Default value**

Obligatory parameter

### column_description

#### Description

The path to the input file  that contains the [columns description](https://catboost.ai/docs/en/concepts/input-data_column-descfile.md).


**Possible types**

string

**Default value**

None

### pairs

#### Description

The path to the input file that contains the [pairs description](https://catboost.ai/docs/en/concepts/input-data_pairs-description.md).

<!-- source: en/_includes/work_src/reusage/learn_pairs__where_is_used.md -->
This information is used for calculation and optimization of [Pairwise metrics](https://catboost.ai/docs/en/concepts/loss-functions-ranking.md).
<!-- endsource: en/_includes/work_src/reusage/learn_pairs__where_is_used.md -->

**Possible types**

string

**Default value**

<!-- source: en/_includes/work_src/reusage/python__pairs__default-short.md -->
None
<!-- endsource: en/_includes/work_src/reusage/python__pairs__default-short.md -->

### graph

#### Description

The path to the input file that contains the [graph information](https://catboost.ai/docs/en/concepts/input-data_graph-description.md) for the dataset.

<!-- source: en/_includes/work_src/reusage/graph__where_is_used.md -->
Graph information is used to calculate the [graph aggregated features](https://catboost.ai/docs/en/features/graph-aggregated-features.md).
<!-- endsource: en/_includes/work_src/reusage/graph__where_is_used.md -->

**Possible types**

string

**Default value**

None

### delimiter

#### Description

The delimiter character used to separate the data in the dataset input file.

Only single char delimiters are supported. If the specified value contains more than one character, only the first one is used.

<!-- source: en/_includes/work_src/reusage-formats/note-restriction-delimiter-separated-format.md -->
{% note info %}

Used only if the dataset is given in the [Delimiter-separated values format](https://catboost.ai/docs/en/concepts/input-data_values-file.md).

{% endnote %}
<!-- endsource: en/_includes/work_src/reusage-formats/note-restriction-delimiter-separated-format.md -->

**Possible types**

The input data is assumed to be tab-separated

**Default values**

CPU and GPU

### has_header

#### Description

Read the column names from the first line of the dataset file if this parameter is set.

<!-- source: en/_includes/work_src/reusage-formats/note-restriction-delimiter-separated-format.md -->
{% note info %}

Used only if the dataset is given in the [Delimiter-separated values format](https://catboost.ai/docs/en/concepts/input-data_values-file.md).

{% endnote %}
<!-- endsource: en/_includes/work_src/reusage-formats/note-restriction-delimiter-separated-format.md -->

**Possible types**

bool

**Default value**

False

### feature_names

#### Description

A list of names for each feature in the dataset.

**Possible types**

list

**Default value**

None

### thread_count

#### Description

The number of threads to use.

<!-- source: en/_includes/work_src/reusage/thread_count__cpu_cores__optimizes-the-speed-of-execution.md -->
Optimizes the speed of execution. This parameter doesn't affect results.
<!-- endsource: en/_includes/work_src/reusage/thread_count__cpu_cores__optimizes-the-speed-of-execution.md -->

**Possible types**

int

**Default values**

-1 (the number of threads is equal to the number of processor cores)

### ignored_features

#### Description

<!-- source: en/_includes/work_src/reusage/ignored-feature__common-div.md -->
Feature indices or names to exclude from the training. It is assumed that all passed values are feature names if at least one of the passed values can not be converted to a number or a range of numbers. Otherwise, it is assumed that all passed values are feature indices.

Specifics:

- Non-negative indices that do not match any features are successfully ignored. For example, if five features are defined for the objects in the dataset and this parameter is set to <q>42</q>, the corresponding non-existing feature is successfully ignored.

- The identifier corresponds to the feature's index. Feature indices used in train and feature importance are numbered from 0 to `featureCount – 1`. If a file is used as [input data](https://catboost.ai/docs/en/concepts/input-data.md) then any non-feature column types are ignored when calculating these indices. For example, each row in the input file contains data in the following order: `cat feature<\t>label value<\t>num feature`. So for the row `rock<\t>0<\t>42`, the identifier for the <q>rock</q> feature is 0, and for the <q>42</q> feature it's 1.


- The addition of a non-existing feature name raises an error.
<!-- endsource: en/_includes/work_src/reusage/ignored-feature__common-div.md -->


For example, use the following construction if features indexed 1, 2, 7, 42, 43, 44, 45, should be ignored:
```
[1,2,7,42,43,44,45]
```

**Possible types**

list

**Default value**

None

### per_float_feature_quantization

#### Description

<!-- source: en/_includes/work_src/reusage/python__per-float-feature-quantization__desc-without-examples.md -->
The quantization description for the specified feature or list of features.

Description format for a single feature:
```
FeatureId[:border_count=BorderCount][:nan_mode=BorderType][:border_type=border_selection_method]
```
<!-- endsource: en/_includes/work_src/reusage/python__per-float-feature-quantization__desc-without-examples.md -->


Example:

<!-- source: en/_includes/work_src/reusage/python__per_float_feature_quantization__string_example.md -->
```python
per_float_feature_quantization=['0:border_count=1024', '1:border_count=1024']
```

In this example, features indexed 0 and 1 have 1024 borders.
<!-- endsource: en/_includes/work_src/reusage/python__per_float_feature_quantization__string_example.md -->


**Possible types**

list of strings

**Default value**

GreedyLogSum

### border_count

_Alias:_`max_bin`

#### Description

The number of splits for numerical features. Allowed values are integers from 1 to 65535 inclusively.

**Possible types**

int

**Default value**

The default value depends on the processing unit type:
- CPU: 254
- GPU: 128


### feature_border_type

#### Description

The [quantization mode](https://catboost.ai/docs/en/concepts/quantization.md) for numerical features.

Possible values:
- Median
- Uniform
- UniformAndQuantiles
- MaxLogSum
- MinEntropy
- GreedyLogSum

**Possible types**

string

**Default value**

GreedyLogSum

### nan_mode

#### Description

The method for  [processing missing values](https://catboost.ai/docs/en/concepts/algorithm-missing-values-processing.md) in the input dataset.

<!-- source: en/_includes/work_src/reusage/cmd__nan-mode__div.md -->
Possible values:

<!-- source: en/_includes/work_src/reusage-missing-values/mv-processing-methods.md -->
- "Forbidden" — Missing values are not supported, their presence is interpreted as an error.
- "Min" — Missing values are processed as the minimum value (less than all other values) for the feature. It is guaranteed that a split that separates missing values from all other values is considered when selecting trees.
- "Max" — Missing values are processed as the maximum value (greater than all other values) for the feature. It is guaranteed that a split that separates missing values from all other values is considered when selecting trees.
<!-- endsource: en/_includes/work_src/reusage-missing-values/mv-processing-methods.md -->

Using the  Min or Max value of this parameter guarantees that a split between missing values and other values is considered when selecting a new split in the tree.

{% note info %}

The method for processing missing values can be set individually for each feature in the [Custom quantization borders and missing value modes](https://catboost.ai/docs/en/concepts/input-data_custom-borders.md) input file. Such values override the ones specified in this parameter.

{% endnote %}
<!-- endsource: en/_includes/work_src/reusage/cmd__nan-mode__div.md -->

**Possible types**

string

**Default value**

Min

### input_borders

#### Description

Load [Custom quantization borders and missing value modes](https://catboost.ai/docs/en/concepts/input-data_custom-borders.md) from a file (do not generate them).

Borders are automatically generated before training if this parameter is not set.

**Possible types**

string

**Default value**

None

### task_type

#### Description

The processing unit type to use for training.

Possible values:
- CPU
- GPU

**Possible types**

string

**Default value**

CPU

### used_ram_limit

#### Description

Attempt to limit the amount of used CPU RAM.

{% note alert %}

- This option affects only the CTR calculation memory usage.
- In some cases it is impossible to limit the amount of CPU RAM used in accordance with the specified value.

{% endnote %}


Format:
```
<size><measure of information>
```

Supported measures of information (non case-sensitive):
- MB
- KB
- GB

For example:
```
2gb
```
**Possible types**

int

**Default value**

None (memory usage is no limited)

### random_seed

#### Description

The random seed used for training.

**Possible types**

int

**Default value**

None (0)


## Type of return value {#output-format}

catboost.Pool (a quantized pool)

## Usage examples {#usage-examples}

The following is the input file with the dataset:

```
4	52	64	73
3	87	32	54
9	34	35	45
8	9	83	32
```

The pool is created as follows:

```python
from catboost.utils import quantize

quantized_pool=quantize(data_path="pool__utils__quantize_data")
print(type(quantized_pool))
```

The output of this example:
```
<class 'catboost.core.Pool'>
```
