コード例 #1
0
def pca_classification(physiological_data, labels, classes):
    ppg_data = physiological_data[:, :, :]
    print(physiological_data.shape, labels.shape, ppg_data.shape)
    ppg_train, ppg_test, \
        y_train, y_test = \
        normal_train_test_split(ppg_data, labels)

    scaler = StandardScaler()

    # Fit on training set only.
    scaler.fit(ppg_train
               )  # Apply transform to both the training set and the test set.
    ppg_train = scaler.transform(ppg_train)
    ppg_test = scaler.transform(ppg_test)

    # Make an instance of the Model
    pca = PCA(.95)
    pca.fit(ppg_train)
    ppg_train = pca.transform(ppg_train)
    ppg_test = pca.transform(ppg_test)

    preds_ppg = \
        physiological_classification(ppg_train, ppg_test, y_train, y_test, classes)
    print("ppg ppg ppg")
    ppg_result = validate_predictions(preds_ppg, y_test, classes)
    print(ppg_result)
コード例 #2
0
def cnn_lstm_classification(physiological_data, labels, classes):
    print(physiological_data.shape)
    print(labels.shape)
    train_x, test_x, \
        train_y, test_y = \
        normal_train_test_split(physiological_data, labels)
    preds_physiological = cnn_lstm(train_x, test_x, train_y, test_y)
    print(validate_predictions(preds_physiological, test_y, classes))
コード例 #3
0
def cnn_lstm_classification(physiological_data, labels, classes):
    print(physiological_data.shape)
    print(labels.shape)
    # train_x, test_x, train_y, test_y = \
    #    normal_train_test_split(physiological_data, labels)
    # train_x, test_x, train_y, test_y = \
    #    leave_one_subject_out_split(physiological_data, labels, subject_out=0)

    train_x, test_x, train_y, test_y = \
        leave_one_trial_out_split(physiological_data, labels, trial_out=0)
    preds_physiological = cnn_lstm(train_x, test_x, train_y, test_y)
    print(validate_predictions(preds_physiological, test_y, classes))
コード例 #4
0
def lstm_classification(physiological_data,
                        labels,
                        part_seconds,
                        classes,
                        sampling_rate=128):
    '''
    Classify data using lstm method
    '''

    participants, trials = np.array(labels).shape
    all_physiological_features = []
    print(physiological_data.shape)
    participants, trials, points = physiological_data.shape
    part_length = part_seconds * sampling_rate
    part_count = int(points / part_length)
    all_participants_labels = []
    for p in range(participants):
        all_trials_physiological = []
        all_trial_labels = []
        for t in range(trials):
            physiological_parts = []
            for i in range(part_count):
                ppg_data = \
                    physiological_data[p,
                                       t,
                                       i * part_length:(i+1)*part_length]
                ppg_labels = labels[p, t]

                physiological_parts.append(get_ppg_features(ppg_data))
            all_trial_labels.append(ppg_labels)
            all_trials_physiological.append(physiological_parts)
        all_participants_labels.append(all_trial_labels)
        all_physiological_features.append(all_trials_physiological)
    physiological_data = np.array(all_physiological_features)
    all_participants_labels = np.array(all_participants_labels)

    physiological_train, physiological_test, \
        y_train, y_test = \
        normal_train_test_split(physiological_data, all_participants_labels)

    #physiological_train, physiological_test, \
    #   y_train, y_test = \
    #    leave_one_trial_out_split(physiological_data,
    #                              np.array(all_participants_labels), trial_out=0)

    preds_physiological = \
        physiological_lstm_classifier(physiological_train, physiological_test,
                                      y_train, y_test, classes)
    print(validate_predictions(preds_physiological, y_test, classes))
コード例 #5
0
def feature_classification(physiological_data,
                           labels,
                           part_seconds,
                           classes,
                           sampling_rate=128):

    # physiological_data, labels = \
    #    prepare_experimental_data(classes, label_type, sampling_rate, ignore_time)
    participants, trials = np.array(labels).shape
    participants, trials, points = physiological_data.shape
    all_physiological_features = []
    part_length = part_seconds * sampling_rate
    part_count = int(points / part_length)
    all_participants_labels = []
    for p in range(participants):
        all_trials_physiological = []
        all_trial_labels = []
        for t in range(trials):
            physiological_parts = []
            all_parts_labels = []
            for i in range(part_count):
                physiological_parts.append(
                    get_gsr_features(
                        physiological_data[p, t, i * part_length:(i + 1) *
                                           part_length]))
                all_parts_labels.append(labels[p, t])
            all_trial_labels.append(all_parts_labels)
            all_trials_physiological.append(physiological_parts)
        all_participants_labels.append(all_trial_labels)
        all_physiological_features.append(all_trials_physiological)
    physiological_data = np.array(all_physiological_features)
    all_participants_labels = np.array(all_participants_labels)

    physiological_train, physiological_test, \
        y_train, y_test = \
        leave_one_subject_out_split(physiological_data, all_participants_labels)

    #physiological_train, physiological_test, \
    #    y_train, y_test = \
    #    leave_one_trial_out_split(physiological_data,
    #                              np.array(all_participants_labels), trial_out=0)

    preds_physiological = \
        physiological_classification(
            physiological_train, physiological_test, y_train, y_test, classes)
    print(validate_predictions(preds_physiological, y_test, classes))