Naive Bayes NLTK

97 views
Skip to first unread message

Subhabrata

unread,
Nov 21, 2012, 2:39:48 PM11/21/12
to nltk-...@googlegroups.com
Dear Group,
 
I am trying to study NLTK Naive Bayes Classifier source code,
as given in,
# Natural Language Toolkit: Naive Bayes Classifiers
#
# Copyright (C) 2001-2012 NLTK Project
# Author: Edward Loper <edl...@gradient.cis.upenn.edu>
 
I am using Python2.7 with Windows 7.
Here, I could import the following files,
from collections import defaultdict
from nltk.probability import FreqDist, DictionaryProbDist, ELEProbDist, sum_logs
 
I can import even,
from nltk import ClassifierI
but I could not,
from api import ClassifierI
 
If you can kindly let me know how should I do it?
 
Regards,
Subhabrata Banerjee.

Toddy Mladenov

unread,
Nov 21, 2012, 3:04:10 PM11/21/12
to nltk-...@googlegroups.com
The actual module name is nltk.classify.api so you need to use (I think)

from nltk.classify.api import ClassifierI

but why do you need to do this if you already used:
from nltk import ClassifierI?

Toddy


--
 
 

Subhabrata

unread,
Nov 22, 2012, 10:55:00 AM11/22/12
to nltk-...@googlegroups.com
Dear Sir,
Well. I am trying to read the source code and understand it appropriately. If that'd do no issues.
NLTK codes are mammoth and many places they are using their own libraries so I get confused, whether I am calling them properly.
 
Regards,
Subhabrata Banerjee.

JAGANADH G

unread,
Nov 22, 2012, 11:08:09 AM11/22/12
to nltk-...@googlegroups.com
On Thu, Nov 22, 2012 at 9:25 PM, Subhabrata <subhaba...@gmail.com> wrote:
Dear Sir,
Well. I am trying to read the source code and understand it appropriately. If that'd do no issues.
NLTK codes are mammoth and many places they are using their own libraries so I get confused, whether I am calling them properly.
 


Hi  Subhabrata,
To get naive bayes you have to do

>>> from nltk.classify import NaiveBayesClassifier


To train the classifier 
>>> classifier = NaiveBayesClassifier.train(trainfeat)

Incase if you have any issue please let me know

--
**********************************
JAGANADH G
http://jaganadhg.in
ILUGCBE
http://ilugcbe.org.in

Subhabrata

unread,
Nov 22, 2012, 2:11:34 PM11/22/12
to nltk-...@googlegroups.com
Hi Jagannath,

Thanks for the reply. In Naive Bayes/HMM I do not have any problem, it runs fantastic for me in NLTK, even with my own data, I just have the habit of reading good codes and writing good program. I try to do lot of experiments with codes and parameters, not only that gives better code writing capacity but also to play with the theories.

Regards,
Subhabrata Banerjee.

nawafpower

unread,
Nov 23, 2012, 7:44:25 PM11/23/12
to nltk-...@googlegroups.com
Hi,

I'm playing with NLTK too to do some authorship identifications, assuming that I want to use the BOW feature, how does that feature looks like in Python? list? dictionary? if someone can explain not how to do the BOW, but how to store the feature to send it to train 
( classifier = NaiveBayesClassifier.train(trainfeat) )

Your help is much appreciated guys.

Nawaf

Subhabrata

unread,
Nov 24, 2012, 3:32:30 PM11/24/12
to nltk-...@googlegroups.com
In authorship Identification there are many good papers. There is a whole group of people devoted on it in SIGIR.
Reply all
Reply to author
Forward
0 new messages