Install & Compatibility
Where this runs
tested against v0.23.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
muslpy 3.10–3.95 runs
build_error
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 18.0s · import 4.554s · 428MB
445MB installed
● package 445MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
StackingClassifier
✓ from mlxtend.classifier import StackingClassifier
SequentialFeatureSelector
✓ from mlxtend.feature_selection import SequentialFeatureSelector
plot_decision_regions
✓ from mlxtend.plotting import plot_decision_regions
TransactionEncoder
✓ from mlxtend.preprocessing import TransactionEncoder
apriori
✓ from mlxtend.frequent_patterns import apriori
association_rules
✓ from mlxtend.frequent_patterns import association_rules
This quickstart demonstrates how to use the `StackingClassifier` to combine multiple base models (Decision Tree, Logistic Regression) with a meta-classifier (Logistic Regression) to improve prediction accuracy. It uses a synthetic dataset from scikit-learn for illustration.
import numpy as np
from sklearn.linear_model import LogisticRegression
from sklearn.tree import DecisionTreeClassifier
from sklearn.model_selection import train_test_split
from sklearn.datasets import make_classification
from mlxtend.classifier import StackingClassifier
# Generate a synthetic dataset
X, y = make_classification(n_samples=1000, n_features=20, n_informative=10, n_redundant=10, random_state=42)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)
# Initialize base classifiers
clf1 = DecisionTreeClassifier(random_state=42)
clf2 = LogisticRegression(random_state=42, solver='liblinear')
# Initialize meta-classifier
lr = LogisticRegression(random_state=42, solver='liblinear')
# Initialize StackingClassifier
sclf = StackingClassifier(classifiers=[clf1, clf2], meta_classifier=lr, use_probas=True, verbose=0)
# Train and evaluate
sclf.fit(X_train, y_train)
score = sclf.score(X_test, y_test)
print(f"Stacking Classifier Test Accuracy: {score:.4f}")
Debug
Known issues
breakingmlxtend frequently updates to maintain compatibility with newer versions of `scikit-learn` and `pandas`. Older mlxtend versions may not work correctly with the latest releases of these core dependencies, leading to API errors or unexpected behavior. For example, `scikit-learn`'s `set_output` method integration and changes to `LinearRegression`'s `normalize` parameter required updates.fixAlways check mlxtend's release notes for compatibility updates before upgrading `scikit-learn` or `pandas`. Upgrade `mlxtend` to the latest version to ensure full compatibility, or pin dependency versions carefully.
affects: <0.24.0
breakingNumPy's deprecated type aliases like `np.float_`, `np.int_`, `np.bool_` were removed in recent NumPy versions. mlxtend versions prior to v0.23.4 might use these aliases, causing `AttributeError` in newer NumPy environments.fixUpgrade mlxtend to version 0.23.4 or newer to ensure compatibility with recent NumPy versions that have removed these aliases.
affects: <0.23.4
breakingPython 3.12+ removed the `distutils` package. Older mlxtend versions depending on `distutils` might fail to install or run on Python 3.12 and above.fixUpgrade mlxtend to version 0.23.1 or newer. This version specifically addresses the `distutils` dependency issue for Python 3.12+.
affects: <0.23.1
breakingThe `meta_features` handling in `StackingCVClassification` and `StackingCVRegression` was modified to ensure compatibility with `scikit-learn` versions 1.4 and above.fixIf using `StackingCVClassification` or `StackingCVRegression` with `scikit-learn >= 1.4`, ensure mlxtend is at least v0.24.0 to correctly pass `meta_features`.
affects: <0.24.0
gotchaThe behavior and internal workings of `association_rules` underwent fixes and improvements in recent versions. Code relying on specific older behaviors or encountering issues with rule generation should be re-evaluated.fixUpgrade to mlxtend v0.23.4 or newer if you are using `mlxtend.frequent_patterns.association_rules`. Test your code to ensure the updated logic aligns with expected results.
affects: All versions <0.23.4
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'mlxtend'
The `mlxtend` library is not installed in the Python environment you are currently using, or there's a typo in the import statement, or it's installed in a different environment.
fixInstall `mlxtend` using pip or conda, and ensure you are in the correct environment:
`pip install mlxtend`
or
`conda install -c conda-forge mlxtend`
If using Jupyter Notebook, you might need to use `!pip install mlxtend` and restart the kernel.
ImportError: cannot import name 'OnehotTransactions' from 'mlxtend.preprocessing'
The `OnehotTransactions` class was deprecated and removed in recent versions of `mlxtend`, replaced by `TransactionEncoder`.
fixUse `TransactionEncoder` instead of `OnehotTransactions`:
`from mlxtend.preprocessing import TransactionEncoder`
TypeError: association_rules() missing 1 required positional argument: 'num_itemsets'
In `mlxtend` versions 0.23.2 and above, the `association_rules` function from `mlxtend.frequent_patterns` made `num_itemsets` a mandatory parameter, which represents the total number of transactions in the original input data.
fixProvide the `num_itemsets` argument, typically the number of rows (transactions) from your original dataset, to the `association_rules` function:
`rules = association_rules(frequent_itemsets, metric="lift", min_threshold=1.0, num_itemsets=len(transactions_dataframe))`
AttributeError: 'numpy.ndarray' object has no attribute 'columns'
This error often occurs when `mlxtend` functions, particularly `SequentialFeatureSelector` or other components expecting pandas DataFrames (with `.columns` attribute), receive a NumPy array instead. This can happen after preprocessing steps like `ColumnTransformer` which typically output NumPy arrays.
fixEnsure the input data to the `mlxtend` function is a pandas DataFrame, or if a NumPy array is necessary, retrieve feature names separately or adjust the `mlxtend` function call if it supports numeric indexing for features.
`X_processed = pd.DataFrame(X_numpy_array, columns=original_feature_names)`
or handle feature names using indices if the `mlxtend` estimator supports it.
Upgrade
Version history
0.25.0latest on PyPI · released Jun 6, 2026
Audit
Dependencies
numpyrequiredCore numerical operations, array handling.
scipyrequiredScientific computing, statistical functions.
scikit-learnrequiredMachine learning algorithms, core API compatibility.
pandasrequiredData manipulation, DataFrame handling.
matplotlibrequiredPlotting and visualization utilities.
joblibrequiredParallel computing for feature selectors.