Implementation of naive bayes algorithm.