Ejemplo n.º 1
0
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);
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
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) + '%'
Ejemplo n.º 5
0
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)]
Ejemplo n.º 6
0
    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) + '%'