Esempio n. 1
0
###############################################################################
# Computing the results of the experiment
###############################################################################
    test_score.append(naive.test_score(numpy.array(sets.lsa_vectors_test[i]), numpy.array(sets.robot_ids_test[i])))
    probability = naive.classifier.predict_proba(sets.lsa_vectors_test[i])
    for j in range(len(sets.lsa_vectors_test[i])):
        predicted_class = naive.predict_new_robot_id(sets.lsa_vectors_test[i][j])[0]
        r_class = sets.robot_ids_test[i][j]
        if r_class != predicted_class:
            print("Correct total prob", numpy.round(probability[j][r_class], 3))
            print("Pred total prob", numpy.round(probability[j][predicted_class], 3))
            print("Prob of real class:", numpy.round(math.exp(naive.classifier.class_log_prior_[r_class]), 3))
            print("Prob of of predicted class:",
                  numpy.round(math.exp(naive.classifier.class_log_prior_[predicted_class]), 3))
            for o in range(len(sets.lsa_vectors_test[i][j])):
                if sets.lsa_vectors_test[i][j][o] > 0.1:
                    print("Term:" + lsa.features_utterance[o])
                    print("Prob of term given real class:",
                          math.exp(naive.classifier.feature_log_prob_[r_class][o]))
                    print("Prob of term given predicted class:",
                          math.exp(naive.classifier.feature_log_prob_[predicted_class][o]))
                    print(sets.lsa_vectors_test[i][j][o])
                    print('\n')
            print("Human phrase: " + sets.test_phrases[i][j])
            print("Correct phrase: " + db.get_robot_utterance(r_class))
            print("Predicted phrase: " + db.get_robot_utterance(predicted_class))
            print('\n'*3)
avg = numpy.round(numpy.average(numpy.array(test_score)), 2)
print("Test Score:", avg)
###############################################################################
Esempio n. 2
0
        ###############################################################################

        ###############################################################################
        # Computing the results of the experiment
        ###############################################################################
        test_score.append(
            naive.test_score(numpy.array(sets.lsa_vectors_test[i]),
                             numpy.array(sets.robot_ids_test[i])))

    avg = numpy.round(numpy.average(numpy.array(test_score)), 2)
    max_index = test_score.index(max(test_score))
    print("Test Score:", avg)
    print(max_index)

    naive = NaiveBayesClassifier(alpha=ALPHA)
    naive.learning_phase(numpy.array(sets.lsa_vectors_train[max_index]),
                         sets.robot_ids_train[max_index])

    j = 0
    for i in range(len(sets.lsa_vectors_test[max_index])):
        if ((sets.robot_ids_test[max_index][i] == naive.predict_new_robot_id(
                sets.lsa_vectors_test[max_index][i]))
                and (sets.robot_ids_test[max_index][i] == j)):
            print(sets.test_phrases[max_index][i])
            print(db.get_robot_utterance(sets.robot_ids_test[max_index][i]))
            j = j + 1

    if j == 22:
        break
###############################################################################