I have around 9 string features which I have indexed using string indexer and used vector assembler to get the feature vector and used a normalizer to normalize across features . These are the transformation I have made and used naive Bayes classifier as the estimator , all the above operations after enclosed in a pipeline model. I trained on around 3 lakh samples and tested on 20k samples the model predicted same label for all of them. I handpicked the features is that the problem? Or any tuning parameters available ? I found out a smoothing parameter which I set it to 1.0 should I increased or decrease to improve the model accuracy? Please help
2 Answers
If you are hand-coding, and found that you got the same prediction for everything in your test set, it is possible that you are multiplying feature probabilities until you hit the floating point limitations of your environment, ending up with a zero value, which probably matches one of your labels.
e.g., $0.001 * 0.0001 * 0.0002 * 0.0003 ... = 0$
Try adding log values instead.
e.g., $log(0.001) + log(0.0001) + log(0.0002) ... $
I think that you should read more on the theory of Naive Bayes classifier (http://scikit-learn.org/stable/modules/naive_bayes.html) as it is very crucial that you need to choose the right likelihood distribution, $P(x_i|y)$. If it is hard to choose the right likelihood distribution, you may just try to use a few different distributions to see if the result can be improved.