Beispiel #1
0
def test_models():
    for i, model in enumerate(models):
        print("model{0} results:".format(i + 1))
        # dohvati vjerojatnosti na skupu za učenje
        probs = model.eval(mnist.train.images)

        # ispiši performansu (preciznost i odziv po razredima)
        Y = model.eval_class(mnist.test.images)

        accuracy, pr, M = data.eval_perf_multi(
            Y, mnist.test.labels.argmax(axis=1))
        print("Accuracy: ", accuracy)
        print("Precision / Recall: ", pr)
        print("Confusion Matrix: ", M)
Beispiel #2
0
    tf.set_random_seed(100)

    # instanciraj podatke X i labele Yoh_

    X, Y_ = data.sample_gmm_2d(6, 2, 10)

    Yoh_ = data.class_to_onehot(Y_)

    # izgradi graf:
    tf_deep = TF_deep([2, 10, 10, 2])

    # nauči parametre:
    tf_deep.train(X, Yoh_, 10000)

    # dohvati vjerojatnosti na skupu za učenje
    probs = tf_deep.eval(X)
    print(probs)

    # ispiši performansu (preciznost i odziv po razredima)
    Y = tf_deep.eval_class(X)
    print(Y)
    accuracy, pr, M = data.eval_perf_multi(tf_deep.eval_class(X), Y_)
    print("Accuracy: ", accuracy)
    print("Precision / Recall: ", pr)
    print("Confusion Matrix: ", M)

    # iscrtaj rezultate, decizijsku plohu
    rect = (np.min(X, axis=0), np.max(X, axis=0))
    data.graph_surface(tf_deep.eval_probs, rect, offset=0.5)
    data.graph_data(X, Y_, Y_)
    plt.show()
Beispiel #3
0
def fcann2_classify(X, W1, b1, W2, b2):
    s1 = np.dot(X, W1) + b1
    h1 = relu(s1)
    s2 = np.dot(h1, W2) + b2
    return softmax(s2)


if __name__ == "__main__":
    # init random seeds
    np.random.seed(100)

    # create data
    X, Y_ = data.sample_gmm_2d(6, 2, 10)

    # train model
    W1, b1, W2, b2 = fcann2_train(X, Y_, 5, 10000, 0.05, 1e-3, print_diagnostics_step=1000)

    # print diagnostics
    Y = fcnn2_decfun_class(X, W1, b1, W2, b2)(X)
    accuracy, pr, M = data.eval_perf_multi(Y, Y_)
    print("Accuracy: ", accuracy)
    print("Precision / Recall: ", pr)
    print("Confusion Matrix: ", M)

    # graph the decision surface
    rect = (np.min(X, axis=0), np.max(X, axis=0))
    decision_function = fcnn2_decfun_probs(X, W1, b1, W2, b2)
    data.graph_surface(decision_function, rect, offset=0.5)
    data.graph_data(X, Y_, fcnn2_decfun_class(X, W1, b1, W2, b2))
    plt.show()
Beispiel #4
0
 def get_scores(self, X, Y_):
     accuracy, pr, M = data.eval_perf_multi(self.predict(X), Y_)
     print("Accuracy: ", accuracy)
     print("Precision / Recall: ", pr)
     print("Confusion Matrix: ", M)