Feature-engine is an open-source Python library offering a comprehensive suite of transformers for feature engineering and selection in machine learning. It provides functionality for missing data imputation, categorical encoding, discretisation, outlier handling, feature transformation, creation, and selection. Compatible with Scikit-learn's `fit()` and `transform()` API, Feature-engine currently stands at version 1.9.4 and undergoes routine development with new releases.
pip install feature-engineVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `feature-engine`'s `MeanMedianImputer` to handle missing data. It loads a dataset, splits it into training and testing sets, fits the imputer on the training data, and then transforms both sets. This follows the standard Scikit-learn `fit()` and `transform()` pattern, ensuring proper parameter learning from training data.
Update import statements to the new module paths. Refer to the official documentation or the v1.0.0 release notes for a complete list of changes. E.g., `from feature_engine.imputation import MeanMedianImputer`.
Ensure target variables are cast to `object` or `category` dtype before applying the encoder, or set the `ignore_format=True` parameter in the transformer if you intend to encode numerical variables (use with caution). Example: `df['numerical_col'] = df['numerical_col'].astype('object')`.Use `feature-engine`'s `MatchCategories` transformer (introduced in v1.5.0) as part of your pipeline to align categories between training and test sets. Alternatively, ensure your chosen encoder has a strategy for handling unseen categories (e.g., `handle_unknown='ignore'` or a custom mapping). For `OneHotEncoder` specifically, a bug fix in v1.1.2 addressed how it handles binary variables with `drop_last_binary=True`.
If your code inspects the list of variables transformed, switch to using `transformer.variables_` instead of `transformer.variables` for robust behavior, especially in complex pipelines where `variables` might refer to initial input and `variables_` to final processed ones.
Convert the target numerical column(s) to 'object' or 'category' dtype before fitting the encoder, or set `ignore_format=True` in the encoder's constructor if you deliberately want to encode numerical columns (e.g., `df['col'] = df['col'].astype('object')`).Use `feature_engine.preprocessing.MatchCategories()` at the preprocessing stage to ensure consistent categories across train and test sets. Alternatively, review your chosen encoder's parameters for handling unknown categories (e.g., `RareLabelEncoder(tol=...)`, `OneHotEncoder(handle_unknown='ignore')`).