This repository was archived by the owner on Sep 7, 2025. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork174
Gaussian naive Bayes algorithm#128
Open
abdoulayegk wants to merge2 commits intoAllAlgorithms:masterChoose a base branch fromabdoulayegk:gaussan
base:master
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Uh oh!
There was an error while loading.Please reload this page.
Open
Changes fromall commits
Commits
Show all changes
2 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
39 changes: 39 additions & 0 deletionsclassification/adaboost_classifier.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| 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() |
32 changes: 32 additions & 0 deletionsclassification/gaussian_n_bayes.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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() |
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.