def main():
    if len(sys.argv) != 4:
        print 'Invalid Command. Should be python MainHandler train_file classifier_file type(1:Neutral,2:Polarity) '
        sys.exit(0)

    print sys.argv[1]
    pdata = bayesianClassifier.NBayesianMethod(sys.argv[1], sys.argv[3])
    pdata.trainClassifier(sys.argv[2])
Пример #2
0
def main():

    if len(sys.argv) != 2:
        print 'Invalid Command. Should be python MainHandler test_file '
        sys.exit(0)

    f = open('neutral.pickle')
    classifier = pickle.load(f)
    f.close()
    pdata = bayesianClassifier.NBayesianMethod(sys.argv[1], "1")
    alltweets = []
    print 'Accuracy:', nltk.classify.accuracy(classifier,
                                              [(pdata.features(d), s)
                                               for (d, s) in pdata.tweets])
    for (t, s) in pdata.tweets:
        p = classifier.classify(pdata.features(t))
        alltweets.append((t, p, s))
    f = open('polar.pickle')
    classifier = pickle.load(f)
    f.close()
    pdata = bayesianClassifier.NBayesianMethod(sys.argv[1], 2)
    print 'Accuracy:', nltk.classify.accuracy(classifier,
                                              [(pdata.features(d), s)
                                               for (d, s) in pdata.tweets])

    print 'Tweet \t\t\t Actual \t\t Predicted'
    wrong = 0
    for (t, s) in pdata.tweets:
        p = classifier.classify(pdata.features(t))
        alltweets.append((t, p, s))
    for (t, p, s) in alltweets:
        if p != s:
            print p, s
            print t, '\t', s, '\t', p
            wrong = wrong + 1
    print wrong
    print "Accuracy:", float(wrong) / len(pdata.tweets)
def main():

    if len(sys.argv) != 4:
        print 'Invalid Command. Should be python MainHandler test_file classifier_file type(1:neutral,2:polar)'
        sys.exit(0)

    f = open(sys.argv[2])
    classifier = pickle.load(f)
    f.close()
    pdata = bayesianClassifier.NBayesianMethod(sys.argv[1], sys.argv[3])

    print 'Accuracy:', nltk.classify.accuracy(classifier,
                                              [(pdata.features(d), s)
                                               for (d, s) in pdata.tweets])

    print 'Tweet \t\t\t Actual \t\t Predicted'
import sys
import bayesianClassifier
import pickle
import nltk
f = open('neutral.pickle')
nc = pickle.load(f)
f.close()
ffeatred = open('neutral_woswrds.pickle')
ncred = pickle.load(ffeatred)
ffeatred.close()
f = open('polar.pickle')
pc = pickle.load(f)
f.close()
pdata = bayesianClassifier.NBayesianMethod('ltest.csv')
            if (i <= 100):

                tweets.append(tweet['text'])
                #print( '@%s tweeted: %s' % ( tweet['user']['screen_name'], tweet['text'] ) )
                i = i + 1
            else:
                break

    print 'Total Tweets:', len(tweets)
    f = open('neutral.pickle')
    nc = pickle.load(f)
    f.close()
    posTweets = []
    negTweets = []
    nutrl = []
    ppolar = bayesianClassifier.NBayesianMethod()
    print "************* Neutral Tweets ********************"
    for t in tweets:
        #print t
        s = nc.classify(ppolar.features(t))
        #print t,s
        if (int(s) != 2):
            ppolar.tweets.append(t)
        else:
            nutrl.append(t)
            print t

    f = open('polar.pickle')
    pc = pickle.load(f)
    f.close()
    print "**************************"