FeatureEngineFeatureTransformer¶
This class is a subclass of BaseFeatureTransformer and is used for transforming input data using feature_engine transformers. It provides methods for fitting and transforming the data.
Configuration¶
Required Configuration¶
FeatureTransformerFeatureTransformer contains the following configuration:
transformers: A list of transformers to run. Each transformer is a dictionary with the following entries:transformer: Thefeature_engineclass to use as the transformer. Required.transformer_args: A list of arguments to pass into the transformer. Optional.transformer_kwargs: A dictionary of keyword arguments to pass into the transformer. Optional.transformer_columns: A list of columns names to apply the transformer to.
Optional Configuration¶
FeatureTransformerFeatureTransformer contains the following optional configuration:
pipeline_kwargs: A dictionary of keyword arguments to pass into thesklearn.pipeline.Pipelineobject that is used to pipeline together thefeature_enginetransformations.
Default Configuration¶
FeatureTransformerFeatureTransformer contains no default configuration.
Attributes¶
transformer: An instance ofsklearn.pipeline.Pipeline, which is used to run all the transformers provided in the configuration.
Methods¶
fit¶
This method fits the feature transformer to the input data.
def fit(self, data, *args, **kwargs)
Arguments:
data(array-like): The input data to fit the transformer to.**kwargs(optional): Keyword arguments to be passed to thefitmethod.
Returns:
self.transformer: The fittedPipelineobject.
transform¶
This method applies the fitted feature transformer to transform the input data.
def transform(self, data, *args, **kwargs)
Arguments:
data(array-like): The input data to be transformed.**kwargs(optional): Keyword arguments to be passed to thetransformmethod.
Returns:
- A dataframe containing the transformed data.
fit_transform¶
This method fits the feature transformer to the data and transforms it.
def fit_transform(self, data, *args, **kwargs)
Arguments:
data(array-like): The input data to fit the transformer to and transform.**kwargs(optional): Keyword arguments to be passed to thefit_transformmethod.
Returns:
- A dataframe containing the transformed data.
_get_transformer¶
This method gets the feature_engine transformer object based on the given class name.
def _get_transformer(self, transformer_class, columns, *args, **kwargs)
Arguments:
transformer_class: The class name of the transformer.columns: The columns to apply the transformer to**kwargs(optional): Keyword arguments to be passed to the transformer constructor.
Returns:
object: The instantiatedfeature_enginetransformer object.
_map_transformer¶
This method maps the feature_engine class name to the feature_engine object.
def _map_transformer(self, transformer_class)
Arguments:
transformer_class: The class name of the transformer.
Returns:
object: Thefeature_engineclass.
Usage:¶
from lolpop.component import FeatureTransformerFeatureTransformer
data = #generate data
conf = {
#insert component configuration here ...
"config" : {
"transformers" : [
{"transformer": "OneHotEncoder", "transformer_columns": ["Sex"]},
{"transformer": "LogCpTransformer", "transformer_columns": ["Height", "Weight", "Diameter"]},
]
}
}
transformer = FeatureTransformerFeatureTransformer(conf=conf)
transformed_data = transformer.fit_transform(data)
print(transformed_data)
Sample Configuration¶
conf = {
"config": {
"transformers":
[
{"transformer": "OneHotEncoder", "transformer_columns": ["Sex"]},
{"transformer": "LogCpTransformer", "transformer_columns": ["Height", "Weight", "Diameter"]},
]
}
}