def main(): choice='TP' prepare_dictionary(); if(choice == 'TP'): global pathVars; global pathToAuthors; global gloveText; for i, item in enumerate(pathVars): pathToFold = os.getcwd() + "/data/folds"+ "/" + pathTopics[i]+ "_folds"; reorderedData = reorder(readData.readData(pathVars[i], pathToAuthors, pathTopics[i]), pathToFold); learn(reorderedData, pathTopics[i]); elif(choice == 'E'): sentence = raw_input("Enter your sentence.."); topic = raw_input(' What is the topic? '); predict(sentence.lower(), topic);
def main(): choice = 'TP' prepare_dictionary() if (choice == 'TP'): global pathVars global pathToAuthors global gloveText for i, item in enumerate(pathVars): pathToFold = os.getcwd( ) + "/data/folds" + "/" + pathTopics[i] + "_folds" reorderedData = reorder( readData.readData(pathVars[i], pathToAuthors, pathTopics[i]), pathToFold) learn(reorderedData, pathTopics[i]) elif (choice == 'E'): sentence = raw_input("Enter your sentence..") topic = raw_input(' What is the topic? ') predict(sentence.lower(), topic)
def update_output_div(n, tag): rows = [[learn.predict(MODEL, x, TOKENS), x.replace('\n', '')] for x in twitter.get_last_tweets(tag)] emos = [row[0] for row in rows] x = ['Neutral', 'Negative', 'Positive'] y = [emos.count('neutral'), emos.count('negative'), emos.count('positive')] fig = go.Figure(data=[go.Pie(labels=x, values=y)], layout=go.Layout(title='Points Accumulation', showlegend=False)) return fig
def testAlgo(name, classifier, iterations, output=None): print name expected = map(learn.getClassification, tests) testCount = len(expected) scores = [] for iteration in range(0, iterations): actual = learn.predict(classifier, trainings, tests) scores.append(getScore(expected, actual)) # print scores average = numpy.mean(scores) percentage = int((float(average) / float(testCount)) * 100.0) # print str(average) + "/" + str(float(totalCount)) + "\n" print str(percentage) + '%'
def update_output_div(n, tag): rows = [[learn.predict(MODEL, x, TOKENS), x.replace('\n', '')] for x in twitter.get_last_tweets(tag)] return [generate_table(rows)]
trainings = json.load(data_file) with open(test_filename) as data_file: tests = json.load(data_file) def getScore(expected, actual): numCorrect = 0 length = len(expected) for index in range(0, length): if (expected[index] == actual[index]): numCorrect += 1 return numCorrect expected = map(learn.getClassification, tests) actual = learn.predict(classifier, trainings, tests) def testAlgo(name, classifier, iterations, output=None): print name expected = map(learn.getClassification, tests) testCount = len(expected) scores = [] for iteration in range(0, iterations): actual = learn.predict(classifier, trainings, tests) scores.append(getScore(expected, actual)) # print scores average = numpy.mean(scores) percentage = int((float(average) / float(testCount)) * 100.0) # print str(average) + "/" + str(float(totalCount)) + "\n" print str(percentage) + '%'