예제 #1
0
def test_highLevelsktime(network=catch22ForestClassifier()):
    '''
    truly generalised test with sktime tasks/strategies
        load data, build task
        construct classifier, build strategy
        fit,
        score
    '''

    print("start test_highLevelsktime()")

    from sktime.highlevel.tasks import TSCTask
    from sktime.highlevel.strategies import TSCStrategy
    from sklearn.metrics import accuracy_score

    train = load_gunpoint(split='TRAIN')
    test = load_gunpoint(split='TEST')
    task = TSCTask(target='class_val', metadata=train)

    strategy = TSCStrategy(network)
    strategy.fit(task, train.iloc[:10])

    y_pred = strategy.predict(test.iloc[:10])
    y_test = test.iloc[:10][task.target].values.astype(np.float)
    print(accuracy_score(y_test, y_pred))

    print("End test_highLevelsktime()")
예제 #2
0
def test_pipeline(network=catch22ForestClassifier()):
    '''
    slightly more generalised test with sktime pipelines
        load data,
        construct pipeline with classifier,
        fit,
        score
    '''

    print("Start test_pipeline()")

    from sktime.pipeline import Pipeline

    # just a simple (useless) pipeline

    steps = [('clf', network)]
    clf = Pipeline(steps)

    X_train, y_train = load_gunpoint(split='TRAIN', return_X_y=True)
    X_test, y_test = load_gunpoint(split='TEST', return_X_y=True)

    hist = clf.fit(X_train[:10], y_train[:10])

    print(clf.score(X_test[:10], y_test[:10]))
    print("End test_pipeline()")
예제 #3
0
def test_network(network=catch22ForestClassifier()):
    # sklearn compatibility

    test_basic_univariate(network)
    # test_basic_multivariate(network)
    test_pipeline(network)
    test_highLevelsktime(network)
예제 #4
0
def all_networks_all_tests():

    networks = [
        catch22ForestClassifier(),
    ]

    for network in networks:
        print('\n\t\t' + network.__class__.__name__ + ' testing started')
        test_network(network)
        print('\t\t' + network.__class__.__name__ + ' testing finished')
예제 #5
0
def test_basic_univariate(network=catch22ForestClassifier()):
    '''
    just a super basic test with gunpoint,
        load data,
        construct classifier,
        fit,
        score
    '''

    print("Start test_basic()")

    X_train, y_train = load_gunpoint(split='TRAIN', return_X_y=True)
    X_test, y_test = load_gunpoint(split='TEST', return_X_y=True)

    hist = network.fit(X_train[:10], y_train[:10])

    print(network.score(X_test[:10], y_test[:10]))
    print("End test_basic()")
예제 #6
0
if __name__ == "__main__":

    X_train, y_train = load_gunpoint(split='TRAIN', return_X_y=True)
    X_test, y_test = load_gunpoint(split='TEST', return_X_y=True)

    # # alternatively load data from disk
    # X_train, y_train = load_from_tsfile_to_dataframe(
    #     '/home/carl/Downloads/Matthew_errorData/UWaveGestureLibraryZ_TRAIN.ts')
    # X_test, y_test = load_from_tsfile_to_dataframe(
    #     '/home/carl/Downloads/Matthew_errorData/UWaveGestureLibraryZ_TEST.ts')

    # In case the labels are not numbers
    if not isinstance(y_train[0], (int, float)):
        le = LabelEncoder()
        le.fit(np.unique(y_train))
        y_train = le.transform(y_train)
        y_test = le.transform(y_test)
    else:
        y_train = y_train.astype(np.int64)
        y_test = y_test.astype(np.int64)

    f = catch22ForestClassifier()
    c = time.time()
    f.fit(X_train, y_train)
    print("Classes: ", f.classes_)
    print("Num dimensions: ", X_train.shape[1])
    print("Num patterns: ", X_train.shape[0])
    print("Num timepoints: ", len(X_train.iloc[0].iloc[0]))
    print("Accuracy: ", f.score(X_test, y_test))
    print("Time spent: ", round(time.time() - c))