Supervised ML - Naive Bayes
Steps for Naive Bayes using sklearn(Python):
- Import GaussianNB:
- from sklearn.naivebayes import GaussianNB
- Create classifier:
- clf = GaussianNB()
- Fit the classifier:
- clf.fit(FeatureTrainingSet,LabelTrainingSet)
- Prediction for testing data
- clf.predict(FeatureTestingSet)
- Manually calculating number of correctly predicted data set upon all dataset.
- 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.
- 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
Post a Comment