classifiers/resting_tremor_classifier.py
def build_rest_tremor_classification_feature_set(raw_accelerometer_data_df, fs):
    '''
    Pre-process raw accelerometer data and compute signal based features on pre-processed signal data.

    :param raw_accelerometer_data_df: Pandas DataFrame of raw accelerometer data. Columns = ['ts','x','y','z']
    :param fs: Sampling rate of raw accelerometer data (float)
    :return: Pandas DataFrame of calculated features in 3 second windows.
    '''
    # Initialize final DataFrame
    final_feature_set = pd.DataFrame()

    # Pre-process data
    # Bandpass filter between 3.5-7.5 hz
    filtered_data_df = preprocess.band_pass_filter(raw_accelerometer_data_df, fs, [3.5, 7.5],
                                                             1, channels=['x', 'y', 'z'])
    bp1_headers = ['x_bp_filt_[3.5, 7.5]', 'y_bp_filt_[3.5, 7.5]', 'z_bp_filt_[3.5, 7.5]']

    # Bandpass filter between 0.25-3.5 hz
    filtered_data_df = preprocess.band_pass_filter(filtered_data_df, fs, [0.25, 3.5],
                                                             1, channels=['x', 'y', 'z'])
    bp2_headers = ['x_bp_filt_[0.25, 3.5]', 'y_bp_filt_[0.25, 3.5]', 'z_bp_filt_[0.25, 3.5]']

    # Perform PCA get 1st principal component for [3.5 - 7.5] bandpass filtered data
    filtered_data_df = preprocess.get_principal_component(filtered_data_df, channels=bp1_headers)
    filtered_data_df.rename(columns={'PC1': 'PC1_[3.5, 7.5]'}, inplace=True)
    pca1_headers = ['PC1_[3.5, 7.5]']

    # Perform PCA get 1st principal component for [0.25 - 3.5] bandpass filtered data
    filtered_data_df = preprocess.get_principal_component(filtered_data_df, channels=bp2_headers)
    filtered_data_df.rename(columns={'PC1': 'PC1_[0.25, 3.5]'}, inplace=True)
    pca2_headers = ['PC1_[0.25, 3.5]']

    # Obtain all data channels of interest
    total_data_channels = bp1_headers + bp2_headers + pca1_headers + pca2_headers

    # Segment into 3 second windows
    total_samples = filtered_data_df.shape[0]
    window_samples = fs * 3.0
    total_windows = round(total_samples / float(window_samples))
    for win in range(int(total_windows)):
        current_win_start = int(window_samples * win + 1)
        current_win_end = int(current_win_start + window_samples - 1)
        if current_win_end > filtered_data_df.shape[0]:
            window_data_df = filtered_data_df.loc[current_win_start:, :]
        else:
            window_data_df = filtered_data_df.loc[current_win_start:current_win_end, :]
        window_data_df.reset_index(drop=True, inplace=True)

        # Create DataFrame for current window of data
        current_features_df = pd.DataFrame()
        # Extract signal features for tremor detection
        current_features_df = extract_tremor_classification_features(window_data_df, current_features_df, total_data_channels, fs)
        # Aggregate features for each window
        final_feature_set = final_feature_set.append(current_features_df, ignore_index=True)

    return final_feature_set

    Pre-process raw accelerometer data and compute signal based features on pre-processed signal data.

    :param raw_accelerometer_data_df: Pandas DataFrame of raw accelerometer data. Columns = ['ts','x','y','z']
    :param fs: Sampling rate of raw accelerometer data (float)
    :return: Pandas DataFrame of calculated features in 3 second windows.
    
Pre-process raw accelerometer data and compute signal based features on pre-processed signal data.
Pre - process raw accelerometer data and compute signal based features on pre - processed signal data .
def build_rest_tremor_classification_feature_set(raw_accelerometer_data_df, fs):
    final_feature_set = pd.DataFrame()
    filtered_data_df = preprocess.band_pass_filter(raw_accelerometer_data_df, fs, [3.5, 7.5],
                                                             1, channels=['x', 'y', 'z'])
    bp1_headers = ['x_bp_filt_[3.5, 7.5]', 'y_bp_filt_[3.5, 7.5]', 'z_bp_filt_[3.5, 7.5]']
    filtered_data_df = preprocess.band_pass_filter(filtered_data_df, fs, [0.25, 3.5],
                                                             1, channels=['x', 'y', 'z'])
    bp2_headers = ['x_bp_filt_[0.25, 3.5]', 'y_bp_filt_[0.25, 3.5]', 'z_bp_filt_[0.25, 3.5]']
    filtered_data_df = preprocess.get_principal_component(filtered_data_df, channels=bp1_headers)
    filtered_data_df.rename(columns={'PC1': 'PC1_[3.5, 7.5]'}, inplace=True)
    pca1_headers = ['PC1_[3.5, 7.5]']
    filtered_data_df = preprocess.get_principal_component(filtered_data_df, channels=bp2_headers)
    filtered_data_df.rename(columns={'PC1': 'PC1_[0.25, 3.5]'}, inplace=True)
    pca2_headers = ['PC1_[0.25, 3.5]']
    total_data_channels = bp1_headers + bp2_headers + pca1_headers + pca2_headers
    total_samples = filtered_data_df.shape[0]
    window_samples = fs * 3.0
    total_windows = round(total_samples / float(window_samples))
    for win in range(int(total_windows)):
        current_win_start = int(window_samples * win + 1)
        current_win_end = int(current_win_start + window_samples - 1)
        if current_win_end > filtered_data_df.shape[0]:
            window_data_df = filtered_data_df.loc[current_win_start:, :]
        else:
            window_data_df = filtered_data_df.loc[current_win_start:current_win_end, :]
        window_data_df.reset_index(drop=True, inplace=True)
        current_features_df = pd.DataFrame()
        current_features_df = extract_tremor_classification_features(window_data_df, current_features_df, total_data_channels, fs)
        final_feature_set = final_feature_set.append(current_features_df, ignore_index=True)
    return final_feature_set
def build_rest_tremor_classification_feature_set ( raw_accelerometer_data_df , fs ) : final_feature_set = pd . DataFrame ( ) filtered_data_df = preprocess . band_pass_filter ( raw_accelerometer_data_df , fs , [ 3.5 , 7.5 ] , 1 , channels = [ 'x' , 'y' , 'z' ] ) bp1_headers = [ 'x_bp_filt_[3.5, 7.5]' , 'y_bp_filt_[3.5, 7.5]' , 'z_bp_filt_[3.5, 7.5]' ] filtered_data_df = preprocess . band_pass_filter ( filtered_data_df , fs , [ 0.25 , 3.5 ] , 1 , channels = [ 'x' , 'y' , 'z' ] ) bp2_headers = [ 'x_bp_filt_[0.25, 3.5]' , 'y_bp_filt_[0.25, 3.5]' , 'z_bp_filt_[0.25, 3.5]' ] filtered_data_df = preprocess . get_principal_component ( filtered_data_df , channels = bp1_headers ) filtered_data_df . rename ( columns = { 'PC1' : 'PC1_[3.5, 7.5]' } , inplace = True ) pca1_headers = [ 'PC1_[3.5, 7.5]' ] filtered_data_df = preprocess . get_principal_component ( filtered_data_df , channels = bp2_headers ) filtered_data_df . rename ( columns = { 'PC1' : 'PC1_[0.25, 3.5]' } , inplace = True ) pca2_headers = [ 'PC1_[0.25, 3.5]' ] total_data_channels = bp1_headers + bp2_headers + pca1_headers + pca2_headers total_samples = filtered_data_df . shape [ 0 ] window_samples = fs * 3.0 total_windows = round ( total_samples / float ( window_samples ) ) for win in range ( int ( total_windows ) ) : current_win_start = int ( window_samples * win + 1 ) current_win_end = int ( current_win_start + window_samples - 1 ) if current_win_end > filtered_data_df . shape [ 0 ] : window_data_df = filtered_data_df . loc [ current_win_start : , : ] else : window_data_df = filtered_data_df . loc [ current_win_start : current_win_end , : ] window_data_df . reset_index ( drop = True , inplace = True ) current_features_df = pd . DataFrame ( ) current_features_df = extract_tremor_classification_features ( window_data_df , current_features_df , total_data_channels , fs ) final_feature_set = final_feature_set . append ( current_features_df , ignore_index = True ) return final_feature_set
Pre-process raw accelerometer data and compute signal based features on pre-processed signal data.
Pre - process raw accelerometer data and compute signal based features on pre - processed signal data .
'''
    Pre-process raw accelerometer data and compute signal based features on pre-processed signal data.

    :param raw_accelerometer_data_df: Pandas DataFrame of raw accelerometer data. Columns = ['ts','x','y','z']
    :param fs: Sampling rate of raw accelerometer data (float)
    :return: Pandas DataFrame of calculated features in 3 second windows.
    ''' # Initialize final DataFrame # Pre-process data # Bandpass filter between 3.5-7.5 hz # Bandpass filter between 0.25-3.5 hz # Perform PCA get 1st principal component for [3.5 - 7.5] bandpass filtered data # Perform PCA get 1st principal component for [0.25 - 3.5] bandpass filtered data # Obtain all data channels of interest # Segment into 3 second windows # Create DataFrame for current window of data # Extract signal features for tremor detection # Aggregate features for each window
Pandas DataFrame of calculated features in 3 second windows.
Pandas DataFrame of calculated features in 3 second windows .
raw_accelerometer_data_df
Pandas DataFrame of raw accelerometer data.
Pandas DataFrame of raw accelerometer data .
fs
Sampling rate of raw accelerometer data (float)
Sampling rate of raw accelerometer data ( float )