skfolio.base.BaseAssetPanelTransformer#
- class skfolio.base.BaseAssetPanelTransformer[source]#
Base class for estimators that transform asset panel data.
Descriptors and factor exposure estimators take an
AssetPaneland 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 asOneHotCategoricalFactors, return an array with shape(n_observations, n_assets, n_categories).In scikit-learn,
fitandpartial_fitupdate fitted state, stored in trailing underscore attributes, whiletransformreturns transformed input data using that state. This separation is not suitable for everyAssetPaneltransformer. For some estimators, the transformed value is produced by the same state transition that updates the estimator. A separatetransformmethod would either need to mutate state or depend on a precedingpartial_fitcall, so the API exposes the combined operation directly. For example, the exponentially weighted momentum descriptorEWMomentumneeds to update its internal EWMA state to compute the transformed value on each observation.Other transformers are independent across observations. For example, the
DividendToPricedescriptor depends only on the currentdividends_ttmandmarket_capvalues and can therefore be declared stateless.Accordingly,
fit_transformis used for full-batch computation andpartial_fit_transformfor online computation. Subclasses must implementfit_transform. Downstream meta-estimators use the presence ofpartial_fit_transformto determine whether a transformer supports online transformation.Supported implementation patterns are:
Batch-only transformers implement only
fit_transform.Stateless transformers declare
stateless=Trueand implement onlyfit_transform. The base class addspartial_fit_transformas a direct delegation tofit_transform.Online transformers implement both
fit_transformandpartial_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(X[, y])Fit the transformer if needed and return transformed values.
Get metadata routing of this object.
get_params([deep])Get parameters for this estimator.
set_params(**params)Set the parameters of this estimator.
See also
BaseDescriptorComputes raw descriptor values.
BaseFactorExposureComputes factor exposures.
- abstractmethod fit_transform(X, y=None, **fit_params)[source]#
Fit the transformer if needed and return transformed values.
- Parameters:
- XAssetPanel
Input panel data.
- yNone
Ignored. Present for API consistency.
- **fit_paramsdict
Additional fit parameters. Metadata routing may pass these parameters to sub-estimators when applicable.
- Returns:
- valuesndarray of shape (n_observations, n_assets) or (n_observations, n_assets, n_components)
Transformed values.
- get_metadata_routing()#
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
- Returns:
- routingMetadataRequest
A
MetadataRequestencapsulating routing information.
- get_params(deep=True)#
Get parameters for this estimator.
- Parameters:
- deepbool, default=True
If True, will return the parameters for this estimator and contained subobjects that are estimators.
- Returns:
- paramsdict
Parameter names mapped to their values.
- 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:
- **paramsdict
Estimator parameters.
- Returns:
- selfestimator instance
Estimator instance.