From 0b34ba92bc9ccadaf7e16984dd1400ba38b6ee89 Mon Sep 17 00:00:00 2001 From: Dynamo13 <62235947+Dynamo13@users.noreply.github.com> Date: Sat, 28 Mar 2020 00:40:19 -0400 Subject: [PATCH] Updated naive bayers classifier Used pandas to import dataset sklearn for preprocessing and confusion matrix to check accuracy. The classifier is GaussianNB( lines 23-26) --- .../modular/classifier_gaussiannaivebayes.txt | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/examples/descriptions/modular/classifier_gaussiannaivebayes.txt b/examples/descriptions/modular/classifier_gaussiannaivebayes.txt index 3e0f730de5b..9c3e5661a8a 100644 --- a/examples/descriptions/modular/classifier_gaussiannaivebayes.txt +++ b/examples/descriptions/modular/classifier_gaussiannaivebayes.txt @@ -1,2 +1,33 @@ In this example the Gaussian Naive Bayes algorithm is used to classify toy data +#data preprocessing + +import pandas as pd +data=read.csv('\..\filename.csv') + +X=data.iloc[:,:-1].values +Y=data.iloc[:,4].values #the last cloumn of the data + +#splitting the data into training and test set + +from sklearn.cross_validation import train_test_split +X_train,X_test,Y_train,Y_test=train_test_split(X,Y,test_size=0.25,random_state=0) + +#feature scaling + +from sklearn.preprocessing import StandardScaler +sc=StandardScaler() +X_train=sc.fit_transform(X_train) +X_test=sc.transform(X_test) + +#importing and using the classifier +from sklearn.naive_bayes import GaussianNB +classifier = GaussianNB() +classifier.fit(X_train,Y_train) + +#predicting the dataset +Y_pred=classifier.predict(X_test) + +#making the confusion matrix to check the accuracy of the data +from sklearn.metrics import confusion_matrix +cm=confusion_matrix(Y_test,Y_pred)