<a id="skfolio-base-baseassetpaneltransformer"></a>

# skfolio.base.BaseAssetPanelTransformer

<a id="skfolio.base.BaseAssetPanelTransformer"></a>

### *class* skfolio.base.BaseAssetPanelTransformer

Base class for estimators that transform asset panel data.

Descriptors and factor exposure estimators take an
[`AssetPanel`](https://skfolio.org/generated/skfolio.containers.AssetPanel.html.md#skfolio.containers.AssetPanel) and return transformed values indexed by
observation and asset. Most transformers return an array with shape
`(n_observations, n_assets)`. Transformers that produce multiple values per asset,
such as [`OneHotCategoricalFactors`](https://skfolio.org/generated/skfolio.factor_exposure.OneHotCategoricalFactors.html.md#skfolio.factor_exposure.OneHotCategoricalFactors), return an array
with shape `(n_observations, n_assets, n_categories)`.

In scikit-learn, `fit` and `partial_fit` update fitted state, stored in trailing
underscore attributes, while `transform` returns transformed input data using that
state. This separation is not suitable for every
[`AssetPanel`](https://skfolio.org/generated/skfolio.containers.AssetPanel.html.md#skfolio.containers.AssetPanel) transformer. For some estimators, the
transformed value is produced by the same state transition that updates the
estimator. A separate `transform` method would either need to mutate state or
depend on a preceding `partial_fit` call, so the API exposes the combined
operation directly. For example, the exponentially weighted momentum
descriptor [`EWMomentum`](https://skfolio.org/generated/skfolio.descriptor.EWMomentum.html.md#skfolio.descriptor.EWMomentum) needs to update its internal
EWMA state to compute the transformed value on each observation.

Other transformers are independent across observations. For example, the
[`DividendToPrice`](https://skfolio.org/generated/skfolio.descriptor.DividendToPrice.html.md#skfolio.descriptor.DividendToPrice) descriptor depends only on the current
`dividends_ttm` and `market_cap` values and can therefore be declared stateless.

Accordingly, `fit_transform` is used for full-batch computation and
`partial_fit_transform` for online computation. Subclasses must implement
`fit_transform`. Downstream meta-estimators use the presence of
`partial_fit_transform` to determine whether a transformer supports online
transformation.

Supported implementation patterns are:

- Batch-only transformers implement only `fit_transform`.
- Stateless transformers declare `stateless=True` and implement only `fit_transform`.
  The base class adds `partial_fit_transform` as a direct delegation to `fit_transform`.
- Online transformers implement both `fit_transform` and `partial_fit_transform`.

* **Attributes:**
  **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.base.BaseAssetPanelTransformer.fit_transform)(X[, y])   | Fit the transformer if needed and return transformed values.   |
|--------------------------------------------------------------------------|----------------------------------------------------------------|
| [`get_metadata_routing`](#skfolio.base.BaseAssetPanelTransformer.get_metadata_routing)()  | Get metadata routing of this object.                           |
| [`get_params`](#skfolio.base.BaseAssetPanelTransformer.get_params)([deep])      | Get parameters for this estimator.                             |
| [`set_params`](#skfolio.base.BaseAssetPanelTransformer.set_params)(\*\*params)  | Set the parameters of this estimator.                          |

#### SEE ALSO
[`BaseDescriptor`](https://skfolio.org/generated/skfolio.descriptor.BaseDescriptor.html.md#skfolio.descriptor.BaseDescriptor)
: Computes raw descriptor values.

[`BaseFactorExposure`](https://skfolio.org/generated/skfolio.factor_exposure.BaseFactorExposure.html.md#skfolio.factor_exposure.BaseFactorExposure)
: Computes factor exposures.

<a id="skfolio.base.BaseAssetPanelTransformer.fit_transform"></a>

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

Fit the transformer if needed and return transformed values.

* **Parameters:**
  **X** *AssetPanel*
  : Input panel data.

  **y** *None*
  : Ignored. Present for API consistency.

  **\*\*fit_params** *dict*
  : Additional fit parameters. Metadata routing may pass these parameters to
    sub-estimators when applicable.
* **Returns:**
  **values** *ndarray of shape (n_observations, n_assets) or (n_observations, n_assets, n_components)*
  : Transformed values.

<a id="skfolio.base.BaseAssetPanelTransformer.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.base.BaseAssetPanelTransformer.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.base.BaseAssetPanelTransformer.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.

