To blend machine-learning models in Python, train several base estimators, collect predictions they make on examples they did not train on, and use those predictions as features for a second-level model. In scikit-learn, StackingClassifier and StackingRegressor implement this cross-validated approach. The crucial safeguard is to keep the meta-model’s training predictions separate from the data used to fit each base model.
What blending means—and how it relates to stacking
Blending combines predictions from multiple models with a second-level learner, often called a meta-model. The base models make predictions; the meta-model learns how to use them to predict the target. In common usage, “blending” often means training the meta-model on predictions from a reserved holdout subset, while “stacking” often means generating those predictions through cross-validation. The terms are not used consistently, so this article uses stacking for the cross-validated workflow implemented by scikit-learn.
The aim is to let the meta-model exploit differences among base learners—for example, one model may be useful on cases where another tends to be wrong. An ensemble is not automatically better: evaluate it against each base model using the same untouched test data and metric.
Choose the right prediction-generation method
Cross-validated predictions
In cross-validated stacking, each training example receives a prediction from a base estimator that was fitted without that example. Those predictions become meta-features for training the final estimator. The scikit-learn guide describes this process and provides StackingClassifier and StackingRegressor.
#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
This is usually the straightforward choice when using scikit-learn’s stacking estimators. If you leave cv unset, the current API documentation specifies five folds. That is a default configuration, not a guarantee that five folds suit every dataset; select a validation strategy that reflects how the data were collected and how predictions will be used.
Holdout blending
A holdout design reserves a subset specifically for generating meta-model training features. Fit the base estimators on the other training data, predict the reserved examples, and train the meta-model on those predictions and the reserved labels. The reserved examples must not have been used to fit the base models producing their meta-features.
After fitting the meta-model, a deployment implementation must also specify how base estimators are trained for inference. A holdout design typically refits base learners using the available training data after creating the meta-training predictions, while retaining the fitted meta-model. Whichever design you choose, keep the final test set out of both base-model and meta-model fitting.
Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
Build a scikit-learn stacking model
The example below shows classification. It uses a stratified train/test split and puts preprocessing inside each model pipeline, so transformations that learn from data are fitted within the training process rather than before the split. Replace the sample estimators, preprocessing, and metric with choices appropriate to your task.
from sklearn.datasets import load_breast_cancer
from sklearn.ensemble import RandomForestClassifier, StackingClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score
from sklearn.model_selection import train_test_split
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.svm import SVC
X, y = load_breast_cancer(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.2, stratify=y, random_state=42
)
base_models = [
("logistic", make_pipeline(StandardScaler(), LogisticRegression(max_iter=2000))),
("svc", make_pipeline(StandardScaler(), SVC(probability=True))),
("forest", RandomForestClassifier(n_estimators=300, random_state=42)),
]
model = StackingClassifier(
estimators=base_models,
final_estimator=LogisticRegression(max_iter=2000),
cv=5,
stack_method="predict_proba",
)
model.fit(X_train, y_train)
predictions = model.predict(X_test)
print("Stacking accuracy:", accuracy_score(y_test, predictions))
This illustrative example does not establish that stacking improves accuracy on this dataset. To make a fair comparison, fit and assess each base model on the same training/test split and compare the same metric. Consider additional metrics—such as precision, recall, or a probability-sensitive metric—if accuracy does not reflect the costs of mistakes in your application.
Choose what classification predictions become meta-features
For classification, scikit-learn can build meta-features from predicted probabilities, decision scores, or class labels, depending on the estimator and stack_method. These contain different information: probabilities preserve confidence estimates, decision scores express distance or ranking according to the estimator, and class labels reduce each prediction to a category. Choose deliberately and confirm the chosen method is supported by every base estimator. The API also provides a passthrough option to send original input features to the final estimator in addition to base predictions; enable it only when that extra information fits your design.
Rank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
Use regression for continuous targets
For a continuous target, use StackingRegressor. Its base estimators’ predictions serve as the meta-features, and the final estimator learns to combine them. Choose a regression metric suited to the task, then compare the stacked model and each base model on the same held-out test observations.
Prevent leakage when training the meta-model
If a base model predicts examples it was trained on, those predictions can be unrealistically strong. Training a meta-model on them may teach it to rely on a pattern that will not hold for new data. The meta-model should therefore learn from predictions generated on observations excluded from the corresponding base model’s fit—through cross-validation or a properly reserved blending holdout.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Repair Windows errors before they cause bigger problems3Fix the driver behind crashes, sound loss and screen glitchesscikit-learn warns that cv="prefit" carries a very high overfitting risk when base estimators were trained on the same data used to fit the stacking model. In prefit mode, the stacking estimator does not refit those estimators. Use it only when the data used to fit the meta-model are genuinely separate from the data used to fit the base estimators.
Rank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
Keep all data-dependent preprocessing inside the base-estimator pipelines. Otherwise, a transformation could learn information from validation or test observations before model fitting, undermining the separation your evaluation depends on.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Match the split strategy to the data
For ordinary classification tasks, stratification helps preserve approximate target-class proportions across folds. scikit-learn’s cross-validation guide describes this purpose. The example uses stratification for the train/test split; the stacking estimator’s default cross-validation behavior should also be checked against the task’s structure.
Random or ordinary stratified folds are not automatically appropriate when observations are grouped, repeated for the same subject, or ordered in time. Choose a splitter that prevents information from crossing between training and validation in a way that would not be possible at deployment. For a time-based prediction task, for instance, training on future observations to predict earlier ones would make the evaluation misleading. The appropriate specialized splitter depends on the data and prediction setup.
Best Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
Decide whether the ensemble is worth using
Stacking can combine different strengths, but it may perform about as well as the strongest base predictor, and training it costs more. The scikit-learn guide makes both points in its discussion of stacking. Treat an improvement as something to measure, not assume.
- Performance: compare the ensemble with every base model on identical held-out data and task-appropriate metrics.
- Complementarity: stacking is more promising when base models contribute useful, different information rather than making essentially the same errors.
- Validation quality: use splits that reflect class balance, grouping, time order, and the intended deployment setting.
- Cost and complexity: account for the extra fitting work, inference work, and maintenance of multiple estimators.
- Operational fit: check that the ensemble supplies the outputs you need, such as probabilities, and that its complexity is acceptable for deployment and interpretation.
There is no universal percentage improvement to expect. Keep the simpler best-performing base model if the measured gain from stacking is not valuable enough to justify its additional cost and complexity.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

