def get_sub_result_df(base_model, input_names, output_names, result_column,
                      i_sub):
    total_sub_df = pd.DataFrame()
    start_time = datetime.now()
    print('Subject ' + str(i_sub) + ', start at ' +
          start_time.strftime('%H:%M:%S'))
    all_sub_data = pd.read_csv(ALL_SUB_FILE, index_col=False)
    other_sub_data = all_sub_data[all_sub_data['subject_id'] != i_sub]
    x_train = other_sub_data[input_names]
    y_train = other_sub_data[output_names]
    my_evaluator = Evaluation(output_names, base_model)

    my_evaluator.train_sklearn(x_train, y_train)  # very time consuming
    test_sub_data = all_sub_data[all_sub_data['subject_id'] == i_sub]
    del all_sub_data
    subject_data = SubjectData(PROCESSED_DATA_PATH, i_sub)
    # the range have to be defined after subject data to get the diameter
    shank_diameter = SubjectData.get_cylinder_diameter(test_sub_data,
                                                       'l_shank')
    thigh_diameter = SubjectData.get_cylinder_diameter(test_sub_data,
                                                       'l_thigh')
    for segment_moved in SEGMENT_NAMES:
        if i_sub == 0:  # for test
            print('subject 0, ' + segment_moved)
        multi_offset = MultiAxisOffset.get_segment_multi_translation(
            segment_moved, shank_diameter, thigh_diameter)
        offset_combo_list = multi_offset.get_combos()
        offset_combo_len = len(offset_combo_list)
        all_offsets_df = multi_offset.get_offset_df()
        for speed in SPEEDS:
            test_speed_data = test_sub_data[test_sub_data['speed'] == float(
                speed)]
            height = test_speed_data['height'].as_matrix()[0]
            x_test = test_speed_data[input_names]
            y_test = test_speed_data[output_names].as_matrix()
            R2 = np.zeros([offset_combo_len, len(output_names)])
            RMSEs = np.zeros([offset_combo_len, len(output_names)])
            NRMSEs = np.zeros([offset_combo_len, len(output_names)])
            my_xy_generator = XYGeneratorUni(subject_data, speed, output_names,
                                             input_names)
            for i_combo in range(len(offset_combo_list)):
                x_test_modified = my_xy_generator.modify_x_segment(
                    x_test, offset_combo_list[i_combo], height)
                y_pred = my_evaluator.evaluate_sklearn(x_test_modified, y_test)
                R2[i_combo, :], RMSEs[i_combo, :], NRMSEs[
                    i_combo, :] = my_evaluator.get_all_scores(y_test, y_pred)
            evaluation_result = np.column_stack([R2, RMSEs, NRMSEs])
            scores_df = pd.DataFrame(evaluation_result, columns=result_column)
            scores_df = scores_df.reset_index(drop=True)
            speed_df = pd.concat([all_offsets_df, scores_df], axis=1)
            speed_df.insert(loc=0, column='segment', value=segment_moved)
            speed_df.insert(loc=0, column='speed', value=str(speed))
            speed_df.insert(loc=0, column='subject_id', value=i_sub)
            total_sub_df = pd.concat([total_sub_df, speed_df], axis=0)

    end_time = datetime.now()
    print('Subject ' + str(i_sub) + ', finished at ' +
          end_time.strftime('%H:%M:%S'))
    return total_sub_df
Exemplo n.º 2
0
def get_all_rotation_result(input_names,
                            output_names,
                            result_column,
                            i_sub,
                            model_name,
                            error_value=25):
    start_time = datetime.now()
    print('Subject ' + str(i_sub) + ', start at ' +
          start_time.strftime('%H:%M:%S'))

    file_path = RESULT_PATH + 'evaluator\\' + model_name + '\\' + model_name + '_subject_' + str(
        i_sub) + '.pkl'
    with open(file_path, 'rb') as fp:
        my_evaluator = pickle.load(fp)

    all_sub_data = pd.read_csv(ALL_SUB_FILE, index_col=False)
    total_sub_df = pd.DataFrame()
    test_sub_data = all_sub_data[all_sub_data['subject_id'] == i_sub]
    del all_sub_data
    subject_data = SubjectData(PROCESSED_DATA_PATH, i_sub)
    segment_combo_class = RotationCombos(error_value=error_value)
    combos_list = segment_combo_class.get_segment_combos()
    combo_len = len(combos_list)
    all_offsets_df = segment_combo_class.get_offset_df()
    for speed in SPEEDS:
        test_speed_data = test_sub_data[test_sub_data['speed'] == float(speed)]
        x_test = test_speed_data[input_names]
        y_test = test_speed_data[output_names].as_matrix()
        height = test_speed_data['height'].as_matrix()[0]
        R2 = np.zeros([combo_len + 1, len(output_names)])
        RMSEs = np.zeros([combo_len + 1, len(output_names)])
        NRMSEs = np.zeros([combo_len + 1, len(output_names)])
        y_pred = my_evaluator.evaluate_sklearn(x_test, y_test)
        R2[0, :], RMSEs[0, :], NRMSEs[0, :] = my_evaluator.get_all_scores(
            y_test, y_pred)
        my_xy_generator = XYGeneratorUni(subject_data, speed, output_names,
                                         input_names)
        for i_combo in range(len(combos_list)):
            x_test_modified = my_xy_generator.modify_x_all_combined(
                x_test, combos_list[i_combo], height)
            y_pred = my_evaluator.evaluate_sklearn(x_test_modified, y_test)
            R2[i_combo +
               1, :], RMSEs[i_combo +
                            1, :], NRMSEs[i_combo +
                                          1, :] = my_evaluator.get_all_scores(
                                              y_test, y_pred)
        evaluation_result = np.column_stack([R2, RMSEs, NRMSEs])
        scores_df = pd.DataFrame(evaluation_result, columns=result_column)
        scores_df = scores_df.reset_index(drop=True)
        speed_df = pd.concat([all_offsets_df, scores_df], axis=1)
        speed_df.insert(loc=0, column='speed', value=str(speed))
        speed_df.insert(loc=0, column='subject_id', value=i_sub)
        total_sub_df = pd.concat([total_sub_df, speed_df], axis=0)

    end_time = datetime.now()
    print('Subject ' + str(i_sub) + ', finished at ' +
          end_time.strftime('%H:%M:%S'))
    return total_sub_df
Exemplo n.º 3
0
def get_segment_rotation_result(input_names, output_names, result_column,
                                i_sub, model_name):
    start_time = datetime.now()
    print('Subject ' + str(i_sub) + ', start at ' +
          start_time.strftime('%H:%M:%S'))

    file_path = RESULT_PATH + 'evaluator\\' + model_name + '\\' + model_name + '_subject_' + str(
        i_sub) + '.pkl'
    with open(file_path, 'rb') as fp:
        my_evaluator = pickle.load(fp)
    all_sub_data = pd.read_csv(ALL_SUB_FILE, index_col=False)
    total_sub_df = pd.DataFrame()
    test_sub_data = all_sub_data[all_sub_data['subject_id'] == i_sub]
    del all_sub_data

    subject_data = SubjectData(PROCESSED_DATA_PATH, i_sub)
    for segment_moved in SEGMENT_NAMES:
        if i_sub == 0:  # for test
            print('subject 0, ' + segment_moved)
        rotation_offsets = OneAxisRotation.get_one_axis_rotation(segment_moved)
        all_offsets_df = rotation_offsets.get_offset_df()
        rotation_len = len(rotation_offsets)

        for speed in SPEEDS:
            test_speed_data = test_sub_data[test_sub_data['speed'] == float(
                speed)]
            height = test_speed_data['height'].as_matrix()[0]
            x_test = test_speed_data[input_names]
            y_test = test_speed_data[output_names].as_matrix()
            R2 = np.zeros([rotation_len, len(output_names)])
            RMSEs = np.zeros([rotation_len, len(output_names)])
            NRMSEs = np.zeros([rotation_len, len(output_names)])
            my_xy_generator = XYGeneratorUni(subject_data, speed, output_names,
                                             input_names)
            for i_rotation in range(rotation_len):
                x_test_modified = my_xy_generator.modify_x_segment(
                    x_test, rotation_offsets[i_rotation], height)
                y_pred = my_evaluator.evaluate_sklearn(x_test_modified, y_test)
                R2[i_rotation, :], RMSEs[i_rotation, :], NRMSEs[
                    i_rotation, :] = my_evaluator.get_all_scores(
                        y_test, y_pred)
            evaluation_result = np.column_stack([R2, RMSEs, NRMSEs])
            scores_df = pd.DataFrame(evaluation_result, columns=result_column)
            scores_df = scores_df.reset_index(drop=True)
            speed_df = pd.concat([all_offsets_df, scores_df], axis=1)
            speed_df.insert(loc=0, column='segment', value=segment_moved)
            speed_df.insert(loc=0, column='speed', value=str(speed))
            speed_df.insert(loc=0, column='subject_id', value=i_sub)
            total_sub_df = pd.concat([total_sub_df, speed_df], axis=0)

    end_time = datetime.now()
    print('Subject ' + str(i_sub) + ', finished at ' +
          end_time.strftime('%H:%M:%S'))
    return total_sub_df
# # for test
# SUB_NUM = 2

X_NORM_ALL = True  # if true, normalize along all the subjects, if false, normalize each subject independently
Y_NORM = False  # if true, normalize along all the subjects, if false, do not do normalize

for X_NORM_ALL in [False]:
    for Y_NORM in [True]:
        print('X_NORM_ALL: ' + str(X_NORM_ALL) + '\tY_NORM: ' + str(Y_NORM))
        x, y = {}, {}
        for i_sub in range(SUB_NUM):
            subject_data = SubjectData(PROCESSED_DATA_PATH, i_sub)
            x_sub, y_sub = {}, {}
            for speed in SPEEDS:
                my_xy_generator = XYGeneratorUni(subject_data,
                                                 SEGMENT_NAMES[0], speed,
                                                 output_names, input_names)
                x_trial, y_trial = my_xy_generator.get_xy()
                x_sub[speed] = x_trial.as_matrix()
                y_sub[speed] = y_trial.as_matrix()
            if not X_NORM_ALL:
                x_scalar.fit(
                    np.row_stack(
                        [x_sub[SPEEDS[0]], x_sub[SPEEDS[1]],
                         x_sub[SPEEDS[2]]]))
                for speed in SPEEDS:
                    x_sub[speed] = x_scalar.transform(x_sub[speed])
            x[i_sub] = x_sub
            y[i_sub] = y_sub

        for i_sub_test in range(1):
Exemplo n.º 5
0
    my_evaluator.train_sklearn()  # very time consuming

    for speed in SPEEDS:
        test_sub_data = all_sub_data[all_sub_data['subject_id'] == i_sub_test]
        test_speed_data = test_sub_data[test_sub_data['speed'] == float(speed)]
        height = test_speed_data['height'].as_matrix()[0]
        x_test = test_speed_data[input_names]
        y_test = test_speed_data[output_names]
        my_evaluator.set_x_test(x_test)
        my_evaluator.set_y_test(y_test)
        my_evaluator.evaluate_sklearn()
        scores = np.zeros([combo_len, len(output_names)])
        RMSEs = np.zeros([combo_len, len(output_names)])
        NRMSEs = np.zeros([combo_len, len(output_names)])
        my_xy_generator = XYGeneratorUni(subject_data, speed, output_names,
                                         input_names)
        for i_combo in range(len(combos_list)):
            x_test_modified = my_xy_generator.modify_x_all_combined(
                x_test, combos_list[i_combo], height)
            my_evaluator.set_x_test(x_test_modified)
            my_evaluator.evaluate_sklearn()
            scores[i_combo, :] = my_evaluator.get_scores()
            RMSEs[i_combo, :] = my_evaluator.get_RMSE()
            NRMSEs[i_combo, :] = my_evaluator.get_NRMSE()
        evaluation_result = np.column_stack([scores, RMSEs, NRMSEs])
        scores_df = pd.DataFrame(evaluation_result, columns=result_column)
        scores_df = scores_df.reset_index(drop=True)
        speed_df = pd.concat([all_offsets_df, scores_df], axis=1)
        speed_df.insert(loc=0, column='speed', value=str(speed))
        speed_df.insert(loc=0, column='subject_id', value=i_sub_test)
        total_result_df = pd.concat([total_result_df, speed_df], axis=0)
Exemplo n.º 6
0
                                                        test_size=0.3,
                                                        random_state=2)
    test_index = x_test.index
    my_evaluator = CrossValidation(output_names, model, n_fold=3)
    my_evaluator.set_train(x_train, y_train)
    my_evaluator.set_y_test(y_test)

    my_evaluator.train_sklearn()  # very time consuming

    scores = np.zeros([combo_len, len(output_names)])
    for i_combo in range(len(offset_list)):
        x_modified = np.zeros([0, len(input_names)])
        for speed in SPEEDS:
            speed_df = sub_data_df[sub_data_df['speed'] == float(speed)]
            x_speed = speed_df[input_names]
            my_xy_generator = XYGeneratorUni(subject_data, speed, output_names,
                                             input_names)
            x_modified_speed = my_xy_generator.modify_x_all_combined(
                x_speed, offset_list[i_combo])
            x_modified = np.row_stack([x_modified, x_modified_speed])
        x_test_modified = pd.DataFrame(x_modified).loc[test_index]
        my_evaluator.set_x_test(x_test_modified)
        y_pred = my_evaluator.evaluate_sklearn()
        scores[i_combo, :] = my_evaluator.get_scores()

    scores_df = pd.DataFrame(scores, columns=output_names)
    scores_df = scores_df.reset_index(drop=True)
    subject_df = pd.concat([all_offsets_df, scores_df], axis=1)
    subject_df.insert(loc=0, column='subject_id', value=i_sub)
    total_result_df = pd.concat([total_result_df, subject_df], axis=0)

EvaluationUni.save_result(total_result_df, model, input_names, output_names,
Exemplo n.º 7
0
def get_segment_translation_result(input_names, output_names, result_column,
                                   i_sub, model_names):
    print('one trans')
    start_time = datetime.now()
    print('Subject ' + str(i_sub) + ', start at ' +
          start_time.strftime('%H:%M:%S'))

    my_evaluators = []
    for model_name in model_names:
        file_path = RESULT_PATH + 'evaluator\\' + model_name + '\\' + model_name + '_subject_' + str(
            i_sub) + '.pkl'
        with open(file_path, 'rb') as fp:
            my_evaluators.append(pickle.load(fp))

    all_sub_data = pd.read_csv(ALL_SUB_FILE, index_col=False)
    total_sub_df = pd.DataFrame()
    test_sub_data = all_sub_data[all_sub_data['subject_id'] == i_sub]
    del all_sub_data

    subject_data = SubjectData(PROCESSED_DATA_PATH, i_sub)
    # the range have to be defined after subject data to get the diameter
    shank_diameter = SubjectData.get_cylinder_diameter(test_sub_data,
                                                       'l_shank')
    thigh_diameter = SubjectData.get_cylinder_diameter(test_sub_data,
                                                       'l_thigh')
    for segment_moved in SEGMENT_NAMES:
        # if i_sub == 0:  # for test
        # print('subject 0, ' + segment_moved)
        multi_offset = MultiAxisOffset.get_segment_multi_translation(
            segment_moved, shank_diameter, thigh_diameter)
        offset_combo_list = multi_offset.get_combos()
        offset_combo_len = len(offset_combo_list)
        all_offsets_df = multi_offset.get_offset_df()
        for speed in SPEEDS:
            test_speed_data = test_sub_data[test_sub_data['speed'] == float(
                speed)]
            height = test_speed_data['height'].as_matrix()[0]
            x_test = test_speed_data[input_names]
            y_test = test_speed_data[output_names].as_matrix()
            R2 = np.zeros(
                [offset_combo_len,
                 len(output_names) * len(my_evaluators)])
            RMSEs = np.zeros(
                [offset_combo_len,
                 len(output_names) * len(my_evaluators)])
            NRMSEs = np.zeros(
                [offset_combo_len,
                 len(output_names) * len(my_evaluators)])
            my_xy_generator = XYGeneratorUni(subject_data, speed, output_names,
                                             input_names)
            for i_combo in range(len(offset_combo_list)):
                x_test_modified = my_xy_generator.modify_x_segment(
                    x_test, offset_combo_list[i_combo], height)
                for i_eval in range(len(my_evaluators)):
                    y_pred = my_evaluators[i_eval].evaluate_sklearn(
                        x_test_modified, y_test)
                    R2[i_combo, i_eval*len(output_names):(i_eval+1)*len(output_names)], \
                        RMSEs[i_combo, i_eval*len(output_names):(i_eval+1)*len(output_names)],\
                        NRMSEs[i_combo, i_eval*len(output_names):(i_eval+1)*len(output_names)] =\
                        my_evaluators[i_eval].get_all_scores(y_test, y_pred)
            evaluation_result = np.column_stack([R2, RMSEs, NRMSEs])
            scores_df = pd.DataFrame(evaluation_result, columns=result_column)
            scores_df = scores_df.reset_index(drop=True)
            speed_df = pd.concat([all_offsets_df, scores_df], axis=1)
            speed_df.insert(loc=0, column='segment', value=segment_moved)
            speed_df.insert(loc=0, column='speed', value=str(speed))
            speed_df.insert(loc=0, column='subject_id', value=i_sub)
            speed_df.insert(loc=0, column='experiment', value='one_trans')
            total_sub_df = pd.concat([total_sub_df, speed_df], axis=0)

    end_time = datetime.now()
    print('Subject ' + str(i_sub) + ', finished at ' +
          end_time.strftime('%H:%M:%S'))
    return total_sub_df
Exemplo n.º 8
0
def get_all_trans_rota(input_names,
                       output_names,
                       result_column,
                       i_sub,
                       model_names,
                       rotation_value=25):
    print('all trans rota')
    start_time = datetime.now()
    print('Subject ' + str(i_sub) + ', start at ' +
          start_time.strftime('%H:%M:%S'))

    my_evaluators = []
    for model_name in model_names:
        file_path = RESULT_PATH + 'evaluator\\' + model_name + '\\' + model_name + '_subject_' + str(
            i_sub) + '.pkl'
        with open(file_path, 'rb') as fp:
            my_evaluators.append(pickle.load(fp))

    all_sub_data = pd.read_csv(ALL_SUB_FILE, index_col=False)
    total_sub_df = pd.DataFrame()
    test_sub_data = all_sub_data[all_sub_data['subject_id'] == i_sub]
    del all_sub_data
    subject_data = SubjectData(PROCESSED_DATA_PATH, i_sub)
    thigh_diameter = SubjectData.get_cylinder_diameter(test_sub_data,
                                                       'l_thigh')
    shank_diameter = SubjectData.get_cylinder_diameter(test_sub_data,
                                                       'l_shank')
    combo_value = np.array([[100, 100], [100, 100], [25, 100], [25, 100],
                            [25, 100], [25, 100], [50, 50], [50, 50]])
    segment_combo_class = TransRotaCombos(combo_value,
                                          thigh_diameter,
                                          shank_diameter,
                                          rotation_value=rotation_value)
    combos_list = segment_combo_class.get_segment_combos()
    combo_len = len(combos_list)
    all_offsets_df = segment_combo_class.get_offset_df()
    for speed in SPEEDS:
        test_speed_data = test_sub_data[test_sub_data['speed'] == float(speed)]
        x_test = test_speed_data[input_names]
        y_test = test_speed_data[output_names].as_matrix()
        height = test_speed_data['height'].as_matrix()[0]
        R2 = np.zeros([combo_len + 1, len(output_names) * len(my_evaluators)])
        RMSEs = np.zeros(
            [combo_len + 1,
             len(output_names) * len(my_evaluators)])
        NRMSEs = np.zeros(
            [combo_len + 1,
             len(output_names) * len(my_evaluators)])
        # get the first data (no placement error)
        for i_eval in range(len(my_evaluators)):
            y_pred = my_evaluators[i_eval].evaluate_sklearn(x_test, y_test)
            R2[0, i_eval * len(output_names):(i_eval + 1) * len(output_names)], \
                RMSEs[0, i_eval * len(output_names):(i_eval + 1) * len(output_names)], \
                NRMSEs[0, i_eval * len(output_names):(i_eval + 1) * len(output_names)] = \
                my_evaluators[i_eval].get_all_scores(y_test, y_pred)
        my_xy_generator = XYGeneratorUni(subject_data, speed, output_names,
                                         input_names)
        for i_combo in range(len(combos_list)):
            x_test_modified = my_xy_generator.modify_x_all_combined(
                x_test, combos_list[i_combo], height)
            # get all other data
            for i_eval in range(len(my_evaluators)):
                y_pred = my_evaluators[i_eval].evaluate_sklearn(
                    x_test_modified, y_test)
                R2[i_combo + 1, i_eval * len(output_names):(i_eval + 1) * len(output_names)], \
                    RMSEs[i_combo + 1, i_eval * len(output_names):(i_eval + 1) * len(output_names)], \
                    NRMSEs[i_combo + 1, i_eval * len(output_names):(i_eval + 1) * len(output_names)] = \
                    my_evaluators[i_eval].get_all_scores(y_test, y_pred)
        evaluation_result = np.column_stack([R2, RMSEs, NRMSEs])
        scores_df = pd.DataFrame(evaluation_result, columns=result_column)
        scores_df = scores_df.reset_index(drop=True)
        speed_df = pd.concat([all_offsets_df, scores_df], axis=1)
        speed_df.insert(loc=0, column='speed', value=str(speed))
        speed_df.insert(loc=0, column='subject_id', value=i_sub)
        speed_df.insert(loc=0, column='experiment', value='all_trans_rota')
        total_sub_df = pd.concat([total_sub_df, speed_df], axis=0)

    end_time = datetime.now()
    print('Subject ' + str(i_sub) + ', finished at ' +
          end_time.strftime('%H:%M:%S'))
    return total_sub_df
def get_combined_result_df(input_names, output_names, result_column,
                           base_model, i_sub):
    start_time = datetime.now()
    print('Subject ' + str(i_sub) + ', start at ' +
          start_time.strftime('%H:%M:%S'))

    all_sub_data = pd.read_csv(ALL_SUB_FILE, index_col=False)
    other_sub_data = all_sub_data[all_sub_data['subject_id'] != i_sub]
    x_train = other_sub_data[input_names]
    y_train = other_sub_data[output_names]
    my_evaluator = Evaluation(output_names, base_model)
    my_evaluator.train_sklearn(x_train, y_train)  # very time consuming

    total_sub_df = pd.DataFrame()
    test_sub_data = all_sub_data[all_sub_data['subject_id'] == i_sub]
    del all_sub_data
    subject_data = SubjectData(PROCESSED_DATA_PATH, i_sub)
    # the range have to be defined after subject data to get the diameter
    thigh_diameter = SubjectData.get_cylinder_diameter(test_sub_data,
                                                       'l_thigh')
    shank_diameter = SubjectData.get_cylinder_diameter(test_sub_data,
                                                       'l_shank')
    combo_value = np.array([[100, 100], [100, 100], [25, 100], [25, 100],
                            [25, 100], [25, 100], [50, 50], [50, 50]])
    segment_combo_class = TranslationCombos(combo_value, thigh_diameter,
                                            shank_diameter)
    combos_list = segment_combo_class.get_segment_combos()
    combo_len = len(combos_list)
    all_offsets_df = segment_combo_class.get_offset_df()
    for speed in SPEEDS:
        test_speed_data = test_sub_data[test_sub_data['speed'] == float(speed)]
        x_test = test_speed_data[input_names]
        y_test = test_speed_data[output_names].as_matrix()
        height = test_speed_data['height'].as_matrix()[0]
        R2 = np.zeros([combo_len + 1, len(output_names)])
        RMSEs = np.zeros([combo_len + 1, len(output_names)])
        NRMSEs = np.zeros([combo_len + 1, len(output_names)])
        y_pred = my_evaluator.evaluate_sklearn(x_test, y_test)
        R2[0, :], RMSEs[0, :], NRMSEs[0, :] = my_evaluator.get_all_scores(
            y_test, y_pred)
        my_xy_generator = XYGeneratorUni(subject_data, speed, output_names,
                                         input_names)
        for i_combo in range(len(combos_list)):
            x_test_modified = my_xy_generator.modify_x_all_combined(
                x_test, combos_list[i_combo], height)
            y_pred = my_evaluator.evaluate_sklearn(x_test_modified, y_test)
            R2[i_combo +
               1, :], RMSEs[i_combo +
                            1, :], NRMSEs[i_combo +
                                          1, :] = my_evaluator.get_all_scores(
                                              y_test, y_pred)
        evaluation_result = np.column_stack([R2, RMSEs, NRMSEs])
        scores_df = pd.DataFrame(evaluation_result, columns=result_column)
        scores_df = scores_df.reset_index(drop=True)
        speed_df = pd.concat([all_offsets_df, scores_df], axis=1)
        speed_df.insert(loc=0, column='speed', value=str(speed))
        speed_df.insert(loc=0, column='subject_id', value=i_sub)
        total_sub_df = pd.concat([total_sub_df, speed_df], axis=0)

    end_time = datetime.now()
    print('Subject ' + str(i_sub) + ', finished at ' +
          end_time.strftime('%H:%M:%S'))
    return total_sub_df