{"id":4824,"date":"2026-10-14T11:40:01","date_gmt":"2026-10-14T11:40:01","guid":{"rendered":"https:\/\/prwatech.in\/blog\/?p=4824"},"modified":"2026-10-15T15:46:56","modified_gmt":"2026-10-15T15:46:56","slug":"ensemble-methods-tutorial","status":"publish","type":"post","link":"https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/ensemble-methods-tutorial\/","title":{"rendered":"Ensemble Methods"},"content":{"rendered":"<h1><strong><b>Ensemble Methods in Machine Learning<\/b><\/strong><\/h1>\r\n<p>Before you buy something expensive, you probably ask more than one person. A friend may know the product, a colleague may have used it, and a review site may have tested it. No single opinion is perfect, but together they usually point you in a better direction than any one of them alone. Ensemble methods apply exactly this habit to machine learning.<\/p>\r\n<p>An ensemble combines the predictions of several models into a single answer. The reasoning is that different models make different mistakes. If they are combined well, the mistakes partly cancel and the group is more accurate and more stable than any individual member. The best known algorithms in applied machine learning, random forests and gradient boosted trees, are both ensembles.<\/p>\r\n<p>This tutorial explains every major ensemble technique in plain language. We cover the simple methods first, which are max voting, averaging and weighted averaging, with a worked example you can check by hand. Then the advanced methods: stacking, blending, bagging and boosting. After that comes a complete Python program that compares voting and stacking against the individual models on the same data, followed by advice on choosing a method, common mistakes and a short FAQ.<\/p>\r\n<h2><strong><b>What are Ensemble Methods?<\/b><\/strong><\/h2>\r\n<p>An ensemble method builds several models, called base models or base learners, and combines their outputs. The combination can be a vote, an average, or even another model that learns how to blend them. Ensemble methods fall into two broad families:<\/p>\r\n<ul>\r\n<li><b><\/b><strong><b>Averaging methods<\/b><\/strong>build models independently and combine them. Voting, averaging, bagging and stacking belong here. Their main benefit is lower variance.<\/li>\r\n<li><b><\/b><strong><b>Boosting methods<\/b><\/strong>build models one after another, each correcting the one before. Their main benefit is lower bias.<\/li>\r\n<\/ul>\r\n<p>Ensemble methods are often split into simple and advanced types, which is how we will cover them.<\/p>\r\n<p>&nbsp;<\/p>\r\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-4825\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2020\/02\/ensemright.png\" alt=\"Ensemble Methods Tutorial\" width=\"850\" height=\"601\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2020\/02\/ensemright.png 474w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2020\/02\/ensemright-300x212.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\r\n<h2><strong><b>Types of Ensemble Methods<\/b><\/strong><\/h2>\r\n<h3><strong><b>1. Simple Ensemble Methods<\/b><\/strong><\/h3>\r\n<h4><strong><b>Max Voting<\/b><\/strong><\/h4>\r\n<p>Each model votes for a class, and the class with the most votes wins. It is used mainly for classification. If three models predict spam, not spam and spam, the ensemble answers spam. This is also called hard voting. If votes are tied, the result depends on the library, so it is best to use an odd number of models.<\/p>\r\n<h4><strong><b>Averaging<\/b><\/strong><\/h4>\r\n<p>Each model produces a number, and the ensemble takes the average. For regression, the numbers are predictions. For classification, they can be predicted probabilities, which is called soft voting. Averaging smooths out the quirks of individual models.<\/p>\r\n<h4><strong><b>Weighted Average<\/b><\/strong><\/h4>\r\n<p>Some models deserve more trust than others. A weighted average gives stronger models a larger say. The following example uses predicted probabilities for three classes from three models.<\/p>\r\n<div style=\"border: 1px solid #d9e0ea; border-radius: 8px; overflow-x: auto; margin: 20px 0; -webkit-overflow-scrolling: touch;\">\r\n<table style=\"width: 100%; min-width: 560px; border-collapse: collapse; font-family: Arial,Helvetica,sans-serif; font-size: 16px; line-height: 1.6; color: #1f2937;\"><caption style=\"caption-side: top; text-align: left; padding: 14px 16px; font-weight: bold; font-size: 17px; color: #0f2a4a;\">Soft voting example with three models<\/caption>\r\n<thead>\r\n<tr>\r\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38; width: 220px;\" scope=\"col\">Model<\/th>\r\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38;\" scope=\"col\">Class 1<\/th>\r\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38;\" scope=\"col\">Class 2<\/th>\r\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38;\" scope=\"col\">Class 3<\/th>\r\n<\/tr>\r\n<\/thead>\r\n<tbody>\r\n<tr style=\"background: #ffffff;\">\r\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; white-space: nowrap;\" scope=\"row\">Model 1<\/th>\r\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">0.2<\/td>\r\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">0.5<\/td>\r\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">0.3<\/td>\r\n<\/tr>\r\n<tr style=\"background: #f5f8fc;\">\r\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; white-space: nowrap;\" scope=\"row\">Model 2<\/th>\r\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">0.6<\/td>\r\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">0.3<\/td>\r\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">0.1<\/td>\r\n<\/tr>\r\n<tr style=\"background: #ffffff;\">\r\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; white-space: nowrap;\" scope=\"row\">Model 3<\/th>\r\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">0.3<\/td>\r\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">0.4<\/td>\r\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">0.3<\/td>\r\n<\/tr>\r\n<tr style=\"background: #f5f8fc;\">\r\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; white-space: nowrap;\" scope=\"row\">Equal weights average<\/th>\r\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">0.37<\/td>\r\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">0.40<\/td>\r\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">0.23<\/td>\r\n<\/tr>\r\n<tr style=\"background: #ffffff;\">\r\n<th style=\"text-align: left; padding: 12px 16px; color: #0f2a4a; white-space: nowrap;\" scope=\"row\">Weights 2, 5 and 1<\/th>\r\n<td style=\"padding: 12px 16px;\">0.46<\/td>\r\n<td style=\"padding: 12px 16px;\">0.36<\/td>\r\n<td style=\"padding: 12px 16px;\">0.18<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<\/div>\r\n<p>&nbsp;<\/p>\r\n<p>With equal weights, class 2 wins with 0.40. But if Model 2 is the most trustworthy and gets a weight of 5, with weights of 2 and 1 for the others, class 1 wins with about 0.46. The data did not change, only the trust. That is why choosing weights matters, and why they should be chosen on validation data, not by hunch.<\/p>\r\n<h3><strong><b>2. Advanced Ensemble Methods<\/b><\/strong><\/h3>\r\n<h4><strong><b>Stacking<\/b><\/strong><\/h4>\r\n<p>Stacking lets a model learn how to combine the others. The base models make predictions, and those predictions become the input features of a final model, sometimes called the meta model. The final model learns, for example, that Model 1 is reliable for some kinds of cases and Model 2 for others.<\/p>\r\n<p>There is one trap. If the base models predict on the same rows they were trained on, their predictions look too good, and the final model learns to trust them too much. To avoid this, stacking uses predictions made on data the base models did not train on, produced by cross validation. Scikit learn does this for you inside StackingClassifier.<\/p>\r\n<h4><strong><b>Blending<\/b><\/strong><\/h4>\r\n<p>Blending is a simpler cousin of stacking. Instead of cross validation, you set aside a validation set, usually 10 to 20 percent of the training data. The base models are trained on the rest, they predict on the validation set, and the final model is trained on those predictions.<\/p>\r\n<div style=\"border: 1px solid #d9e0ea; border-radius: 8px; overflow-x: auto; margin: 20px 0; -webkit-overflow-scrolling: touch;\">\r\n<table style=\"width: 100%; min-width: 700px; border-collapse: collapse; font-family: Arial,Helvetica,sans-serif; font-size: 16px; line-height: 1.6; color: #1f2937;\"><caption style=\"caption-side: top; text-align: left; padding: 14px 16px; font-weight: bold; font-size: 17px; color: #0f2a4a;\">Stacking vs blending<\/caption>\r\n<thead>\r\n<tr>\r\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38; width: 200px;\" scope=\"col\">Point<\/th>\r\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38;\" scope=\"col\">Stacking<\/th>\r\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38;\" scope=\"col\">Blending<\/th>\r\n<\/tr>\r\n<\/thead>\r\n<tbody>\r\n<tr style=\"background: #ffffff;\">\r\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; white-space: nowrap;\" scope=\"row\">Final model trained on<\/th>\r\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Cross validated predictions for every training row<\/td>\r\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Predictions on one held out validation set<\/td>\r\n<\/tr>\r\n<tr style=\"background: #f5f8fc;\">\r\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; white-space: nowrap;\" scope=\"row\">Data used<\/th>\r\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">All the training data<\/td>\r\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Less, because some is held out<\/td>\r\n<\/tr>\r\n<tr style=\"background: #ffffff;\">\r\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; white-space: nowrap;\" scope=\"row\">Complexity<\/th>\r\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">More, and slower<\/td>\r\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Simpler and faster<\/td>\r\n<\/tr>\r\n<tr style=\"background: #f5f8fc;\">\r\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; white-space: nowrap;\" scope=\"row\">Leakage risk<\/th>\r\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Handled by cross validation<\/td>\r\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Low, if the split is kept separate<\/td>\r\n<\/tr>\r\n<tr style=\"background: #ffffff;\">\r\n<th style=\"text-align: left; padding: 12px 16px; color: #0f2a4a; white-space: nowrap;\" scope=\"row\">In scikit learn<\/th>\r\n<td style=\"padding: 12px 16px;\">StackingClassifier and StackingRegressor<\/td>\r\n<td style=\"padding: 12px 16px;\">No ready made class, write it by hand<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<\/div>\r\n<p>&nbsp;<\/p>\r\n<h4><strong><b>Bagging<\/b><\/strong><\/h4>\r\n<p>Bagging, short for bootstrap aggregating, trains many models in parallel, each on a random sample of the data drawn with replacement, and averages them. It reduces variance and works best with strong, unstable models such as deep decision trees. Random forest is bagging plus a random choice of features at each split. Our full guide to bagging covers it in detail.<\/p>\r\n<h4><strong><b>Boosting<\/b><\/strong><\/h4>\r\n<p>Boosting trains simple models in sequence. Each new model concentrates on the mistakes of the ones before it, and the final prediction combines them all. It reduces bias and often gives the highest accuracy on tables of data. AdaBoost, gradient boosting, XGBoost, LightGBM and CatBoost are all boosting methods. Our full guide to boosting covers them.<\/p>\r\n<p>&nbsp;<\/p>\r\n<p>&nbsp;<\/p>\r\n<p><iframe loading=\"lazy\" src=\"https:\/\/www.youtube.com\/embed\/EGbyBqFlTcQ\" width=\"850\" height=\"315\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\r\n<p>&nbsp;<\/p>\r\n<h2><strong><b>Bagging Versus Boosting<\/b><\/strong><\/h2>\r\n<div style=\"border: 1px solid #d9e0ea; border-radius: 8px; overflow-x: auto; margin: 20px 0; -webkit-overflow-scrolling: touch;\">\r\n<table style=\"width: 100%; min-width: 640px; border-collapse: collapse; font-family: Arial,Helvetica,sans-serif; font-size: 16px; line-height: 1.6; color: #1f2937;\"><caption style=\"caption-side: top; text-align: left; padding: 14px 16px; font-weight: bold; font-size: 17px; color: #0f2a4a;\">Bagging vs boosting<\/caption>\r\n<thead>\r\n<tr>\r\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38; width: 190px;\" scope=\"col\">Point<\/th>\r\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38;\" scope=\"col\">Bagging<\/th>\r\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38;\" scope=\"col\">Boosting<\/th>\r\n<\/tr>\r\n<\/thead>\r\n<tbody>\r\n<tr style=\"background: #ffffff;\">\r\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; white-space: nowrap;\" scope=\"row\">Main goal<\/th>\r\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Reduce variance<\/td>\r\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Reduce bias<\/td>\r\n<\/tr>\r\n<tr style=\"background: #f5f8fc;\">\r\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; white-space: nowrap;\" scope=\"row\">Build order<\/th>\r\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Independent, in parallel<\/td>\r\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">In sequence<\/td>\r\n<\/tr>\r\n<tr style=\"background: #ffffff;\">\r\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; white-space: nowrap;\" scope=\"row\">Best base models<\/th>\r\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Strong and complex<\/td>\r\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Weak and simple<\/td>\r\n<\/tr>\r\n<tr style=\"background: #f5f8fc;\">\r\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; white-space: nowrap;\" scope=\"row\">Overfitting risk<\/th>\r\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Low<\/td>\r\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Higher if run too long<\/td>\r\n<\/tr>\r\n<tr style=\"background: #ffffff;\">\r\n<th style=\"text-align: left; padding: 12px 16px; color: #0f2a4a; white-space: nowrap;\" scope=\"row\">Typical choice when<\/th>\r\n<td style=\"padding: 12px 16px;\">Your model is accurate but unstable<\/td>\r\n<td style=\"padding: 12px 16px;\">Your model is too simple and underfits<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<\/div>\r\n<p>&nbsp;<\/p>\r\n<h2><strong><b>Ensemble Methods in Python<\/b><\/strong><\/h2>\r\n<p>Here is a complete program that compares three individual models against hard voting, soft voting and stacking. All use the same training and test split of the breast cancer dataset that comes with scikit learn.<\/p>\r\n<p>from sklearn.datasets import load_breast_cancer<\/p>\r\n<p>from sklearn.model_selection import train_test_split<\/p>\r\n<p>from sklearn.pipeline import make_pipeline<\/p>\r\n<p>from sklearn.preprocessing import StandardScaler<\/p>\r\n<p>from sklearn.linear_model import LogisticRegression<\/p>\r\n<p>from sklearn.ensemble import RandomForestClassifier, VotingClassifier, StackingClassifier<\/p>\r\n<p>from sklearn.naive_bayes import GaussianNB<\/p>\r\n<p>&nbsp;<\/p>\r\n<p>X, y = load_breast_cancer(return_X_y=True)<\/p>\r\n<p>X_train, X_test, y_train, y_test = train_test_split(<\/p>\r\n<p>\u00a0\u00a0\u00a0\u00a0X, y, test_size=0.3, random_state=0, stratify=y<\/p>\r\n<p>)<\/p>\r\n<p>&nbsp;<\/p>\r\n<p>lr = make_pipeline(StandardScaler(), LogisticRegression(max_iter=1000))<\/p>\r\n<p>rf = RandomForestClassifier(n_estimators=100, random_state=0)<\/p>\r\n<p>nb = GaussianNB()<\/p>\r\n<p>base = [(&#8220;lr&#8221;, lr), (&#8220;rf&#8221;, rf), (&#8220;nb&#8221;, nb)]<\/p>\r\n<p>&nbsp;<\/p>\r\n<p>models = {<\/p>\r\n<p>\u00a0\u00a0\u00a0\u00a0&#8220;Logistic regression&#8221;: lr,<\/p>\r\n<p>\u00a0\u00a0\u00a0\u00a0&#8220;Random forest&#8221;: rf,<\/p>\r\n<p>\u00a0\u00a0\u00a0\u00a0&#8220;Naive Bayes&#8221;: nb,<\/p>\r\n<p>\u00a0\u00a0\u00a0\u00a0&#8220;Hard voting&#8221;: VotingClassifier(base, voting=&#8221;hard&#8221;),<\/p>\r\n<p>\u00a0\u00a0\u00a0\u00a0&#8220;Soft voting&#8221;: VotingClassifier(base, voting=&#8221;soft&#8221;),<\/p>\r\n<p>\u00a0\u00a0\u00a0\u00a0&#8220;Stacking&#8221;: StackingClassifier(base, final_estimator=LogisticRegression(max_iter=1000), cv=5),<\/p>\r\n<p>}<\/p>\r\n<p>&nbsp;<\/p>\r\n<p>for name, model in models.items():<\/p>\r\n<p>\u00a0\u00a0\u00a0\u00a0model.fit(X_train, y_train)<\/p>\r\n<p>\u00a0\u00a0\u00a0\u00a0print(f&#8221;{name}: {model.score(X_test, y_test):.3f}&#8221;)<\/p>\r\n<p>When I ran it, the output was:<\/p>\r\n<p>Logistic regression: 0.959<\/p>\r\n<p>Random forest: 0.953<\/p>\r\n<p>Naive Bayes: 0.924<\/p>\r\n<p>Hard voting: 0.959<\/p>\r\n<p>Soft voting: 0.942<\/p>\r\n<p>Stacking: 0.971<\/p>\r\n<h3><strong><b>Reading the Results<\/b><\/strong><\/h3>\r\n<ul>\r\n<li><b><\/b><strong><b>Stacking did best. <\/b><\/strong>It scored 0.971, against 0.959 for the best single model.<\/li>\r\n<li><b><\/b><strong><b>Voting did not always help. <\/b><\/strong>Hard voting only matched the best single model, and soft voting scored lower than logistic regression. The weakest member, Naive Bayes, may have dragged it down.<\/li>\r\n<li><b><\/b><strong><b>The differences are small. <\/b><\/strong>The test set has 171 patients, and each patient is worth about 0.6 points. Stacking&#8217;s lead is two patients. Treat these results as a demonstration, and use cross validation on your own data before drawing conclusions.<\/li>\r\n<\/ul>\r\n<p>The lesson matters more than the numbers. An ensemble is not guaranteed to beat its best member. It helps most when the members are individually good and make different kinds of mistakes.<\/p>\r\n<h2><strong><b>How to Choose an Ensemble Method?<\/b><\/strong><\/h2>\r\n<div style=\"border: 1px solid #d9e0ea; border-radius: 8px; overflow-x: auto; margin: 20px 0; -webkit-overflow-scrolling: touch;\">\r\n<table style=\"width: 100%; min-width: 640px; border-collapse: collapse; font-family: Arial,Helvetica,sans-serif; font-size: 16px; line-height: 1.6; color: #1f2937;\"><caption style=\"caption-side: top; text-align: left; padding: 14px 16px; font-weight: bold; font-size: 17px; color: #0f2a4a;\">Which ensemble method to try first<\/caption>\r\n<thead>\r\n<tr>\r\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38; width: 340px;\" scope=\"col\">Your situation<\/th>\r\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38;\" scope=\"col\">Try first<\/th>\r\n<\/tr>\r\n<\/thead>\r\n<tbody>\r\n<tr style=\"background: #ffffff;\">\r\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a;\" scope=\"row\">A deep tree is accurate but unstable<\/th>\r\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Bagging or random forest<\/td>\r\n<\/tr>\r\n<tr style=\"background: #f5f8fc;\">\r\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a;\" scope=\"row\">Your model underfits and is too simple<\/th>\r\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Boosting<\/td>\r\n<\/tr>\r\n<tr style=\"background: #ffffff;\">\r\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a;\" scope=\"row\">You have a few good, different models already<\/th>\r\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Voting or stacking<\/td>\r\n<\/tr>\r\n<tr style=\"background: #f5f8fc;\">\r\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a;\" scope=\"row\">You have a small dataset and little time<\/th>\r\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Random forest<\/td>\r\n<\/tr>\r\n<tr style=\"background: #ffffff;\">\r\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a;\" scope=\"row\">You want the highest accuracy on tabular data<\/th>\r\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Gradient boosting, then consider stacking<\/td>\r\n<\/tr>\r\n<tr style=\"background: #f5f8fc;\">\r\n<th style=\"text-align: left; padding: 12px 16px; color: #0f2a4a;\" scope=\"row\">You want to keep it simple and explainable<\/th>\r\n<td style=\"padding: 12px 16px;\">A single model, or a small voting ensemble<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<\/div>\r\n<p>&nbsp;<\/p>\r\n<h2><strong><b>Strengths and Limitations of Ensembles<\/b><\/strong><\/h2>\r\n<h3><strong><b>Strengths<\/b><\/strong><\/h3>\r\n<ul>\r\n<li>Usually more accurate and more stable than one model.<\/li>\r\n<li>Reduce the chance of one bad model ruining results.<\/li>\r\n<li>Work with almost any type of base model.<\/li>\r\n<\/ul>\r\n<h3><strong><b>Limitations<\/b><\/strong><\/h3>\r\n<ul>\r\n<li>Slower to train and to predict.<\/li>\r\n<li>Harder to explain than a single model.<\/li>\r\n<li>More code and more settings to maintain.<\/li>\r\n<li>Gains can be small if the models make the same mistakes.<\/li>\r\n<\/ul>\r\n<h2><strong><b>Common Mistakes to Avoid<\/b><\/strong><\/h2>\r\n<ul>\r\n<li><b><\/b><strong><b>Combining models that are too similar. <\/b><\/strong>If they all make the same errors, nothing cancels.<\/li>\r\n<li><b><\/b><strong><b>Training stacking models on their own training predictions. <\/b><\/strong>Use cross validation, which StackingClassifier does for you.<\/li>\r\n<li><b><\/b><strong><b>Choosing weights by hunch. <\/b><\/strong>Pick them on validation data.<\/li>\r\n<li><b><\/b><strong><b>Expecting an ensemble to win every time. <\/b><\/strong>It does not.<\/li>\r\n<li><b><\/b><strong><b>Evaluating on the training set. <\/b><\/strong>Always keep a held out test set.<\/li>\r\n<li><b><\/b><strong><b>Ignoring cost. <\/b><\/strong>An ensemble of fifty models may not be worth a half point of accuracy in production.<\/li>\r\n<\/ul>\r\n<p>Ensemble methods turn many imperfect models into one stronger one. Start by running the comparison program on your own data, check whether combining actually helps, and pick between bagging, boosting, voting and stacking based on what your single model gets wrong.<\/p>\r\n","protected":false},"excerpt":{"rendered":"<p>Ensemble Methods in Machine Learning Before you buy something expensive, you probably ask more than one person. A friend may know the product, a colleague may have used it, and a review site may have tested it. No single opinion is perfect, but together they usually point you in a better direction than any one [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32,1696],"tags":[440,439,437,438],"class_list":["post-4824","post","type-post","status-publish","format-standard","hentry","category-machine-learning","category-machine-learning-modules","tag-advanced-ensemble-techniques","tag-ensemble-methods-introduction","tag-ensemble-methods-tutorial","tag-types-of-ensemble-methods"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Ensemble Methods in Machine Learning With Python | Prwatech<\/title>\n<meta name=\"description\" content=\"Learn ensemble methods in machine learning: voting, averaging, stacking, blending, bagging and boosting, with a tested Python comparison and clear guidance.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/ensemble-methods-tutorial\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Ensemble Methods in Machine Learning With Python | Prwatech\" \/>\n<meta property=\"og:description\" content=\"Learn ensemble methods in machine learning: voting, averaging, stacking, blending, bagging and boosting, with a tested Python comparison and clear guidance.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/ensemble-methods-tutorial\/\" \/>\n<meta property=\"og:site_name\" content=\"Prwatech\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prwatech.in\/\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-14T11:40:01+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-10-15T15:46:56+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2020\/02\/ensemright.png\" \/>\n\t<meta property=\"og:image:width\" content=\"474\" \/>\n\t<meta property=\"og:image:height\" content=\"335\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Prwatech\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@Eduprwatech\" \/>\n<meta name=\"twitter:site\" content=\"@Eduprwatech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Prwatech\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/ensemble-methods-tutorial\/\",\"url\":\"https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/ensemble-methods-tutorial\/\",\"name\":\"Ensemble Methods in Machine Learning With Python | Prwatech\",\"isPartOf\":{\"@id\":\"https:\/\/prwatech.in\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/ensemble-methods-tutorial\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/ensemble-methods-tutorial\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2020\/02\/ensemright.png\",\"datePublished\":\"2026-10-14T11:40:01+00:00\",\"dateModified\":\"2026-10-15T15:46:56+00:00\",\"author\":{\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3\"},\"description\":\"Learn ensemble methods in machine learning: voting, averaging, stacking, blending, bagging and boosting, with a tested Python comparison and clear guidance.\",\"breadcrumb\":{\"@id\":\"https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/ensemble-methods-tutorial\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/ensemble-methods-tutorial\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/ensemble-methods-tutorial\/#primaryimage\",\"url\":\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2020\/02\/ensemright.png\",\"contentUrl\":\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2020\/02\/ensemright.png\",\"width\":474,\"height\":335},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/ensemble-methods-tutorial\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/prwatech.in\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Ensemble Methods\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/prwatech.in\/blog\/#website\",\"url\":\"https:\/\/prwatech.in\/blog\/\",\"name\":\"Prwatech\",\"description\":\"Share Ideas, Start Something Good.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/prwatech.in\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3\",\"name\":\"Prwatech\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g\",\"caption\":\"Prwatech\"},\"url\":\"https:\/\/prwatech.in\/blog\/author\/prwatech123\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Ensemble Methods in Machine Learning With Python | Prwatech","description":"Learn ensemble methods in machine learning: voting, averaging, stacking, blending, bagging and boosting, with a tested Python comparison and clear guidance.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/ensemble-methods-tutorial\/","og_locale":"en_US","og_type":"article","og_title":"Ensemble Methods in Machine Learning With Python | Prwatech","og_description":"Learn ensemble methods in machine learning: voting, averaging, stacking, blending, bagging and boosting, with a tested Python comparison and clear guidance.","og_url":"https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/ensemble-methods-tutorial\/","og_site_name":"Prwatech","article_publisher":"https:\/\/www.facebook.com\/prwatech.in\/","article_published_time":"2026-10-14T11:40:01+00:00","article_modified_time":"2026-10-15T15:46:56+00:00","og_image":[{"width":474,"height":335,"url":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2020\/02\/ensemright.png","type":"image\/png"}],"author":"Prwatech","twitter_card":"summary_large_image","twitter_creator":"@Eduprwatech","twitter_site":"@Eduprwatech","twitter_misc":{"Written by":"Prwatech","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/ensemble-methods-tutorial\/","url":"https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/ensemble-methods-tutorial\/","name":"Ensemble Methods in Machine Learning With Python | Prwatech","isPartOf":{"@id":"https:\/\/prwatech.in\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/ensemble-methods-tutorial\/#primaryimage"},"image":{"@id":"https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/ensemble-methods-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2020\/02\/ensemright.png","datePublished":"2026-10-14T11:40:01+00:00","dateModified":"2026-10-15T15:46:56+00:00","author":{"@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3"},"description":"Learn ensemble methods in machine learning: voting, averaging, stacking, blending, bagging and boosting, with a tested Python comparison and clear guidance.","breadcrumb":{"@id":"https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/ensemble-methods-tutorial\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/ensemble-methods-tutorial\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/ensemble-methods-tutorial\/#primaryimage","url":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2020\/02\/ensemright.png","contentUrl":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2020\/02\/ensemright.png","width":474,"height":335},{"@type":"BreadcrumbList","@id":"https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/ensemble-methods-tutorial\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/prwatech.in\/blog\/"},{"@type":"ListItem","position":2,"name":"Ensemble Methods"}]},{"@type":"WebSite","@id":"https:\/\/prwatech.in\/blog\/#website","url":"https:\/\/prwatech.in\/blog\/","name":"Prwatech","description":"Share Ideas, Start Something Good.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/prwatech.in\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3","name":"Prwatech","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g","caption":"Prwatech"},"url":"https:\/\/prwatech.in\/blog\/author\/prwatech123\/"}]}},"_links":{"self":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/4824","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/comments?post=4824"}],"version-history":[{"count":12,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/4824\/revisions"}],"predecessor-version":[{"id":12006,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/4824\/revisions\/12006"}],"wp:attachment":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/media?parent=4824"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/categories?post=4824"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/tags?post=4824"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}