A Naïve Bayesian model optimized for sparse datasets, implemented as described in Xia et al. 2004.
In summary, a small-sample correction is applied, (currently the Laplace correction), the probability is normalized, the natural log is taken and the results are summed.
Add this line to your application's Gemfile:
gem 'modified_bayes'
And then execute:
$ bundle
Or install it yourself as:
$ gem install modified_bayes
The features in this example are strings, but features can be any kind of object.
positive_samples = [
["sweet", "yellow"],
["sweet"]
]
negative_samples = [
["sweet", "round"],
["sweet", "yellow"],
["sweet"],
["round"]
]
model = ModifiedBayes::Model.new(positive_samples, negative_samples)
model.score(["sweet", "yellow"]) #=> 0.3001; this sample is predicted to be positive
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request