From d25bc3107d22a2fc9a0d0aff8d29550e4e943345 Mon Sep 17 00:00:00 2001 From: abdoulayegk Date: Thu, 19 Nov 2020 07:49:40 +0530 Subject: [PATCH 1/2] adaboost classifier to predict brest cancer --- classification/adaboost_classifier.py | 39 +++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 classification/adaboost_classifier.py diff --git a/classification/adaboost_classifier.py b/classification/adaboost_classifier.py new file mode 100644 index 0000000..e0f23f0 --- /dev/null +++ b/classification/adaboost_classifier.py @@ -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() \ No newline at end of file From dcd6aba9e9dc5db5aef9bef6aeffe3e103978cd8 Mon Sep 17 00:00:00 2001 From: abdoulayegk Date: Thu, 19 Nov 2020 09:12:49 +0530 Subject: [PATCH 2/2] gaussian naive bayes to classify flours iris dataset --- classification/gaussian_n_bayes.py | 32 ++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 classification/gaussian_n_bayes.py diff --git a/classification/gaussian_n_bayes.py b/classification/gaussian_n_bayes.py new file mode 100644 index 0000000..8bbb146 --- /dev/null +++ b/classification/gaussian_n_bayes.py @@ -0,0 +1,32 @@ +# importing libraries +from sklearn.naive_bayes import GaussianNB +from sklearn.model_selection import train_test_split +from sklearn.datasets import load_iris +from sklearn.metrics import accuracy_score, classification_report +import pandas as pd + + +"""To implement Gaussian naves bayes for flowers clssification""" + + +def main(): + + iris = load_iris() + print(iris.keys()) + iris_df = pd.DataFrame(iris.data, columns=iris.feature_names) + iris_df['target'] = iris.target + print(iris_df.head()) + X, y = iris_df.drop('target', 1), iris_df.target + print(X.shape, y.shape) + X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42) + model = GaussianNB() + model.fit(X_train, y_train) + y_pred = model.predict(X_test) + print(y_pred[:10]) + accuracy = accuracy_score(y_test, y_pred) + print("The accuracy of Gaussian naves is {}".format(accuracy)) + # classification report + print(classification_report(y_test, y_pred)) + + +main()