# Data Encoding (DP\_3)

This process involves converting data into a format that can be understood by a computer. This can include converting text into numerical values, or categorizing data into discrete groups. The goal of encoding is to make it possible for a machine learning algorithm to interpret and learn from the data.

There are many different types of encoding techniques, such as one-hot encoding, which converts categorical data into a binary format, and label encoding, which assigns a unique numerical value to each category in a categorical variable. The appropriate encoding technique depends on the type of data and the machine learning algorithm being used.

## Sample Request

This request encodes categorical values in the X variable with `one-hot` method, ignoring values in the Y variable.

```javascript
{
    "project_id": 1,
    "parent_id": 2,
    "block_id": 3,
    "function_code": "DP_3",
    "args": {
        "xvalue": {
            "encode": true,
            "encoding_type": "onehot",
            "remainder": "passthrough",
            "index": 0
        },
        "yvalue": {
            "encode": false,
            "encoding_type": "categorical",
            "remainder": "drop",
            "index": 2
        }
        "save_name": "testweights",
        "load_name": "testweights"
    }
}
```

## Encoding Data

## Encode categorical values

<mark style="color:green;">`POST`</mark> `https://autogon.ai/api/v1/engine/start`

Encodes categorical data on specific columns with specified boundaries

#### Request Body

| Name                                             | Type   | Description                                                                                                                                                                                                                                                                                                                                                                                                |
| ------------------------------------------------ | ------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| project\_id<mark style="color:red;">\*</mark>    | int    | current project ID                                                                                                                                                                                                                                                                                                                                                                                         |
| parent\_id<mark style="color:red;">\*</mark>     | int    | parent block ID                                                                                                                                                                                                                                                                                                                                                                                            |
| block\_id<mark style="color:red;">\*</mark>      | int    | current block ID                                                                                                                                                                                                                                                                                                                                                                                           |
| function\_code<mark style="color:red;">\*</mark> | String | block's function code                                                                                                                                                                                                                                                                                                                                                                                      |
| xvalue/yvalue<mark style="color:red;">\*</mark>  | object | arguments for X or Y variables                                                                                                                                                                                                                                                                                                                                                                             |
| encode<mark style="color:red;">\*</mark>         | bool   | specify if variable is encoded                                                                                                                                                                                                                                                                                                                                                                             |
| args                                             | object | block arguments                                                                                                                                                                                                                                                                                                                                                                                            |
| encoding\_type<mark style="color:red;">\*</mark> | String | <p>One-Hot Encoding: Converts categories into binary columns.<br><br>Label Encoding: Assigns numbers to categories.</p><p></p><p>Binary Encoding: Represents categories as binary codes.</p><p></p><p>Target Encoding: Replaces categories with target stats.</p><p></p><p>String to Hash Encoding: Hashes strings to numbers.</p><p></p><p>Extract Numbers Encoding: Converts text numbers to digits.</p> |
| remainder<mark style="color:red;">\*</mark>      | String | applied method to none specified columns; `drop` drops the unspecified columns for encoding, `passthrough` ignores unspecified columns                                                                                                                                                                                                                                                                     |
| index<mark style="color:red;">\*</mark>          | int    | column index to apply encoding technique                                                                                                                                                                                                                                                                                                                                                                   |
| save\_name                                       | String | name to save processing models with.                                                                                                                                                                                                                                                                                                                                                                       |
| load\_name                                       | String | name to load processing models with. Used to switch to loading mode                                                                                                                                                                                                                                                                                                                                        |

{% tabs %}
{% tab title="200: OK Data Encode Successful" %}

```javascript
{
    "status": "true",
    "message": {
        "id": 3,
        "project": 1,
        "block_id": 3,
        "parent_id": 2,
        "dataset_url": "",
        "x_value_url": "",
        "y_value_url": ""
    }
}
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Python" %}

```
// Some code
```

{% endtab %}

{% tab title="Node" %}

```
// Some code
```

{% endtab %}
{% endtabs %}
