Hey everybody, yeah! at present let’s focus on Ensemble Studying. Come on!!
Ensemble Studying is a course of the place a number of base fashions (weak learners) are mixed and educated to resolve the identical drawback. This technique relies on the idea that weak learner alone carry out job poorly however when mixed with different weak learner, they kind a robust leaner, and these ensemble fashions produce extra correct outcomes.
Ensemble studying is a way that mixes a number of machine studying algorithms to provide one optimum predictive mannequin with diminished variance (utilizing bagging), bias (utilizing boosting), and improved prediction (utilizing stacking)
There are three varieties of strategies in Ensemble studying
- Bagging (Parallel Ensemble)
- Stacking
- Boosting (Sequential Ensemble)
Let’s see what’s bagging intimately on this article
It will get its title as a result of it combines Bootstrapping and Aggregation to kind one ensemble mannequin. Bootstrap aggregation refers to ensembles that obtain range within the estimators by coaching on random bootstrap resamples of the information. The aggregation of the outputs of three estimators is achieved by averaging as majority votes.
Right here we’re utilizing the diabetes dataset,
import pandas as pd
df=pd.read_csv('diabetes.csv')
df.head()
df.isnull().sum()
df.describe()df.End result.value_counts()
268/500
x=df.drop('End result',axis='columns')
y=df.End result
from sklearn.preprocessing import StandardScaler
scaler=StandardScaler()
x_scaled=scaler.fit_transform(x)
x_scaled[:3]
from sklearn.model_selection import train_test_split
x_train,x_test,y_train,y_test=train_test_split(x_scaled,y,test_size=0.2,random_state=10)
x_train.form
x_test.form
y_train.value_counts()
209/405
from sklearn.tree import DecisionTreeClassifier
from sklearn.model_selection import cross_val_score
rating=cross_val_score(DecisionTreeClassifier(),x_train,y_train,cv=5)
rating
rating.imply()
from sklearn.ensemble import BaggingClassifier
bag_model=BaggingClassifier(
DecisionTreeClassifier(),n_estimators=100,
max_samples=0.8,oob_score=True,random_state=0
)
bag_model.match(x_train,y_train)
bag_model.oob_score_
bag_model.rating(x_train,y_train)
from sklearn.ensemble import BaggingClassifier
bag_model=BaggingClassifier(
DecisionTreeClassifier(),n_estimators=100,
max_samples=0.8,oob_score=True,random_state=0
)
rating=cross_val_score(bag_model,x_train,y_train,cv=5)
rating.imply()
from sklearn.ensemble import RandomForestClassifier
rating=cross_val_score(RandomForestClassifier(),x_train,y_train,cv=5)
rating.imply()
Right here you’ll be able to entry the total code:
Bagging/Bagging.ipynb at main · kaviya2478/Bagging (github.com)
Thanks. Get pleasure from your life with a bag filled with happiness and meals 🙂