> ## Documentation Index
> Fetch the complete documentation index at: https://aidflow.aigensys.com/llms.txt
> Use this file to discover all available pages before exploring further.

# DataEncoderWorker

> AID.data.interface.DataEncoderWorker

```python theme={"theme":{"light":"dracula-soft","dark":"dracula"}}
from AID.data.interface import DataEncoderWorker
```

Step 9: ML Sample Generation & Synchronization.

Acts as the final synchronization point before agent training. It applies    all previously trained encoding transformation logic (Numerical, Categorical, and WOE)    to create synchronized 'ml' versions of the training and test sets.

This method ensures that the exact same encoding pipelines trained during    the Encoding Phase are applied consistently across both datasets,    preventing data leakage and ensuring model validity.

> [!NOTE]
>
> * DataEncoder serves as the entry point to the agent training phase.
> * It applies all fitted encodings to transform input data into ML-ready datasets.
> * Any new data sharing the original training schema can be passed in directly without    requiring a separate test split - new input data are split to train and test part.
> * Results are registered under `ctx.datasets` as `train.ml` and `test.ml`.

#### Parameters

**`inputs`** : *`DataEncoderInput`*
Custom input configuration for sample generation. If None, resolves        defaults from the current pipeline state (train\_set, test\_set, woe\_features).

**`**kwargs`** : *`dict`*
Additional parameters passed to the DataEncoder worker.

> [!NOTE]
>
> Inputs full schema can be obtained by `ctx.workers.data_encoder.spec` with main params:
>
> <table>
>   <tbody>
>     <tr><td>`inputs    == None`</td><td>→</td><td>pipeline data context</td></tr>
>     <tr><td>`train_set != None`</td><td>→</td><td>custom train data for encoding application by data\_encoder</td></tr>
>     <tr><td>`test_set  != None`</td><td>→</td><td>custom test for encoding application by data\_encoder</td></tr>
>     <tr><td>`woe_features != None`</td><td>→</td><td>optional subset of woe features</td></tr>
>   </tbody>
> </table>

#### Returns

*`DataEncoderWorker`*
The populated instance of DataEncoderWorker.

> [!NOTE]
>
> Populates attributes into the worker context:
>
> <table>
>   <tbody>
>     <tr><td>`model`</td><td>→</td><td>ctx.workers.data\_encoder</td></tr>
>     <tr><td>`inputs`</td><td>→</td><td>ctx.workers.data\_encoder.spec</td></tr>
>     <tr><td>`result`</td><td>→</td><td>ctx.workers.data\_encoder.result</td></tr>
>     <tr><td>`state`</td><td>→</td><td>ctx.workers.data\_encoder.state</td></tr>
>     <tr><td>`stats`</td><td>→</td><td>ctx.workers.data\_encoder.stats</td></tr>
>     <tr><td>`fitter`</td><td>→</td><td>ctx.workers.data\_encoder.fitter</td></tr>
>   </tbody>
> </table>

> [!NOTE]
>
> Registers data into the datasets context:
>
> <table>
>   <tbody>
>     <tr><td>`data`</td><td>→</td><td>ctx.datasets.train.ml</td></tr>
>     <tr><td>`data`</td><td>→</td><td>ctx.datasets.test.ml</td></tr>
>     <tr><td>`dtypes`</td><td>→</td><td>ctx.datasets.dtypes.ml</td></tr>
>     <tr><td>`features`</td><td>→</td><td>ctx.datasets.all.ml</td></tr>
>     <tr><td>`stats`</td><td>→</td><td>ctx.datasets.stats.ml</td></tr>
>   </tbody>
> </table>

#### Examples

Defining the Project Context (Control Plane) & Project Scope:

```python theme={"theme":{"light":"dracula-soft","dark":"dracula"}}
import aidflow as aid

ctx = aid.ProjectContext()

ctx.genesis(
    project      = 'test',
    input_data   = 'test.csv',
    target       = 'target',
    yy_mm        = 'decision_date',
    yy_mm_format = '%Y-%m-%d'
)
ctx.params()
```

### Worker → Model → Fitter

Accessing worker's inputs schema → parameters & types (*shown in the display output*):

```python theme={"theme":{"light":"dracula-soft","dark":"dracula"}}
ctx.workers.data_encoder.spec
```

Accessing model's fitter options and schema → parameters & types
(*shown in the display output*):

```python theme={"theme":{"light":"dracula-soft","dark":"dracula"}}
ctx.workers.data_encoder.fitters
```

Executing workers with defaults → auto provided by the context:

```python theme={"theme":{"light":"dracula-soft","dark":"dracula"}}
ctx.workers.data_loader()    # 0. import data to the context scope
ctx.workers.fe_cleaner()     # 1. apply cleaning logic to the imported data (0)
ctx.workers.fe_stabilizer()  # 2. apply temporal stability logic to the cleaned data (1)
ctx.workers.obs_stabilizer() # 3. apply observation stability logic to the cleaned data (2)
ctx.workers.num_encoder()    # 4. apply numerical encoding logic to the stable data (3)
ctx.workers.cat_encoder()    # 5. apply categorical encoding logic to the stable data (3)
ctx.workers.ixn_encoder()    # 6. apply interactions encoding logic to the stable data (3)
ctx.workers.woe_encoder()    # 7. apply woe encoding logic using trained encoding in steps (4-5-6)
ctx.workers.woe_stabilizer() # 8. apply woe stabilization logic using trained woe encoding in step (7)
ctx.workers.data_encoder()   # 9. apply trained encodings (4-7) to transform train-test data
```

Note that steps 0-3 and steps 4-9 can be run by ExecutionContext one-liner:

```python theme={"theme":{"light":"dracula-soft","dark":"dracula"}}
ctx.flow.process('data', verbose = 0)     # steps 0 - 3 have been trained within the context scope
ctx.flow.process('encoding', verbose = 0) # steps 4 - 9 have been trained within the context scope
```

Once worker has been executed, thus its main model has been built,    we have access to all populated attributes.

```python theme={"theme":{"light":"dracula-soft","dark":"dracula"}}
worker   = ctx.workers.data_encoder
inputs   = worker.spec.inputs
result   = worker.result
state    = worker.state
features = worker.features
params   = worker.params
stats    = worker.stats
fitter   = worker.fitter  # jump to chosen internal fitter
...
```

### Model → Fitter

Once worker has been executed, we can obtain internal fitter state    and its parametrization (*shown in the display output*):

```python theme={"theme":{"light":"dracula-soft","dark":"dracula"}}
ctx.workers.data_encoder.fitter
```

The fitted fitter provides all populated attributes.

```python theme={"theme":{"light":"dracula-soft","dark":"dracula"}}
fitter    = ctx.workers.data_encoder.fitter
params_   = fitter.params
stats_    = fitter.stats
```

Use new data to apply fitted encodings to obtain ML-ready datasets:

```python theme={"theme":{"light":"dracula-soft","dark":"dracula"}}
data2 = ... # new pd.dataframe with the orig. training schema
ctx.workers.data_encoder(train_set = data2)
```

Obtaining created ML-ready sets (auto-provided to agents):

```python theme={"theme":{"light":"dracula-soft","dark":"dracula"}}
train = ctx.datasets.train.ml
test  = ctx.datasets.test.ml
```

Direct choice and parametrization of internal fitter:

```python theme={"theme":{"light":"dracula-soft","dark":"dracula"}}
fx  = ctx.workers.data_encoder.fitters[0]
prm = dict(
    preprocess = True,
    remove_outliers = False
)
data_encoder = ctx.workers.data_encoder(fx_choice = fx, fx_params = prm)
```

```python theme={"theme":{"light":"dracula-soft","dark":"dracula"}}
cfg = dict(
    time_var  = 'time_var2',
    test_size = 0.3
)
data_encoder = ctx.workers.data_encoder(fx_config = cfg)
```

#### Attributes

> [!NOTE]
>
> All worker attributes return `None` prior its execution.

| Attribute | Type | Description |
| :- | :- | :- |
| `inputs` | `ModelInput` | Registered populated inputs containing execution timestamps and feature definitions. |
| `result` | `ModelResult` | Execution output payload containing model predictions and fit results. |
| `fitter` | `Fitter` | Underlying fitted estimator instance. |
| `state` | `ModelState` | Consolidated model state (fitter, choice, params, features, report, stats). |
| `report` | `DashboardInterface` | Interactive report interface. Call `report.show()` to render the visualization dashboard. |
| `stats` | `FitStats` | Performance metrics and training metadata gathered during fitting. |
| `features` | `TransResCols` | Feature schema dataclass required for downstream inference. |
| `params` | `tuple[FitParams, Parameters, ...]` | Tuple of fit settings, execution parameters, optionally transformer parameters. |
| `choice` | `RegGet.Choice` | Active configuration parameters including internal fitter choice (`fx_choice`). |
| `model_signature` | `str` | Unique hash identifier for the fitted model instance. |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.