Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adaboost classifier to predict Brest cancer #127

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions classification/adaboost_classifier.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from sklearn.ensemble import AdaBoostClassifier
from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
from sklearn.metrics import plot_confusion_matrix
from matplotlib import pyplot as plt


"""Adaboost classifier example"""


def adaboost():
cancer_df = load_breast_cancer()
print(cancer_df.keys())
X, y = cancer_df.data, cancer_df.target
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42)

abc = AdaBoostClassifier(base_estimator=None,
n_estimators=300, learning_rate=1, random_state=0)
abc.fit(X_train, y_train)
y_pred = abc.predict(X_test)
print(y_pred[:20])
# Display Confusion Matrix of Classifier
plot_confusion_matrix(
abc,
X_test,
y_test,
display_labels=cancer_df["target_names"],
cmap="Blues",
normalize="true",
)
plt.title("Normalized Confusion Matrix - Cancer Dataset")
plt.show()

# to see the accuracy of the model
print("Accuracy of adaboost is:", abc.score(X_test, y_test))


if __name__ == "__main__":
adaboost()