Ejemplo n.º 1
0
    def test_knn_state(self):
        train = pure_multivariate_signal( 40, 3 )
        test = pure_multivariate_signal( 20, 3 )

        clf = kNN(k=10)
        clf.train(train)

        clf.ca.enable(['estimates', 'predictions', 'distances'])

        p = clf.predict(test.samples)

        self.failUnless(p == clf.ca.predictions)
        self.failUnless(np.array(clf.ca.estimates).shape == (80,2))
        self.failUnless(clf.ca.distances.shape == (80,160))

        self.failUnless(not clf.ca.distances.fa is train.sa)
        # Those are deep-copied now by default so they should not be the same
        self.failUnless(not (clf.ca.distances.fa['chunks'] is train.sa['chunks']))
        self.failUnless(not (clf.ca.distances.fa.chunks is train.sa.chunks))
Ejemplo n.º 2
0
    def test_knn_state(self):
        train = pure_multivariate_signal( 40, 3 )
        test = pure_multivariate_signal( 20, 3 )

        clf = kNN(k=10)
        clf.train(train)

        clf.ca.enable(['estimates', 'predictions', 'distances'])

        p = clf.predict(test.samples)

        self.failUnless(p == clf.ca.predictions)
        self.failUnless(np.array(clf.ca.estimates).shape == (80,2))
        self.failUnless(clf.ca.distances.shape == (80,160))

        self.failUnless(not clf.ca.distances.fa is train.sa)
        # XXX if we revert to deepcopy for that state following test
        # should fail
        self.failUnless(clf.ca.distances.fa['chunks'] is train.sa['chunks'])
        self.failUnless(clf.ca.distances.fa.chunks is train.sa.chunks)
Ejemplo n.º 3
0
    def test_multivariate(self):

        mv_perf = []
        uv_perf = []

        clf = kNN(k=10)
        for i in xrange(20):
            train = pure_multivariate_signal( 20, 3 )
            test = pure_multivariate_signal( 20, 3 )
            clf.train(train)
            p_mv = clf.predict( test.samples )
            mv_perf.append( np.mean(p_mv==test.targets) )

            clf.train(train[:, 0])
            p_uv = clf.predict(test[:, 0].samples)
            uv_perf.append( np.mean(p_uv==test.targets) )

        mean_mv_perf = np.mean(mv_perf)
        mean_uv_perf = np.mean(uv_perf)

        self.failUnless( mean_mv_perf > 0.9 )
        self.failUnless( mean_uv_perf < mean_mv_perf )
Ejemplo n.º 4
0
    def test_multivariate(self):

        mv_perf = []
        uv_perf = []

        clf = kNN(k=10)
        for i in xrange(20):
            train = pure_multivariate_signal( 20, 3 )
            test = pure_multivariate_signal( 20, 3 )
            clf.train(train)
            p_mv = clf.predict( test.samples )
            mv_perf.append( np.mean(p_mv==test.targets) )

            clf.train(train[:, 0])
            p_uv = clf.predict(test[:, 0].samples)
            uv_perf.append( np.mean(p_uv==test.targets) )

        mean_mv_perf = np.mean(mv_perf)
        mean_uv_perf = np.mean(uv_perf)

        self.failUnless( mean_mv_perf > 0.9 )
        self.failUnless( mean_uv_perf < mean_mv_perf )