Example #1
0
def main():
    #               number of inputs
    p_model = Preceptron(2)

    # here is our training data (just some random points generated with a label)
    points = []
    num_points = 100
    for _ in range(num_points):
        points.append(Point())

    # split the data into training and testing data
    train_points, test_points = Point.split_points(points)

    EPOCHS = 10
    for epoch in range(EPOCHS):
        # training happens here
        for _ in range(200):
            rand_num_indx = random.randrange(0, len(train_points)) # choose a random index for points
            rand_train_point = train_points[rand_num_indx]
            # inputs array
            training_inputs = [rand_train_point.x, rand_train_point.y]
            # where is when we adjust the weights by training the model
            p_model.train(training_inputs, rand_train_point.label)

        accuracy = p_model.accuracy(test_points)
        print("Epoch:", epoch+1, "out of", EPOCHS, "accuracy:", accuracy)

        # dont train further if accuracy is perfect
        if accuracy == 1.0:
            break;

    # graph the lines and points of the models
    graph_model(points, p_model)
Example #2
0
def main():
    model_3d = Preceptron(3)

    points = []
    num_points = 100
    for _ in range(num_points):
        points.append(Point())

    # split the data into training and testing data
    train_points, test_points = Point.split_points(points)

    EPOCHS = 10
    BATCH_SIZE = 300
    for epoch in range(EPOCHS):
        # training happens here
        for _ in range(BATCH_SIZE):
            rand_num_indx = random.randrange(len(train_points)) # choose a random index for points
            rand_train_point = train_points[rand_num_indx]
            # inputs array
            training_inputs = [rand_train_point.x, rand_train_point.y, rand_train_point.z]
            # where is when we adjust the weights by training the model
            model_3d.train(training_inputs, rand_train_point.label)

        accuracy = model_3d.accuracy(test_points)
        print("Epoch: {:2d} out of {:2d} accuracy: {:.2f}".format(epoch+1, EPOCHS, accuracy))

        if accuracy == 1.0:
            break

    graph_3d_points(points, model_3d)