コード例 #1
0
def show_res(raw_set, n, k, new_min, new_max):
    for i in range(n):
        training_set, test_set = mylib.n_fold(n, i, raw_set)
        training_data, training_label = mylib.get_data_label(training_set)
        factory = KnnFactory(training_data, training_label)
        knn_machine_5 = factory.get_KnnMachine(k, new_min, new_max)
        test_data, test_label = mylib.get_data_label(test_set)
        res_label = knn_machine_5.predict(test_data)
        confusion = mylib.confusion_matrix(test_label, res_label)
        accuracy = mylib.get_accuracy(confusion)
        precision = mylib.get_precision(confusion)
        recall = mylib.get_recall(confusion)
        f1_score = mylib.get_f1_score(confusion)
        print("***itr: ", i, " ***")
        print("confusion matrix:")
        print(confusion)
        print("accuracy: ", accuracy)
        print("precision: ", precision)
        print("recall: ", recall)
        print("f1_score: ", f1_score)
コード例 #2
0
def show_res(raw_set, n, sec_num):

    for i in range(n):
        training_set, test_set = mylib.n_fold(n, i, raw_set)
        training_data, training_label = mylib.get_data_label(training_set)
        factory = NaiveBayesFactory(training_data, training_label)
        bayes_5 = factory.get_naiveBayes_machine(sec_num)
        test_data, test_label = mylib.get_data_label(test_set)
        res_label = bayes_5.predict(test_data)
        confusion = mylib.confusion_matrix(test_label, res_label)
        accuracy = mylib.get_accuracy(confusion)
        precision = mylib.get_precision(confusion)
        recall = mylib.get_recall(confusion)
        f1_score = mylib.get_f1_score(confusion)
        print("**************itr: ", i, " **************")
        print("confusion matrix:")
        print(confusion)
        print("accuracy: ", accuracy)
        print("precision: ", precision)
        print("recall: ", recall)
        print("f1_score: ", f1_score)
コード例 #3
0
def show_res(raw_set, n, k, branch_num, impurity_fun, sub_space_fun, seed):

    for i in range(n):
        training_set, test_set = mylib.n_fold(n, i, raw_set)
        training_data, training_label = mylib.get_data_label(training_set)
        factory = ForestFactory(training_data, training_label)
        randForest = factory.get_RF(k, branch_num, impurity_fun, sub_space_fun,
                                    seed)
        test_data, test_label = mylib.get_data_label(test_set)
        true_label = mylib.convert_label(test_label)
        res_label = randForest.predict(test_data)
        confusion = mylib.confusion_matrix(true_label, res_label)
        accuracy = mylib.get_accuracy(confusion)
        precision = mylib.get_precision(confusion)
        recall = mylib.get_recall(confusion)
        f1_score = mylib.get_f1_score(confusion)
        print("**************itr: ", i, " **************")
        print("confusion matrix:")
        print(confusion)
        print("accuracy: ", accuracy)
        print("precision: ", precision)
        print("recall: ", recall)
        print("f1_score: ", f1_score)
コード例 #4
0
def show_res(raw_set, n, gate_num, sub_space_fun, seed):

    for i in range(n):
        training_set, test_set = mylib.n_fold(n, i, raw_set)
        training_data, training_label = mylib.get_data_label(training_set)
        factory = TreeFactory(training_data, training_label)

        dtree = factory.get_DT_machine(gate_num, mylib.entropy, sub_space_fun,
                                       seed)
        test_data, test_label = mylib.get_data_label(test_set)
        true_label = mylib.convert_label(test_label)
        res_label = dtree.predict(test_data)
        confusion = mylib.confusion_matrix(true_label, res_label)
        accuracy = mylib.get_accuracy(confusion)
        precision = mylib.get_precision(confusion)
        recall = mylib.get_recall(confusion)
        f1_score = mylib.get_f1_score(confusion)
        print("**************itr: ", i, " **************")
        print("confusion matrix:")
        print(confusion)
        print("accuracy: ", accuracy)
        print("precision: ", precision)
        print("recall: ", recall)
        print("f1_score: ", f1_score)