def test_TSclassifier():
    """Test TS Classifier"""
    covset = generate_cov(40, 3)
    labels = np.array([0, 1]).repeat(20)

    assert_raises(TypeError, TSclassifier, clf='666')
    clf = TSclassifier()
    clf.fit(covset, labels)
    clf.predict(covset)
    clf.predict_proba(covset)
def test_TSclassifier():
    """Test TS Classifier"""
    covset = generate_cov(40, 3)
    labels = np.array([0, 1]).repeat(20)

    assert_raises(TypeError, TSclassifier, clf='666')
    clf = TSclassifier()
    clf.fit(covset, labels)
    clf.predict(covset)
    clf.predict_proba(covset)
Ejemplo n.º 3
0
def test_TSclassifier():
    """Test TS Classifier"""
    covset = generate_cov(40, 3)
    labels = np.array([0, 1]).repeat(20)

    with pytest.raises(TypeError):
        TSclassifier(clf='666')

    clf = TSclassifier()
    clf.fit(covset, labels)
    assert_array_equal(clf.classes_, np.array([0, 1]))
    clf.predict(covset)
    clf.predict_proba(covset)
class wrapper_TSclassifier(machine_learning_method):
    """wrapper for pyriemann TSclassifier"""
    def __init__(self, method_name, method_args):
        super(wrapper_TSclassifier, self).__init__(method_name, method_args)
        self.init_method()

    def init_method(self):
        self.classifier = TSclassifier(metric=self.method_args['metric'],
                                       tsupdate=self.method_args['tsupdate'])

    def fit(self, X, y):
        return self.classifier.fit(X, y)

    def predict(self, X):
        return self.classifier.predict(X)
            MDM_record.append(np.sum(pred == test_label) / box_length)
            print('-----------------------------------------')

            Fgmdm = FgMDM(metric=dict(mean='riemann', distance='riemann'))

            Fgmdm.fit(train, train_label)
            pred = Fgmdm.predict(test)

            print('FGMDM: {:4f}'.format(
                np.sum(pred == test_label) / box_length))
            FGMDM_record.append(np.sum(pred == test_label) / box_length)
            print('-----------------------------------------')

            clf = TSclassifier()
            clf.fit(train, train_label)
            pred = clf.predict(test)

            print('TSC: {:4f}'.format(np.sum(pred == test_label) / box_length))
            TSC_record.append(np.sum(pred == test_label) / box_length)
            print('-----------------------------------------')

            lr = LogisticRegression()
            csp = CSP(n_components=4, reg='ledoit_wolf', log=True)
            clf = Pipeline([('CSP', csp), ('LogisticRegression', lr)])
            clf.fit(train_CSP, train_label)
            pred = clf.predict(test_CSP)

            print('CSP_lr: {:4f}'.format(
                np.sum(pred == test_label) / box_length))
            CSP_lr_record.append(np.sum(pred == test_label) / box_length)
            print('-----------------------------------------')