예제 #1
0
        precision = tp / (tp + fp)
        f_score = (2 * (precision * recall)) / (precision + recall)
        print("The recall is: {0}".format(recall))
        print("The precision is: {0}".format(precision))
        print("The F-score is: {0}".format(f_score))


if __name__ == '__main__':

    #location containing the training set
    location = os.path.dirname(os.path.abspath(__file__))
    training_set_location = os.path.join(location,
                                         'extras/files/training_set1.csv')

    #read training data
    training_set = read_csv(training_set_location)

    #remove the data lables
    labels = training_set.pop(0)

    neuron = NeuralNetwork(training_set, 1, 0.1, 0.2)
    print(neuron.weights)
    neuron.output_weights()
    print(neuron.normalized)
    neuron.iterate()
    #neuron.test()

#backprop

# neuron = NeuralNetwork(training_set, 2, 0.1, 0.8, bias = 0, hidden_layer = 2)
# print(neuron.weights)
예제 #2
0
파일: KNN.py 프로젝트: WinnyTroy/ml_toolkit
    to_consider = results[:neigbours]  #since its an ordered list
    to_consider = [x[-1] for x in to_consider]
    voting_results = {data: to_consider.count(data) for data in to_consider}

    max_key = max(voting_results)

    return max_key


if __name__ == '__main__':
    file_loation = os.path.dirname(os.path.abspath(__file__))
    location = os.path.join(file_loation, 'extras/files/training_set1.csv')

    #get the training set
    training_set = read_csv(location)

    #remove the data lables
    labels = training_set.pop(0)

    #get the users input
    query_set, neigbours = get_input(labels)

    #calculate euclidean distances
    response = get_euclidean_distances(training_set, query_set)

    #voting
    winning_label = vote(response, neigbours)

    print("The query set belongs to the label '{0}'.".format(winning_label))