macrosynergy.learning.forecasting.meta_estimators.dataframe_transformer#
- class DataFrameTransformer(transformer, column_names=None)[source]#
Bases:
BaseEstimator,TransformerMixin,MetaEstimatorMixinMeta estimator to reconvert a transformed numpy array back to a multiindexed pandas DataFrame. This maintains the multi-indexed panel structure.
- Parameters:
transformer (TransformerMixin) – A scikit-learn transformer with a fit and transform method.
Notes
Many scikit-learn compatible transformers convert pandas DataFrames to numpy arrays. This can be problematic when working with panel models that require knowledge of the panel structure. This class wraps around such transformers to ensure that the output is a pandas DataFrame, preserving the original index.
When no column names are provided, default names of the form “Factor_0”, “Factor_1”, etc. are used for the transformed DataFrame. If column names are provided, they will be used instead.
- fit(X, y=None)[source]#
Fit the underlying transformer.
- Parameters:
X (pd.DataFrame) – Pandas dataframe of input features.
y (pd.Series or pd.DataFrame or np.ndarray) – Pandas series, dataframe or numpy array of targets associated with each sample in X.
- transform(X)[source]#
Transform the input data based on the underlying transformer, but return a pandas DataFrame instead of a numpy array.
- Parameters:
X (pd.DataFrame or numpy array) – Input feature matrix.
- Returns:
Transformed data as a pandas DataFrame, preserving the original index and using either provided column names or default names.
- Return type:
pd.DataFrame