Improve naive bayes classifier code