Registry / ai-ml / feature-engine

feature-engine

JSON →
library1.9.4pypypi✓ verified 86d ago

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-engine
INSTALL
IMPORT
SIG · FEATURE-ENGINE
F
feature-engine
ai-mlpythonv1.9.4
Install
16.1s avg
Import
4017ms
Disk
411MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.9.4 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
build_error
glibc
py 3.103.920 runs
installs and imports cleanly · install 16.1s · import 4.017s · 395MB
411MB installed
● package 411MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

MeanMedianImputer
from feature_engine.imputation import MeanMedianImputer
from feature_engine.imputers import MeanMedianImputer
Module paths were renamed in v1.0.0. The correct path is now `feature_engine.imputation`.
OneHotEncoder
from feature_engine.encoding import OneHotEncoder
from feature_engine.categorical_encoders import OneHotEncoder
Module paths were renamed in v1.0.0. The correct path is now `feature_engine.encoding`.
DropCorrelatedFeatures
from feature_engine.selection import DropCorrelatedFeatures
from feature_engine.variable_selection import DropCorrelatedFeatures
Module paths were renamed in v1.0.0. The correct path is now `feature_engine.selection`.

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.

import pandas as pd from sklearn.datasets import fetch_openml from sklearn.model_selection import train_test_split from feature_engine.imputation import MeanMedianImputer # Load dataset X, y = fetch_openml(name="house_prices", version=1, as_frame=True, return_X_y=True) # Separate into train and test sets X_train, X_test, y_train, y_test = train_test_split( X, y, test_size=0.3, random_state=0 ) # Initialize a MeanMedianImputer for specified numerical variables # It will impute 'median' for LotFrontage and MasVnrArea median_imputer = MeanMedianImputer( imputation_method='median', variables=['LotFrontage', 'MasVnrArea'] ) # Fit the imputer on the training data median_imputer.fit(X_train) # Transform both training and test data X_train_imputed = median_imputer.transform(X_train) X_test_imputed = median_imputer.transform(X_test) print("Missing values in 'LotFrontage' before imputation (train):", X_train['LotFrontage'].isnull().sum()) print("Missing values in 'LotFrontage' after imputation (train):", X_train_imputed['LotFrontage'].isnull().sum()) print("Missing values in 'MasVnrArea' before imputation (test):", X_test['MasVnrArea'].isnull().sum()) print("Missing values in 'MasVnrArea' after imputation (test):", X_test_imputed['MasVnrArea'].isnull().sum())
Debug
Known issues
breakingModule paths and some class names were renamed in v1.0.0 to better reflect their functionality and align with Scikit-learn conventions. For example, `feature_engine.imputers` became `feature_engine.imputation`.
fix
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`.
affects: >=1.0.0
gotchaFeature-engine's categorical encoders (e.g., `MeanEncoder`, `OneHotEncoder`) by default expect variables to be of pandas `object` or `category` dtype. Providing numerical variables without explicit handling will raise a `TypeError`.
fix
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')`.
affects: All versions
gotchaWhen dealing with categorical features, it's common for the test set to contain categories not present in the training set ('unseen categories'). This can lead to errors during transformation, especially with certain encoding schemes.
fix
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`.
affects: All versions
breakingIn v1.1.0, most transformers gained a new attribute `variables_` which contains the names of the variables that were actually modified by the transformer. While the old `variables` attribute is generally retained, `variables_` should be preferred for consistency and accuracy.
fix
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.
affects: >=1.1.0
Errors
Common errors & fixes
TypeError: Some of the variables are not categorical. Please cast them as object or category before calling this transformer
A categorical encoding transformer was applied to variables that are not of pandas 'object' or 'category' dtype, but rather numerical.
fix
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')`).
KeyError: "['some_category'] not in index"
This often occurs when trying to directly access or manipulate categories that are present in the test set but were not seen in the training set by a fitted encoder or discretizer.
fix
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')`).
Upgrade
Version history
1.9.4latest on PyPI · released Feb 27, 2026
Audit
Dependencies
pandasrequiredCore data structure for transformers (DataFrame in, DataFrame out).
scikit-learnrequiredProvides the API compatibility (fit/transform) and pipeline integration.
numpyrequiredUnderlying numerical operations.
scipyrequiredStatistical operations for some transformers.
statsmodelsoptionalStatistical models for certain transformations/selections.
matplotliboptionalUsed in examples and for plotting distributions.
seabornoptionalUsed in examples and for plotting distributions.
Agent activity
17 hits · last 30 days
node
16
OpenAI (training)
1
Resources