Beispiel #1
0
    def test_from_data(self):
        # with self.assertRaises(RuntimeError) as cm:
        #     i = np.atleast_2d(np.array([0, 1])).T
        #     t = np.atleast_2d(np.array([2])).T
        #     c = ConfusionMatrix.from_data(3, i, t)
        # self.assertEqual(cm.exception.message, "Output and target data should have the same shape")
        def func():
            i = np.atleast_2d(np.array([0, 1])).T
            t = np.atleast_2d(np.array([2])).T
            c = ConfusionMatrix.from_data(3, i, t)

        self.assertRaises(RuntimeError, func)

        i = np.atleast_2d(np.array([0, 0, 1, 2, 0, 0, 2, 2, 1, 2])).T
        t = np.atleast_2d(np.array([0, 0, 0, 1, 1, 0, 2, 2, 1, 1])).T
        c = ConfusionMatrix.from_data(3, i, t)

        self.assertTrue(np.all(c.truth == [4, 4, 2]))
        self.assertTrue(np.all(c.detections == [4, 2, 4]))
        self.assertTrue(np.all(c.correct == [3, 1, 2]))
        self.assertTrue(np.all(c.incorrect == [1, 3, 0]))
Beispiel #2
0
 def func():
     i = np.atleast_2d(np.array([0, 1])).T
     t = np.atleast_2d(np.array([2])).T
     c = ConfusionMatrix.from_data(3, i, t)
Beispiel #3
0
# testout = flow(test_inputs[0])
# trainout = flow(train_inputs[0])
# testout = flow(test_inputs[0])
# print "shape of testout: ", numpy.shape(testout)

import scipy as sp
from Oger.utils import ConfusionMatrix, plot_conf

ytest = []
for xtest in test_inputs:
    ytest.append(opt_flow(xtest))
ymean = sp.atleast_2d(sp.array([sp.argmax(mdp.numx.atleast_2d(mdp.numx.mean(sample, axis=0))) for sample in test_targets])).T
ytestmean = sp.atleast_2d(sp.array([sp.argmax(mdp.numx.atleast_2d(mdp.numx.mean(sample, axis=0))) for sample in ytest])).T

# use ConfusionMatrix to compute some more information about the
confusion_matrix = ConfusionMatrix.from_data(61, ytestmean , ymean) # 61 classes
print "Error rate: %.4f" % confusion_matrix.error_rate # this comes down to 0-1 loss
print "Balanced error rate: %.4f" % confusion_matrix.ber
print

# compute precision and recall for each class vs. all others
print "Per-class precision and recall"
binary_confusion_matrices = confusion_matrix.binary()
for c in range(61):
    m = binary_confusion_matrices[c]
    print "label %d - precision: %.2f, recall %.2f" % (c, m.precision, m.recall)
print

# properties of the ConfusionMatrix and BinaryConfusionMatrix classes can also be used
# as error measure functions, as follows:
ber = ConfusionMatrix.error_measure('ber', 61) # 61-class balanced error rate
Beispiel #4
0
            for (sample, target) in zip(ytest, outputs[n_train_samples:])
        ]))

    ymean = sp.atleast_2d(
        sp.array([
            sp.argmax(mdp.numx.atleast_2d(mdp.numx.mean(sample, axis=0)))
            for sample in outputs[n_train_samples:]
        ])).T
    ytestmean = sp.atleast_2d(
        sp.array([
            sp.argmax(mdp.numx.atleast_2d(mdp.numx.mean(sample, axis=0)))
            for sample in ytest
        ])).T

    # use ConfusionMatrix to compute some more information about the
    confusion_matrix = ConfusionMatrix.from_data(10, ytestmean,
                                                 ymean)  # 10 classes
    print "Error rate: %.4f" % confusion_matrix.error_rate  # this comes down to 0-1 loss
    print "Balanced error rate: %.4f" % confusion_matrix.ber
    print

    # compute precision and recall for each class vs. all others
    print "Per-class precision and recall"
    binary_confusion_matrices = confusion_matrix.binary()
    for c in range(10):
        m = binary_confusion_matrices[c]
        print "label %d - precision: %.2f, recall %.2f" % (c, m.precision,
                                                           m.recall)
    print

    # properties of the ConfusionMatrix and BinaryConfusionMatrix classes can also be used
    # as error measure functions, as follows:
Beispiel #5
0
        ytest.append(flow(xtest))

    pylab.subplot(n_subplots_x, n_subplots_y, 2)
    pylab.plot(reservoir.inspect()[0])
    pylab.title("Sample reservoir states")
    pylab.xlabel("Timestep")
    pylab.ylabel("Activation")

    print "Error : " + str(mdp.numx.mean([loss_01_time(sample, target) for (sample, target) in zip(ytest, outputs[n_train_samples:])]))

    ymean = sp.array([sp.argmax(mdp.numx.atleast_2d(mdp.numx.mean(sample, axis=0))) for sample in
                      outputs[n_train_samples:]])
    ytestmean = sp.array([sp.argmax(mdp.numx.atleast_2d(mdp.numx.mean(sample, axis=0))) for sample in ytest])

    # use ConfusionMatrix to compute some more information about the 
    confusion_matrix = ConfusionMatrix.from_data(10, ytestmean, ymean) # 10 classes
    print "Error rate: %.4f" % confusion_matrix.error_rate # this comes down to 0-1 loss
    print "Balanced error rate: %.4f" % confusion_matrix.ber
    print

    # compute precision and recall for each class vs. all others
    print "Per-class precision and recall"
    binary_confusion_matrices = confusion_matrix.binary()
    for c in range(10):
        m = binary_confusion_matrices[c]
        print "label %d - precision: %.2f, recall %.2f" % (c, m.precision, m.recall)
    print

    # properties of the ConfusionMatrix and BinaryConfusionMatrix classes can also be used
    # as error measure functions, as follows:
    ber = ConfusionMatrix.error_measure('ber', 10) # 10-class balanced error rate
Beispiel #6
0
ytest = []
for xtest in test_inputs:
    ytest.append(opt_flow(xtest))
ymean = sp.atleast_2d(
    sp.array([
        sp.argmax(mdp.numx.atleast_2d(mdp.numx.mean(sample, axis=0)))
        for sample in test_targets
    ])).T
ytestmean = sp.atleast_2d(
    sp.array([
        sp.argmax(mdp.numx.atleast_2d(mdp.numx.mean(sample, axis=0)))
        for sample in ytest
    ])).T

# use ConfusionMatrix to compute some more information about the
confusion_matrix = ConfusionMatrix.from_data(61, ytestmean,
                                             ymean)  # 61 classes
print "Error rate: %.4f" % confusion_matrix.error_rate  # this comes down to 0-1 loss
print "Balanced error rate: %.4f" % confusion_matrix.ber
print

# compute precision and recall for each class vs. all others
print "Per-class precision and recall"
binary_confusion_matrices = confusion_matrix.binary()
for c in range(61):
    m = binary_confusion_matrices[c]
    print "label %d - precision: %.2f, recall %.2f" % (c, m.precision,
                                                       m.recall)
print

# properties of the ConfusionMatrix and BinaryConfusionMatrix classes can also be used
# as error measure functions, as follows: