Supervised ML - Naive Bayes

Steps for Naive Bayes using sklearn(Python):
  1. Import GaussianNB:
    • from sklearn.naivebayes import GaussianNB
  2.  Create classifier:
    • clf = GaussianNB()
  3. Fit the classifier:
    • clf.fit(FeatureTrainingSet,LabelTrainingSet)
  4. Prediction for testing data
    • clf.predict(FeatureTestingSet)
Accuracy is one of the metrics to check fitting of model over available dataset.There are 3 ways to check accuracy
  1. Manually calculating number of correctly predicted data set upon all dataset.
  2. Using accuracy_score metrics:
    • import statement should be: from sklearn_metrics import accuracy_score
    • wherever you want to check accuracy : print accuracy_score(NumpyArrayToBePredicted, labelledArray)
    • Advantage is that you can use other available metrics as well.
  3.   Using Classifier Score:
    • clf.score(FeatureDataTobePredicted,labelledArray)
    • It will calculate predictions for provided data and then calculates accuracy for that data.
    • Advantage is that you don't need to calculate predictions separately if you are interested in accuracy only.


Comments