{"id":4828,"date":"2026-10-14T11:44:47","date_gmt":"2026-10-14T11:44:47","guid":{"rendered":"https:\/\/prwatech.in\/blog\/?p=4828"},"modified":"2026-10-15T15:37:24","modified_gmt":"2026-10-15T15:37:24","slug":"bagging-technique-in-machine-learning","status":"publish","type":"post","link":"https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/bagging-technique-in-machine-learning\/","title":{"rendered":"Bagging Technique in Machine Learning"},"content":{"rendered":"<h1><strong><b>Bagging Technique in Machine Learning<\/b><\/strong><\/h1>\n<p>Ask a hundred people to guess how many sweets are in a jar, and the average of their guesses is often remarkably close to the truth. No single guess is reliable, some are far too high and some far too low, but the mistakes tend to cancel out. Bagging applies the same idea to machine learning. Instead of trusting one model, it trains many and combines their answers.<\/p>\n<p>The name is short for bootstrap aggregating. It is designed to cure one specific weakness: variance. Some models, especially decision trees, are very sensitive to the exact data they were trained on. Change a few rows and you get a quite different tree. Bagging smooths that out. It is the technique behind random forests, which are among the most widely used models for tables of data.<\/p>\n<p>This guide explains how bagging works, starting with bootstrap sampling and the reason averaging helps. Then we build a complete Python example that compares a single decision tree, a bagging model and a random forest on the same data, and use the out of bag score as a free validation check. After that come the main settings, the variants of bagging, how it differs from boosting, its strengths and limits, common mistakes and a short FAQ.<\/p>\n<h2><strong><b>What is Bagging?<\/b><\/strong><\/h2>\n<p>Bagging is an <strong><b>ensemble<\/b><\/strong>\u00a0method, meaning it combines several models into one. Its recipe has three parts:<\/p>\n<ol>\n<li><b><\/b><b><\/b>Create many different training sets by drawing rows at random from the original data, with replacement.<\/li>\n<li><b><\/b><b><\/b>Fit one model, usually a decision tree, on each training set, all independently.<\/li>\n<li><b><\/b><b><\/b>Combine the predictions. For classification, the models vote or their probabilities are averaged. For regression, their predictions are averaged.<\/li>\n<\/ol>\n<p>Because the models are trained independently, they can be trained in parallel, which makes bagging easy to speed up.<\/p>\n<h2><strong><b>Bootstrap Sampling: The Heart of Bagging<\/b><\/strong><\/h2>\n<p>Drawing with replacement means a row can be picked more than once, and some rows are not picked at all. If your data has n rows and you draw n times, roughly 63 percent of the original rows end up in the sample, and about 37 percent are left out. Each model therefore sees a slightly different version of the data, which is exactly what makes the models differ from one another.<\/p>\n<p>The rows left out of a given model&#8217;s sample are called its <strong><b>out of bag<\/b><\/strong>\u00a0rows. They are useful, as you will see below, because they act as a free test set.<\/p>\n<h2><strong><b>Why does Averaging Reduce Variance?<\/b><\/strong><\/h2>\n<p>A deep decision tree fits its training data very closely, including its noise. That makes it low in bias but high in variance. Each tree errs in its own random direction. When you average many trees that err in different directions, the random errors largely cancel, while the real pattern, which all trees share, remains. The result is a model that is more stable and usually more accurate, without being any simpler.<\/p>\n<p>This works best with models that are strong but unstable, like full depth trees. It does little for models that are already stable, such as linear regression.<\/p>\n<h2><strong><b>Bagging Versus Boosting<\/b><\/strong><\/h2>\n<div style=\"border: 1px solid #d9e0ea; border-radius: 8px; overflow-x: auto; margin: 20px 0; -webkit-overflow-scrolling: touch;\">\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;\">\n<caption style=\"caption-side: top; text-align: left; padding: 14px 16px; font-weight: bold; font-size: 17px; color: #0f2a4a;\">Bagging vs boosting<\/caption>\n<thead>\n<tr>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38; width: 190px;\" scope=\"col\">Point<\/th>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38;\" scope=\"col\">Bagging<\/th>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38;\" scope=\"col\">Boosting<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; white-space: nowrap;\" scope=\"row\">Main goal<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Reduce variance<\/td>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Reduce bias<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; white-space: nowrap;\" scope=\"row\">Build order<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Models trained independently, in parallel<\/td>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Models trained one after another<\/td>\n<\/tr>\n<tr style=\"background: #ffffff;\">\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>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Strong and complex, such as deep trees<\/td>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Weak and simple, such as shallow trees<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; white-space: nowrap;\" scope=\"row\">Data for each model<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Random bootstrap samples<\/td>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Re weighted data or fitted to the errors<\/td>\n<\/tr>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; white-space: nowrap;\" scope=\"row\">Overfitting risk<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Low<\/td>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Higher if run too long<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; color: #0f2a4a; white-space: nowrap;\" scope=\"row\">Examples<\/th>\n<td style=\"padding: 12px 16px;\">Bagging classifier, random forest<\/td>\n<td style=\"padding: 12px 16px;\">AdaBoost, XGBoost, LightGBM<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>&nbsp;<\/p>\n<h2><strong><b>Bagging in Python Step by Step<\/b><\/strong><\/h2>\n<p>We will use the breast cancer dataset that ships with scikit learn, which has 569 patients and 30 measurements each, labelled malignant or benign. First, load the data and split it into training and test sets:<\/p>\n<p>from sklearn.datasets import load_breast_cancer<\/p>\n<p>from sklearn.model_selection import train_test_split<\/p>\n<p>&nbsp;<\/p>\n<p>X, y = load_breast_cancer(return_X_y=True)<\/p>\n<p>print(X.shape)<\/p>\n<p>&nbsp;<\/p>\n<p>X_train, X_test, y_train, y_test = train_test_split(<\/p>\n<p>X, y, test_size=0.3, random_state=0, stratify=y<\/p>\n<p>)<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-4829\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2020\/02\/bag1-1024x235.png\" alt=\"Bagging Technique in Machine Learning - bagging algorithm example\" width=\"850\" height=\"195\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2020\/02\/bag1-1024x235.png 1024w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2020\/02\/bag1-300x69.png 300w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2020\/02\/bag1-768x177.png 768w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2020\/02\/bag1.png 1153w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p>Now the main program. It trains three models on the same split: one decision tree, a bagging model of 100 trees with the out of bag score switched on, and a random forest of 100 trees.<\/p>\n<p>from sklearn.datasets import load_breast_cancer<\/p>\n<p>from sklearn.model_selection import train_test_split<\/p>\n<p>from sklearn.tree import DecisionTreeClassifier<\/p>\n<p>from sklearn.ensemble import BaggingClassifier, RandomForestClassifier<\/p>\n<p>&nbsp;<\/p>\n<p>X, y = load_breast_cancer(return_X_y=True)<\/p>\n<p>X_train, X_test, y_train, y_test = train_test_split(<\/p>\n<p>X, y, test_size=0.3, random_state=0, stratify=y<\/p>\n<p>)<\/p>\n<p>&nbsp;<\/p>\n<p>tree = DecisionTreeClassifier(random_state=0).fit(X_train, y_train)<\/p>\n<p>&nbsp;<\/p>\n<p>bagging = BaggingClassifier(<\/p>\n<p>estimator=DecisionTreeClassifier(),<\/p>\n<p>n_estimators=100,<\/p>\n<p>oob_score=True,<\/p>\n<p>random_state=0,<\/p>\n<p>).fit(X_train, y_train)<\/p>\n<p>&nbsp;<\/p>\n<p>forest = RandomForestClassifier(n_estimators=100, random_state=0).fit(X_train, y_train)<\/p>\n<p>&nbsp;<\/p>\n<p>print(&#8220;Single tree test accuracy:&#8221;, round(tree.score(X_test, y_test), 3))<\/p>\n<p>print(&#8220;Bagging test accuracy:&#8221;, round(bagging.score(X_test, y_test), 3))<\/p>\n<p>print(&#8220;Bagging out of bag score:&#8221;, round(bagging.oob_score_, 3))<\/p>\n<p>print(&#8220;Random forest test accuracy:&#8221;, round(forest.score(X_test, y_test), 3))<\/p>\n<p>print(&#8220;Random forest training accuracy:&#8221;, round(forest.score(X_train, y_train), 3))<\/p>\n<p>When I ran it, this is what it printed:<\/p>\n<p>Single tree test accuracy: 0.906<\/p>\n<p>Bagging test accuracy: 0.936<\/p>\n<p>Bagging out of bag score: 0.955<\/p>\n<p>Random forest test accuracy: 0.953<\/p>\n<p>Random forest training accuracy: 1.0<\/p>\n<h3><strong><b>Reading the Results<\/b><\/strong><\/h3>\n<ul>\n<li><b><\/b><strong><b>Bagging beat the single tree.<\/b><\/strong>The same type of model, trained 100 times on bootstrap samples, gained about three points of accuracy. I also checked this with 10 fold cross validation, where the tree averaged 0.917 and bagging 0.958.<\/li>\n<li><b><\/b><strong><b>The out of bag score is a free check.<\/b><\/strong>It scored each training row using only the trees that never saw it, and gave 0.955 without using the test set. It is a good early indication of how the model will behave on new data.<\/li>\n<li><b><\/b><strong><b>Random forest did a little better still.<\/b><\/strong>It scored 0.953, because it adds one more source of randomness, covered below.<\/li>\n<li><b><\/b><strong><b>Training accuracy of 1.0 is normal here.<\/b><\/strong>A forest of fully grown trees memorises its training data. What matters is the test score.<\/li>\n<\/ul>\n<p>On a test set of 171 patients, one patient is worth about 0.6 points, so the gap between bagging and the forest is within the noise. Do not read it as a winner.<\/p>\n<h2><strong><b>Key Settings of BaggingClassifier<\/b><\/strong><\/h2>\n<div style=\"border: 1px solid #d9e0ea; border-radius: 8px; overflow-x: auto; margin: 20px 0; -webkit-overflow-scrolling: touch;\">\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;\">\n<caption style=\"caption-side: top; text-align: left; padding: 14px 16px; font-weight: bold; font-size: 17px; color: #0f2a4a;\">Key BaggingClassifier settings in scikit learn<\/caption>\n<thead>\n<tr>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38; width: 190px;\" scope=\"col\">Setting<\/th>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38; width: 150px;\" scope=\"col\">Default<\/th>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38;\" scope=\"col\">What it does<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; white-space: nowrap;\" scope=\"row\">estimator<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Decision tree<\/td>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">The base model trained on each sample<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; white-space: nowrap;\" scope=\"row\">n_estimators<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">10<\/td>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">How many models to build. More is steadier but slower<\/td>\n<\/tr>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; white-space: nowrap;\" scope=\"row\">max_samples<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">All rows<\/td>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">How many rows each model draws<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; white-space: nowrap;\" scope=\"row\">max_features<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">1.0<\/td>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Share of features each model sees<\/td>\n<\/tr>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; white-space: nowrap;\" scope=\"row\">bootstrap<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">True<\/td>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Draw rows with replacement. False draws without<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; white-space: nowrap;\" scope=\"row\">bootstrap_features<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">False<\/td>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Draw features with replacement<\/td>\n<\/tr>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; white-space: nowrap;\" scope=\"row\">oob_score<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">False<\/td>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Compute the out of bag score. Needs bootstrap on<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px;\" scope=\"row\">n_jobs<\/th>\n<td style=\"padding: 12px 16px;\">None<\/td>\n<td style=\"padding: 12px 16px;\">Parallel jobs. Use minus one to use every core<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>&nbsp;<\/p>\n<p>Predictions are combined by averaging each model&#8217;s predicted class probabilities. If the base model cannot give probabilities, the ensemble uses a simple vote.<\/p>\n<h2><strong><b>Variants of Bagging<\/b><\/strong><\/h2>\n<ul>\n<li><b><\/b><b><\/b>Draw rows without replacement.<\/li>\n<li><b><\/b><b><\/b>Draw rows with replacement, the standard method.<\/li>\n<li><b><\/b><strong><b>Random subspaces.<\/b><\/strong>Each model sees a random subset of the features.<\/li>\n<li><b><\/b><strong><b>Random patches.<\/b><\/strong>Each model sees random subsets of both rows and features.<\/li>\n<\/ul>\n<h2><strong><b>Random Forest: Bagging With One Extra Trick<\/b><\/strong><\/h2>\n<p>A random forest is bagging with decision trees plus one addition. At every split inside every tree, only a random subset of the features is considered. This forces the trees to differ more from each other, so their errors cancel better. It is why a random forest usually matches or beats plain bagging, and why it needs little tuning.<\/p>\n<p>In classic descriptions a forest predicts by majority vote. In scikit learn, it averages the predicted class probabilities of its trees and picks the class with the highest average. The two usually give the same answer.<\/p>\n<h2><strong><b>Strengths and Limitations of Bagging<\/b><\/strong><\/h2>\n<h3><strong><b>Strengths<\/b><\/strong><\/h3>\n<ul>\n<li>Cuts variance and often improves accuracy over a single model.<\/li>\n<li>Hard to overfit by adding more models.<\/li>\n<li>Models train in parallel.<\/li>\n<li>The out of bag score gives a built in validation estimate.<\/li>\n<li>Works with almost any base model.<\/li>\n<\/ul>\n<h3><strong><b>Limitations<\/b><\/strong><\/h3>\n<ul>\n<li>Does not reduce bias. If the base model is too simple, bagging will not rescue it.<\/li>\n<li>Harder to interpret than a single tree.<\/li>\n<li>Uses more memory and prediction time, because you store and run many models.<\/li>\n<li>Gives little gain for stable models.<\/li>\n<\/ul>\n<h2><strong><b>Applications of Bagging<\/b><\/strong><\/h2>\n<ul>\n<li><b><\/b><strong><b>Credit risk and fraud detection. <\/b><\/strong>Random forests are common in finance.<\/li>\n<li><b><\/b><b><\/b>Predicting disease risk from patient measurements.<\/li>\n<li><b><\/b><strong><b>Customer churn. <\/b><\/strong>Finding customers likely to leave.<\/li>\n<li><b><\/b><strong><b>Price and demand prediction. <\/b><\/strong>Averaging trees for regression.<\/li>\n<li><b><\/b><strong><b>Feature importance. <\/b><\/strong>Forests give a quick ranking of which inputs matter.<\/li>\n<\/ul>\n<p><iframe loading=\"lazy\" src=\"https:\/\/www.youtube.com\/embed\/EGbyBqFlTcQ\" width=\"850\" height=\"315\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<h2><strong><b>Common Mistakes to Avoid<\/b><\/strong><\/h2>\n<ul>\n<li><b><\/b><strong><b>Judging by training accuracy. <\/b><\/strong>Fully grown trees always look perfect on their own training data.<\/li>\n<li><b><\/b><strong><b>Using too few models. <\/b><\/strong>With the default of 10, results can vary. Try 100 or more.<\/li>\n<li><b><\/b><strong><b>Bagging a stable model. <\/b><\/strong>Linear models gain very little.<\/li>\n<li><b><\/b><strong><b>Switching on oob_score without bootstrap. <\/b><\/strong>The out of bag score needs bootstrap sampling.<\/li>\n<li><b><\/b><strong><b>Reading a small gap as a winner. <\/b><\/strong>Use cross validation before choosing between methods.<\/li>\n<li><b><\/b><strong><b>Fitting twice. <\/b><\/strong>Calling fit repeatedly wastes time and can hide mistakes.<\/li>\n<\/ul>\n<p>Bagging shows that averaging many imperfect models beats trusting one. Run the comparison program on your own data, check the out of bag score, and remember that its real job is reducing variance. When you need to reduce bias instead, look at boosting.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Bagging Technique in Machine Learning Ask a hundred people to guess how many sweets are in a jar, and the average of their guesses is often remarkably close to the truth. No single guess is reliable, some are far too high and some far too low, but the mistakes tend to cancel out. Bagging applies [&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":[442,444,441,1759,443],"class_list":["post-4828","post","type-post","status-publish","format-standard","hentry","category-machine-learning","category-machine-learning-modules","tag-bagging-algorithm-introduction","tag-bagging-algorithms-example","tag-bagging-technique-in-machine-learning","tag-ensemble-learning-with-bagging-in-machine-learning","tag-types-of-bagging-algorithms"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Bagging Technique in Machine Learning With Python | PrwaTech<\/title>\n<meta name=\"description\" content=\"Learn how bagging reduces variance with bootstrap samples, compare a single tree, bagging and random forest in Python, and tune the key settings.\" \/>\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\/bagging-technique-in-machine-learning\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Bagging Technique in Machine Learning With Python | PrwaTech\" \/>\n<meta property=\"og:description\" content=\"Learn how bagging reduces variance with bootstrap samples, compare a single tree, bagging and random forest in Python, and tune the key settings.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/bagging-technique-in-machine-learning\/\" \/>\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:44:47+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-10-15T15:37:24+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2020\/02\/bag1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1153\" \/>\n\t<meta property=\"og:image:height\" content=\"265\" \/>\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\/bagging-technique-in-machine-learning\/\",\"url\":\"https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/bagging-technique-in-machine-learning\/\",\"name\":\"Bagging Technique in Machine Learning With Python | PrwaTech\",\"isPartOf\":{\"@id\":\"https:\/\/prwatech.in\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/bagging-technique-in-machine-learning\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/bagging-technique-in-machine-learning\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2020\/02\/bag1-1024x235.png\",\"datePublished\":\"2026-10-14T11:44:47+00:00\",\"dateModified\":\"2026-10-15T15:37:24+00:00\",\"author\":{\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3\"},\"description\":\"Learn how bagging reduces variance with bootstrap samples, compare a single tree, bagging and random forest in Python, and tune the key settings.\",\"breadcrumb\":{\"@id\":\"https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/bagging-technique-in-machine-learning\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/bagging-technique-in-machine-learning\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/bagging-technique-in-machine-learning\/#primaryimage\",\"url\":\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2020\/02\/bag1.png\",\"contentUrl\":\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2020\/02\/bag1.png\",\"width\":1153,\"height\":265},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/bagging-technique-in-machine-learning\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/prwatech.in\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Bagging Technique in Machine Learning\"}]},{\"@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":"Bagging Technique in Machine Learning With Python | PrwaTech","description":"Learn how bagging reduces variance with bootstrap samples, compare a single tree, bagging and random forest in Python, and tune the key settings.","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\/bagging-technique-in-machine-learning\/","og_locale":"en_US","og_type":"article","og_title":"Bagging Technique in Machine Learning With Python | PrwaTech","og_description":"Learn how bagging reduces variance with bootstrap samples, compare a single tree, bagging and random forest in Python, and tune the key settings.","og_url":"https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/bagging-technique-in-machine-learning\/","og_site_name":"Prwatech","article_publisher":"https:\/\/www.facebook.com\/prwatech.in\/","article_published_time":"2026-10-14T11:44:47+00:00","article_modified_time":"2026-10-15T15:37:24+00:00","og_image":[{"width":1153,"height":265,"url":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2020\/02\/bag1.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\/bagging-technique-in-machine-learning\/","url":"https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/bagging-technique-in-machine-learning\/","name":"Bagging Technique in Machine Learning With Python | PrwaTech","isPartOf":{"@id":"https:\/\/prwatech.in\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/bagging-technique-in-machine-learning\/#primaryimage"},"image":{"@id":"https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/bagging-technique-in-machine-learning\/#primaryimage"},"thumbnailUrl":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2020\/02\/bag1-1024x235.png","datePublished":"2026-10-14T11:44:47+00:00","dateModified":"2026-10-15T15:37:24+00:00","author":{"@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3"},"description":"Learn how bagging reduces variance with bootstrap samples, compare a single tree, bagging and random forest in Python, and tune the key settings.","breadcrumb":{"@id":"https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/bagging-technique-in-machine-learning\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/bagging-technique-in-machine-learning\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/bagging-technique-in-machine-learning\/#primaryimage","url":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2020\/02\/bag1.png","contentUrl":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2020\/02\/bag1.png","width":1153,"height":265},{"@type":"BreadcrumbList","@id":"https:\/\/prwatech.in\/blog\/machine-learning\/machine-learning-modules\/bagging-technique-in-machine-learning\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/prwatech.in\/blog\/"},{"@type":"ListItem","position":2,"name":"Bagging Technique in Machine Learning"}]},{"@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\/4828","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=4828"}],"version-history":[{"count":10,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/4828\/revisions"}],"predecessor-version":[{"id":12004,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/4828\/revisions\/12004"}],"wp:attachment":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/media?parent=4828"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/categories?post=4828"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/tags?post=4828"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}