def evaluate_model(self, k, max_warping_window, train_data, train_label, test_data, test_label):
     print '--------------------------'
     print '--------------------------\n'
     print 'Running for k = ', k
     print 'Running for w = ', max_warping_window
     
     model = KnnDtw(k_neighbours = k, max_warping_window = max_warping_window)
     model.fit(train_data, train_label)
     
     predicted_label, probability = model.predict(test_data)
     
     print '\nPredicted : ', predicted_label
     print 'Actual    : ', test_label
     
     accuracy, precision, recall, f1score = evaluate(self.labels, predicted_label, test_label)
     
     print 'Avg/Total Accuracy  :', accuracy
     print 'Avg/Total Precision :', precision
     print 'Avg/Total Recall    :', recall
     print 'Avg/Total F1 Score  :', f1score
def predict(k, w, train, test):
    click.echo('--- Predicting a label ---')
    #click.echo('Predicting with k=%d and w=%d.' % (k,w))

    train_data, train_label = load_labelled(train)
    test_data = load_test(test)

    click.echo('  - k     : %d ' % k)
    click.echo('  - w     : %d ' % w)
    click.echo('  - train : %s ' % train)
    click.echo('  - test  : %s ' % test)

    click.echo('\nRunning...')

    model = KnnDtw(k_neighbours=k, max_warping_window=w)
    model.fit(train_data, train_label)

    predicted_label, probability = model.predict(test_data)

    click.echo('\nPredicted label : %s ' % str(predicted_label))
    click.echo('\nDone.')
Exemple #3
0
    def evaluate_model(self, k, max_warping_window, train_data, train_label,
                       test_data, test_label):
        print '--------------------------'
        print '--------------------------\n'
        print 'Running for k = ', k
        print 'Running for w = ', max_warping_window

        model = KnnDtw(k_neighbours=k, max_warping_window=max_warping_window)
        model.fit(train_data, train_label)

        predicted_label, probability = model.predict(test_data)

        print '\nPredicted : ', predicted_label
        print 'Actual    : ', test_label

        accuracy, precision, recall, f1score = evaluate(
            self.labels, predicted_label, test_label)

        print 'Avg/Total Accuracy  :', accuracy
        print 'Avg/Total Precision :', precision
        print 'Avg/Total Recall    :', recall
        print 'Avg/Total F1 Score  :', f1score
def online_identification(k, w, window_size, train, test):

    click.echo('\n--- Online flight degradation identification ---')

    train_csv = load_csvs(train, should_preprocess=False)
    test_csv = load_csvs(test, should_preprocess=False)
    
    click.echo('  - k     : %d ' % k)
    click.echo('  - w     : %d ' % w)
    click.echo('  - train : %s ' % train)
    click.echo('  - test  : %s ' % test)

    click.echo('\nRunning...\n')
    
    # For Test
    last_second = test_csv[0]['data']['seconds'].iloc[-1]
    #print('[TEST] Last second: {}'.format(last_second))

    for time_window in range(0, last_second, window_size):
        click.echo('Time window is: %d ' % time_window)

        train_window = get_windows(train_csv, time_window, time_window + window_size - 1)
        test_window = get_windows(test_csv, time_window, time_window + window_size - 1)
        
        train_data, train_label = window_to_lists(train_window, 'pose_position_z')
        test_data, test_label = window_to_lists(test_window, 'pose_position_z')


        model = KnnDtw(k_neighbours = k, max_warping_window = w)
        model.fit(np.array(train_data), np.array(train_label))
        
        #click.echo(train_label)

        predicted_label, probability = model.predict(test_data, parallel=True)
        click.echo('Predicted label : %s ' % str(predicted_label))
    
        click.echo('\n')

    click.echo('\nDone.')
def predict(k, w, train, test):
    click.echo('--- Predicting a label ---')
    #click.echo('Predicting with k=%d and w=%d.' % (k,w))

    train_data, train_label = load_labelled(train)
    test_data = load_test(test)

    click.echo('  - k     : %d ' % k)
    click.echo('  - w     : %d ' % w)
    click.echo('  - train : %s ' % train)
    click.echo('  - test  : %s ' % test)

    click.echo('\nRunning...')


    model = KnnDtw(k_neighbours = k, max_warping_window = w)
    model.fit(train_data, train_label)
    
    predicted_label, probability = model.predict(test_data)
    
    click.echo('\nPredicted label : %s ' % str(predicted_label))
    click.echo('\nDone.')