0% found this document useful (0 votes)
18 views2 pages

Ada Boost

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views2 pages

Ada Boost

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

In [1]:

from sklearn.ensemble import AdaBoostClassifier


from sklearn import datasets
from sklearn.model_selection import train_test_split
from sklearn import metrics
from sklearn.tree import DecisionTreeClassifier
cancer = datasets.load_breast_cancer()
print("Features:", cancer.feature_names)
print("Labels:", cancer.target_names)
print(cancer.data.shape)
X_train, X_test, y_train, y_test = train_test_split(cancer.data, cancer.tar
abc = AdaBoostClassifier(n_estimators=50, learning_rate=1)

model = abc.fit(X_train, y_train)


y_pred = model.predict(X_test)
print("##############################################################")
print("Accuracy:",metrics.accuracy_score(y_test, y_pred))
print("Precision:",metrics.precision_score(y_test, y_pred))
print("Recall:",metrics.recall_score(y_test, y_pred))
print("Mean Absolute Error:",metrics.mean_absolute_error(y_test, y_pred))
print("Mean Squared Error:",metrics.mean_squared_error(y_test, y_pred))
print("F-Measure:",metrics.recall_score(y_test, y_pred))
print("##############################################################")

Features: ['mean radius' 'mean texture' 'mean perimeter' 'mean area'


'mean smoothness' 'mean compactness' 'mean concavity'
'mean concave points' 'mean symmetry' 'mean fractal dimension'
'radius error' 'texture error' 'perimeter error' 'area error'
'smoothness error' 'compactness error' 'concavity error'
'concave points error' 'symmetry error' 'fractal dimension error'
'worst radius' 'worst texture' 'worst perimeter' 'worst area'
'worst smoothness' 'worst compactness' 'worst concavity'
'worst concave points' 'worst symmetry' 'worst fractal dimension']
Labels: ['malignant' 'benign']
(569, 30)
##############################################################
Accuracy: 0.9883040935672515
Precision: 0.9908256880733946
Recall: 0.9908256880733946
Mean Absolute Error: 0.011695906432748537
Mean Squared Error: 0.011695906432748537
F-Measure: 0.9908256880733946
##############################################################

In [2]:
# Creating a decision tree classifier instance
dtree = DecisionTreeClassifier(criterion='entropy', max_depth=1, random_sta
# Instantiate the bagging classifier
adbclassifier = AdaBoostClassifier(base_estimator=dtree,

n_estimators=100,
learning_rate=0.01,
random_state=1)
# Fit the AdaBoost classifier
model = adbclassifier.fit(X_train, y_train)
#Predict the response for test dataset
y_pred = model.predict(X_test)
# Model Accuracy, how often is the classifier correct?
print("Accuracy:",metrics.accuracy_score(y_test, y_pred))

C:\ProgramData\anaconda3\lib\site-packages\sklearn\ensemble\_base.py:166: FutureWarning:
`base_estimator` was renamed to `estimator` in version 1.2 and will be removed in 1.4.
warnings.warn(

Accuracy: 0.9415204678362573

In [3]:
from sklearn.ensemble import RandomForestClassifier
# Creating a decision tree classifier instance

rf = RandomForestClassifier(n_estimators=20, random_state=0)

# Instantiate the bagging classifier


adbclassifier = AdaBoostClassifier(base_estimator=rf,

n_estimators=100,
learning_rate=0.01,
random_state=1)

# Fit the AdaBoost classifier


model = adbclassifier.fit(X_train, y_train)

#Predict the response for test dataset


y_pred = model.predict(X_test)

# Model Accuracy, how often is the classifier correct?


print("Accuracy:",metrics.accuracy_score(y_test, y_pred))

Accuracy: 0.9707602339181286

C:\ProgramData\anaconda3\lib\site-packages\sklearn\ensemble\_base.py:166: FutureWarning:
`base_estimator` was renamed to `estimator` in version 1.2 and will be removed in 1.4.
warnings.warn(

You might also like