Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

bagging algorithm

# Import DecisionTreeClassifier
from sklearn.tree import DecisionTreeClassifier

# Import BaggingClassifier
from sklearn.ensemble import BaggingClassifier

# Instantiate dt
dt = DecisionTreeClassifier(random_state=1)

# Instantiate bc
bc = BaggingClassifier(base_estimator=dt,
                       n_estimators=...number of classification trees...,
                       random_state=1,
                       oob_score=True,
                       n_jobs=-1)

# Fit bc to the training set
bc.fit(X_train, y_train)

# Predict test set labels
y_pred = bc.predict(X_test)

# Evaluate OOB accuracy
acc_oob = bc.oob_score_
# Evaluate acc_test
acc_test = accuracy_score(y_test, y_pred)

# Print acc_test and acc_oob
print('Test set accuracy: {:.3f}, OOB accuracy: {:.3f}'.format(acc_test, acc_oob))
Comment

PREVIOUS NEXT
Code Example
Python :: time, date 
Python :: sample stochastic gradient boosting regressor algorithm 
Python :: como colocar uma variavel no print python 
Python :: python kivy black screen 
Python :: fizzbuzz algorithm 
Python :: dht22 micropython library 
Python :: Customizing plot with axes object 
Python :: calculate sin cos tan python 
Python :: Understand the most appropriate graph to use for your dataset 
Python :: reemplazar un caracter de un string 
Python :: negate all elements of a list 
Python :: a list of available font in figlet in python 
Python :: map column dataframe python 
Python :: Horizontal stacked percent bar chart - with dataframe, seaborn colormap 
Python :: how to read file from terminal in python inside code 
Python :: pandas python multiindex 
Python :: short name in python 
Python :: trends in yearly data python 
Python :: how to rinstalll re 
Python :: asp blocking sedular python stackoverflow 
Python :: df.fillna("tagline",inplace=True) in jupyter notebook 
Python :: python pyinstler not found 
Python :: reportlab drawimage issues with png transparency background 
Python :: say something in discord discord.py 
Python :: scrapy itemloader example 
Python :: Return an RDD with the values of each tuple 
Python :: pygame rect follower 
Python :: make large 3d plot in python 
Python :: how to use Py-agender for projects 
Python :: python hangman 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =