def test_auto_encoder():
    iris = DataSet(name="iris")
    classes = ["setosa", "versicolor", "virginica"]
    iris.classes_to_numbers(classes)
    inputs = np.asarray(iris.examples)
    model = auto_encoder_learner(inputs, 100)
    print(inputs[0])
    print(model.predict(inputs[:1]))
Example #2
0
def test_autoencoder():
    iris = DataSet(name='iris')
    classes = ['setosa', 'versicolor', 'virginica']
    iris.classes_to_numbers(classes)
    inputs = np.asarray(iris.examples)
    al = AutoencoderLearner(inputs, 100)
    print(inputs[0])
    print(al.predict(inputs[:1]))
Example #3
0
def test_perceptron():
    iris = DataSet(name="iris")
    classes = ["setosa", "versicolor", "virginica"]
    iris.classes_to_numbers(classes)
    perceptron = perceptron_learner(iris, learning_rate=0.01, epochs=100)
    tests = [([5, 3, 1, 0.1], 0), ([5, 3.5, 1, 0], 0), ([6, 3, 4, 1.1], 1),
             ([6, 2, 3.5, 1], 1), ([7.5, 4, 6, 2], 2), ([7, 3, 6, 2.5], 2)]
    assert grade_learner(perceptron, tests) > 1 / 2
    assert err_ratio(perceptron, iris) < 0.4
Example #4
0
def test_perceptron():
    iris = DataSet(name='iris')
    classes = ['setosa', 'versicolor', 'virginica']
    iris.classes_to_numbers(classes)
    pl = PerceptronLearner(iris, learning_rate=0.01, epochs=100)
    tests = [([5, 3, 1, 0.1], 0), ([5, 3.5, 1, 0], 0), ([6, 3, 4, 1.1], 1),
             ([6, 2, 3.5, 1], 1), ([7.5, 4, 6, 2], 2), ([7, 3, 6, 2.5], 2)]
    assert grade_learner(pl, tests) > 1 / 2
    assert err_ratio(pl, iris) < 0.4
def test_perceptron():
    iris = DataSet(name='iris')
    classes = ['setosa', 'versicolor', 'virginica']
    iris.classes_to_numbers(classes)
    pl_gd = PerceptronLearner(iris,
                              l_rate=0.01,
                              epochs=100,
                              optimizer=stochastic_gradient_descent)
    pl_adam = PerceptronLearner(iris, l_rate=0.01, epochs=100, optimizer=adam)
    tests = [([5, 3, 1, 0.1], 0), ([5, 3.5, 1, 0], 0), ([6, 3, 4, 1.1], 1),
             ([6, 2, 3.5, 1], 1), ([7.5, 4, 6, 2], 2), ([7, 3, 6, 2.5], 2)]
    assert grade_learner(pl_gd, tests) > 1 / 2
    assert err_ratio(pl_gd, iris) < 0.4
    assert grade_learner(pl_adam, tests) > 1 / 2
    assert err_ratio(pl_adam, iris) < 0.4
Example #6
0
def test_perceptron():
    iris = DataSet(name='iris')
    classes = ['setosa', 'versicolor', 'virginica']
    iris.classes_to_numbers(classes)
    n_samples, n_features = len(iris.examples), iris.target

    X, y = (np.array([x[:n_features] for x in iris.examples]),
            np.array([x[n_features] for x in iris.examples]))

    pl_gd = PerceptronLearner(iris, l_rate=0.01, epochs=100, optimizer=stochastic_gradient_descent).fit(X, y)
    assert grade_learner(pl_gd, iris_tests) == 1
    assert err_ratio(pl_gd, iris) < 0.2

    pl_adam = PerceptronLearner(iris, l_rate=0.01, epochs=100, optimizer=adam).fit(X, y)
    assert grade_learner(pl_adam, iris_tests) == 1
    assert err_ratio(pl_adam, iris) < 0.2
Example #7
0
def test_neural_net():
    iris = DataSet(name='iris')
    classes = ['setosa', 'versicolor', 'virginica']
    iris.classes_to_numbers(classes)
    n_samples, n_features = len(iris.examples), iris.target

    X, y = (np.array([x[:n_features] for x in iris.examples]),
            np.array([x[n_features] for x in iris.examples]))

    nnl_gd = NeuralNetworkLearner(iris, [4], l_rate=0.15, epochs=100, optimizer=stochastic_gradient_descent).fit(X, y)
    assert grade_learner(nnl_gd, iris_tests) > 0.7
    assert err_ratio(nnl_gd, iris) < 0.15

    nnl_adam = NeuralNetworkLearner(iris, [4], l_rate=0.001, epochs=200, optimizer=adam).fit(X, y)
    assert grade_learner(nnl_adam, iris_tests) > 0.7
    assert err_ratio(nnl_adam, iris) < 0.15
Example #8
0
def test_neural_net():
    iris = DataSet(name='iris')
    classes = ['setosa', 'versicolor', 'virginica']
    iris.classes_to_numbers(classes)
    nnl_adam = NeuralNetLearner(iris, [4], learning_rate=0.001, epochs=200, optimizer=adam)
    nnl_gd = NeuralNetLearner(iris, [4], learning_rate=0.15, epochs=100, optimizer=gradient_descent)
    tests = [([5.0, 3.1, 0.9, 0.1], 0),
             ([5.1, 3.5, 1.0, 0.0], 0),
             ([4.9, 3.3, 1.1, 0.1], 0),
             ([6.0, 3.0, 4.0, 1.1], 1),
             ([6.1, 2.2, 3.5, 1.0], 1),
             ([5.9, 2.5, 3.3, 1.1], 1),
             ([7.5, 4.1, 6.2, 2.3], 2),
             ([7.3, 4.0, 6.1, 2.4], 2),
             ([7.0, 3.3, 6.1, 2.5], 2)]
    assert grade_learner(nnl_adam, tests) >= 1 / 3
    assert grade_learner(nnl_gd, tests) >= 1 / 3
    assert err_ratio(nnl_adam, iris) < 0.21
    assert err_ratio(nnl_gd, iris) < 0.21