在 Ruby 中实现简单的文本分类器
This repository is no longer maintained for some time. If you're interested in maintaining a fork, contact the author such that I can place a link here.
A library for classifying text into multiple categories.
Currently provided classifiers:
Ran a benchmark of 1345 items that I have previously manually classified with multiple categories. Here's the rate over which the 2 algorithms have correctly detected one of those categories:
I prefer the Naive Bayes approach, because while having lower stats on this benchmark, it seems to make better decisions than I did in many cases. For example, an item with title "Paintball Session, 100 Balls and Equipment" was classified as "Activities" by me, but the bayes classifier identified it as "Sports", at which point I had an intellectual orgasm. Also, the Tf-Idf classifier seems to do better on clear-cut cases, but doesn't seem to handle uncertainty so well. Of course, these are just quick tests I made and I have no idea which is really better.
gem install stuff-classifier
You either instantiate one class or the other. Both have the same signature:
…
Training the classifier:
…
And finally, classifying stuff:
…
The following layers for saving the training data between sessions are implemented:
To persist the data in Redis, you can do this:
# defaults to redis running on localhost on default port
store = StuffClassifier::RedisStorage.new(@key)
# pass in connection args
store = StuffClassifier::RedisStorage.new(@key, {host:'my.redis.server.com', port: 4829})
To persist the data on disk, you can do this:
…
The name you give your classifier is important, as based on it the data will get loaded and saved. For instance, following 3 classifiers will be stored in different buckets, being independent of each other.
cls1 = StuffClassifier::Bayes.new("Cats or Dogs")
cls2 = StuffClassifier::Bayes.new("True or False")
cls3 = StuffClassifier::Bayes.new("Spam or Ham")
MIT Licensed. See LICENSE.txt for details.
暂无开放 Issues,或尚未同步最近议题。