<a id="skfolio-factor-exposure-onehotcategoricalfactors"></a>

# skfolio.factor_exposure.OneHotCategoricalFactors

<a id="skfolio.factor_exposure.OneHotCategoricalFactors"></a>

### *class* skfolio.factor_exposure.OneHotCategoricalFactors(category, \*, family)

One-hot factor exposures from a categorical field.

Expands a categorical field into one factor per category level. The result is an
exposure tensor with shape `(n_observations, n_assets, n_factors)`, where
`n_factors` is the number of category levels.

For each observation $t$, asset $i$ and category factor $k$, the
exposure is:

$$
x_{t,i,k} =
\begin{cases}
1 & \text{if asset } i \text{ belongs to category } k \\
0 & \text{otherwise}
\end{cases}
$$

Missing category codes produce NaN exposures for all category factors of that
asset-observation pair.

* **Parameters:**
  **category** *str*
  : Name of the categorical field in the AssetPanel to one-hot encode. The field
    must be a `FieldCategorical`.

  **family** *str*
  : The factor family this exposure belongs to (e.g., “industry”, “country”).
    Factor families group related factors for basket-neutral constraints,
    neutralization, attribution and reporting.
* **Attributes:**
  **factor_names_** *ndarray of shape (n_factors,)*
  : The category labels corresponding to each one-hot column.

  **n_assets_** *int*
  : Number of assets seen during fitting.

  **asset_names_** *ndarray of shape (n_assets,)*
  : Asset names seen during fitting.

### Methods

| [`fit_transform`](#skfolio.factor_exposure.OneHotCategoricalFactors.fit_transform)(X[, y])         | One-hot encode the categorical field.          |
|--------------------------------------------------------------------------------|------------------------------------------------|
| [`get_metadata_routing`](#skfolio.factor_exposure.OneHotCategoricalFactors.get_metadata_routing)()        | Get metadata routing of this object.           |
| [`get_params`](#skfolio.factor_exposure.OneHotCategoricalFactors.get_params)([deep])            | Get parameters for this estimator.             |
| [`partial_fit_transform`](#skfolio.factor_exposure.OneHotCategoricalFactors.partial_fit_transform)(X[, y]) | Stateless class delegation to `fit_transform`. |
| [`set_params`](#skfolio.factor_exposure.OneHotCategoricalFactors.set_params)(\*\*params)        | Set the parameters of this estimator.          |

<a id="skfolio.factor_exposure.OneHotCategoricalFactors.fit_transform"></a>

#### fit_transform(X, y=None, \*\*fit_params)

One-hot encode the categorical field.

* **Parameters:**
  **X** *AssetPanel*
  : Input panel containing the categorical field as integer codes.

  **y** *None*
  : Ignored. Present for compatibility with scikit-learn’s API.

  **\*\*fit_params** *dict*
  : Additional fit parameters. They are ignored.
* **Returns:**
  **exposures** *ndarray of shape (n_observations, n_assets, n_factors)*
  : One-hot encoded exposures. Column order matches `X.fields[category].levels`.
    Entries with missing codes (MISSING_CATEGORY_CODE == -1) are filled with
    NaN.
* **Raises:**
  IndexError
  : If any valid code is >= n_levels (indicates data corruption).

<a id="skfolio.factor_exposure.OneHotCategoricalFactors.get_metadata_routing"></a>

#### get_metadata_routing()

Get metadata routing of this object.

Please check [User Guide](https://skfolio.org/user_guide/metadata_routing.html.md#metadata-routing) on how the routing
mechanism works.

* **Returns:**
  **routing** *MetadataRequest*
  : A `MetadataRequest` encapsulating
    routing information.

<a id="skfolio.factor_exposure.OneHotCategoricalFactors.get_params"></a>

#### get_params(deep=True)

Get parameters for this estimator.

* **Parameters:**
  **deep** *bool, default=True*
  : If True, will return the parameters for this estimator and
    contained subobjects that are estimators.
* **Returns:**
  **params** *dict*
  : Parameter names mapped to their values.

<a id="skfolio.factor_exposure.OneHotCategoricalFactors.partial_fit_transform"></a>

#### partial_fit_transform(X, y=None, \*\*fit_params)

Stateless class delegation to `fit_transform`.

<a id="skfolio.factor_exposure.OneHotCategoricalFactors.set_params"></a>

#### set_params(\*\*params)

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects
(such as `Pipeline`). The latter have
parameters of the form `<component>__<parameter>` so that it’s
possible to update each component of a nested object.

* **Parameters:**
  **\*\*params** *dict*
  : Estimator parameters.
* **Returns:**
  **self** *estimator instance*
  : Estimator instance.

