acts_as_classifiable
Consider a scenario where you have a blog, and you want to prevent spam comments, but don't want to use captcha as they are bad from accessibility standpoint. What is the solution, in steps `acts_as_classifiable'. Use a Bayesian classifier to distinguish between spam and non-spam and if the comment is flagged as a spam, use a captcha based solution or reject it. Or maybe you want to track the preferences of each user and then based on that make suggestions to them. `acts_as_classifiable' can help in both scenarios and several other. Currently I use it for the web application at Kreeti.com.
To use this plugin, you need to have the gem `classifier' and its dependencies installed. The command below should do it.
gem install classifier --include-dependencies
The plugin itself can be downloaded from
http://opensvn.csie.org/sksinghi/acts_as_classifiable/
Next your database needs to have a table named `classifier_models'. This is used as a persitent store for the built classifier model.
create_table :classifier_models, :force => true do |t|
t.column :identifier, :int
t.column :classifiable_type, :string, :null => false
t.column :data, :blob
end
Now, to use this plugin in your model, put:
class Comment < ActiveRecords::Base
acts_as_classifiable :fields => ["text"], :categories => ["Spam", "Legit"]
end
Let us assume that we have an instance of the above model in '@comment'. Then the classifier can be trained by calling the method `train'
@comment.train :legit
or
@comment.train :spam
Better have some additional helper functions in the model which will do so.
You can also untrain (use it with care) an instance, by using
@comment.untrain :spam
Bulk training and untraining is also possible by
Comment.train @comments, @classifications
where both @comments and @classifications are arrays, such that @classifications contain categorization of each message in @comments.
To use, the classifier to make classification:
@comment.classify
this will return either "Spam" or "Legit". Bulk classification is also possible.
If you want the comment class to have multiple classifiers, one for each user, then all the above methods can be given an additional argument `identifier'.
@comment.train :legit, @user.id
This will create and store a classifier for that particular model, identified by the `identifier'. This can be used in scenarios when one wants to track preference of each user and then want to make suggestions.
The Bayesian classifier in the gem classifier needs some work, but more about it later.
Any questions/issues about this plugin, please post it as a comment or email me.
Update: New release Clusterer + other plugins
93 Comments:
Cool!
It would be really great if the community gets together to provide out of the box training for various classifiable models, spam being an obvious one...
Hi Surendra,
I'd like to use this plugin, unfortunately when I try to train something, I get the following error:
NoMethodError: private method 'word_hash' called for #String:0x48d7940, with the trace leading back to acts_as_classifiable.rb:111
This is Ruby 1.8.5 on XP. Any ideas?
Turns out there's a dependency on stemmer. So I added
require 'stemmer'
to the acts_as_classifiable.rb file and I'm all set.
Is it possible to have a variable number of categories to classify? In otherwords could I have a model declared such as,
class Content < ActiveRecord::Base
acts_as_taggable
acts_as_classifiable :fields => ["summary"], :categories => Tag.find_all
end
As the number of tags in my model grow, will the classifier reclassify?
Thanks for the great work!
Thanks todd. No, the classifier won't reclassify, so if you want to use variable number of categories, it won't work. In case you are using this plugin for something else, you may want to look at the new version, see the update above.
Great article! Thanks.
Thanks for interesting article.
Nice Blog!
Very interesting site. Blog is very good. I am happy that I think the same!
Nice! Nice site! Good resources here. I will bookmark!
Excellent website. Good work. Very useful. I will bookmark!
I see first time your site guys. I like you :)
Viagra
Generic Viagra
Google
Cialis
-------------------------------------------------------
Levitra
Propecia
Meridia
Yahoo!
-------------------------------------------------------
Zocor
Soma
Prozac
Indulge yourself and find partners for hot Sexual Encounters and Adult Dating at Adult friend finder free dating site!
If you are looking for a one night stand or a casual encounter, then the Adult Swingers Club is where the game is played.
If you practice a different range of sexual and sensual activities then adult personals has the Club for you.
Download over 2000 adult dvd movies, available formats: windows, mpeg, psp and ipod!
Shop for Adult Toys, DVDs and Lingerie and other Erotic Adult Products at adult sex toys shop and adult toys store.
qdf86V Thanks to author.
OIL4f5 The best blog you have!
a88Ykf Thanks to author.
Magnific!
Wonderful blog.
actually, that's brilliant. Thank you. I'm going to pass that on to a couple of people.
Hello all!
actually, that's brilliant. Thank you. I'm going to pass that on to a couple of people.
Please write anything else!
actually, that's brilliant. Thank you. I'm going to pass that on to a couple of people.
actually, that's brilliant. Thank you. I'm going to pass that on to a couple of people.
Please write anything else!
Q4C2Kc write more, thanks.
Good job!
Please write anything else!
actually, that's brilliant. Thank you. I'm going to pass that on to a couple of people.
Magnific!
Hello all!
Magnific!
Thanks to author.
Good job!
Hello all!
Please write anything else!
Wonderful blog.
Hello all!
Please write anything else!
Lottery: A tax on people who are bad at math.
When there's a will, I want to be in it.
Oops. My brain just hit a bad sector.
A lot of people mistake a short memory for a clear conscience.
Clap on! , Clap off! clap@#&$NO CARRIER
The gene pool could use a little chlorine.
Calvin, we will not have an anatomically correct snowman!
When there's a will, I want to be in it.
What is a free gift ? Aren't all gifts free?
Clap on! , Clap off! clap@#&$NO CARRIER
A lot of people mistake a short memory for a clear conscience.
Suicidal twin kills sister by mistake!
Energizer Bunny Arrested! Charged with battery.
Suicidal twin kills sister by mistake!
Ever notice how fast Windows runs? Neither did I.
Beam me aboard, Scotty..... Sure. Will a 2x10 do?
Save the whales, collect the whole set
I don't suffer from insanity. I enjoy every minute of it.
Oops. My brain just hit a bad sector.
Wonderful blog.
Save the whales, collect the whole set
actually, that's brilliant. Thank you. I'm going to pass that on to a couple of people.
Beam me aboard, Scotty..... Sure. Will a 2x10 do?
Hello all!
A lot of people mistake a short memory for a clear conscience.
Calvin, we will not have an anatomically correct snowman!
Please write anything else!
If ignorance is bliss, you must be orgasmic.
What is a free gift ? Aren't all gifts free?
Save the whales, collect the whole set
Oops. My brain just hit a bad sector.
Please write anything else!
Beam me aboard, Scotty..... Sure. Will a 2x10 do?
What is a free gift ? Aren't all gifts free?
Oops. My brain just hit a bad sector.
Oops. My brain just hit a bad sector.
Lottery: A tax on people who are bad at math.
Build a watch in 179 easy steps - by C. Forsberg.
actually, that's brilliant. Thank you. I'm going to pass that on to a couple of people.
Please write anything else!
What is a free gift ? Aren't all gifts free?
Lottery: A tax on people who are bad at math.
Ever notice how fast Windows runs? Neither did I.
Energizer Bunny Arrested! Charged with battery.
Lottery: A tax on people who are bad at math.
Hello all!
Clap on! , Clap off! clap@#&$NO CARRIER
Lottery: A tax on people who are bad at math.
Ever notice how fast Windows runs? Neither did I.
Please write anything else!
What is a free gift ? Aren't all gifts free?
Lottery: A tax on people who are bad at math.
<< Home