예제 #1
0
def classify_participant_independent(csv, trainingid, validationid, testingid, normalizer_type, normalizer1, normalizer2, totalDays):
    X_train = []
    Y_train = []

    X_val = []
    Y_val = []

    X_test = []
    Y_test = []

    for i in range(totalDays, len(csv)):
        days = data_collector.collectDayData(csv, i, totalDays)

        userid = days[0][1]

        if data_collector.isSameUserAcross(days):
            x = transform_to_train_vec.transform(
                days,
                False,
                "LSTM",
                totalDays,
                normalizer_type,
                normalizer1,
                normalizer2
            )

            # put the x vector into the appropriate set (i.e. training, validation, testing)
            if days[0][EMA_INDEX] != '':

                X_train, Y_train, X_val, Y_val, X_test, Y_test = assign_data.independent_assign(
                    True,
                    days[0][1],
                    trainingid,
                    validationid,
                    testingid,
                    X_train,
                    Y_train,
                    X_val,
                    Y_val,
                    X_test,
                    Y_test,
                    x,
                    days[0][EMA_INDEX]
                )

    model = Sequential()
    model.add(LSTM(64, return_sequences=True, input_shape=(totalDays, len(X_train[0][0]))))
    model.add(LSTM(64, return_sequences=True, recurrent_dropout=0.2))
    model.add(LSTM(64))

    model.add(Dense(4, activation='softmax', kernel_regularizer=L1L2(l1=0.0, l2=0.0)))
    model.compile(loss='categorical_crossentropy', optimizer='rmsprop', metrics=['categorical_accuracy'])

    if len(X_val) == 0:
        model.fit(X_train, Y_train, epochs=5)
    else:
        model.fit(X_train, Y_train, epochs=5,  validation_data=(X_val, Y_val))

    y_pred = model.predict(X_test)
    return prediction_utilities.convert_preds_into_ema(y_pred), Y_test
예제 #2
0
def regression_participant_independent(csv, trainingid, validationid, testingid, normalizerMethod, normalizer1, normalizer2, totalDays):
    X_train = []
    Y_train = []

    X_val = []
    Y_val = []

    X_test = []
    Y_test = []

    for i in range(totalDays, len(csv)):
        days = data_collector.collectDayData(csv, i, totalDays)

        if data_collector.isSameUserAcross(days):
            x = transform_to_train_vec.transform(
                days,
                False,
                "LSTM",
                totalDays,
                normalizerMethod,
                normalizer1,
                normalizer2
            )

            # put the x vector into the appropriate set (i.e. training, validation, testing)
            if days[0][EMA_INDEX] != '':
                X_train, Y_train, X_val, Y_val, X_test, Y_test = assign_data.independent_assign(
                    False,
                    days[0][1],
                    trainingid,
                    validationid,
                    testingid,
                    X_train,
                    Y_train,
                    X_val,
                    Y_val,
                    X_test,
                    Y_test,
                    x,
                    days[0][EMA_INDEX]
                )

    model = Sequential()
    model.add(LSTM(128, return_sequences=True, input_shape=(totalDays, len(X_train[0][0]))))
    model.add(LSTM(128, return_sequences=True, recurrent_dropout=0.2))
    model.add(LSTM(64))
    model.add(Dense(128, activation='tanh'))
    model.add(Dense(1, activation='softmax', kernel_regularizer=L1L2(l1=0.0, l2=0.0)))
    model.compile(loss='mean_squared_error', optimizer='adam', metrics=['acc'])

    if len(X_val) == 0:
        model.fit(X_train, Y_train, epochs=30)
    else:
        model.fit(X_train, Y_train, epochs=30,  validation_data=(X_val, Y_val))


    y_pred = model.predict(X_test)
    return y_pred, Y_test
예제 #3
0
def classification_participant_dependent(csv, normalizerMethod, normalizer1,
                                         normalizer2, totalDays,
                                         leave_one_patient):
    X_train = []
    Y_train = []

    X_val = []
    Y_val = []

    X_test = []
    Y_test = []

    for i in range(totalDays - 1, len(csv)):
        days = data_collector.collectDayData(csv, i, totalDays)
        userid = days[0][1]

        if data_collector.isSameUserAcross(days):
            x = transform_to_train_vec.transform(days, True, "simpleNN",
                                                 totalDays, "z-score",
                                                 normalizer1, normalizer2)

            if days[0][EMA_INDEX] != '':
                X_train, Y_train, X_val, Y_val, X_test, Y_test = assign_data.dependent_assign(
                    True, 0.60, 0.75, X_train, Y_train, X_val, Y_val, X_test,
                    Y_test, x, days[0][EMA_INDEX], leave_one_patient, userid)

    model = Sequential()
    model.add(Dense(1024, input_dim=len(X_train[0]), activation='relu'))
    model.add(Dense(512, activation='relu'))
    model.add(Dense(512, activation='relu'))
    model.add(Dense(32, activation='relu'))
    #model.add(Dropout(0.4))

    model.add(
        Dense(4,
              activation='softmax',
              kernel_regularizer=L1L2(l1=0.0, l2=0.25)))

    model.compile(optimizer='rmsprop',
                  loss='categorical_crossentropy',
                  metrics=['categorical_accuracy'])

    if len(X_val) == 0:
        model.fit(X_train, Y_train, epochs=4)
    else:
        model.fit(X_train, Y_train, epochs=4, validation_data=(X_val, Y_val))

    y_pred = model.predict(X_test)
    return prediction_utilities.convert_preds_into_ema(y_pred), Y_test
예제 #4
0
def classification_participant_independent(csv, trainingid, validationid,
                                           testingid, normalizerMethod,
                                           normalizer1, normalizer2,
                                           totalDays):
    X_train = []
    Y_train = []

    X_val = []
    Y_val = []

    X_test = []
    Y_test = []

    for i in range(totalDays - 1, len(csv)):
        days = data_collector.collectDayData(csv, i, totalDays)

        if data_collector.isSameUserAcross(days):
            x = transform_to_train_vec.transform(days, True, "simpleNN",
                                                 totalDays, "z-score",
                                                 normalizer1, normalizer2)

            # put the x vector into the appropriate set (i.e. training, validation, testing)
            if days[0][EMA_INDEX] != '':
                X_train, Y_train, X_val, Y_val, X_test, Y_test = assign_data.independent_assign(
                    True, days[0][1], trainingid, validationid, testingid,
                    X_train, Y_train, X_val, Y_val, X_test, Y_test, x,
                    days[0][EMA_INDEX])

    model = Sequential()
    model.add(Dense(1024, input_dim=len(X_train[0]), activation='relu'))
    model.add(Dense(256, activation='relu'))

    model.add(
        Dense(4,
              activation='softmax',
              kernel_regularizer=L1L2(l1=0.0, l2=0.15)))

    model.compile(optimizer='rmsprop',
                  loss='categorical_crossentropy',
                  metrics=['accuracy'])
    model.fit(X_train, Y_train, epochs=30, validation_data=(X_val, Y_val))

    y_pred = model.predict(X_test)
    return prediction_utilities.convert_preds_into_ema(y_pred), Y_test
def regression_participant_independent(csv, trainingid, validationid,
                                       testingid, normalizerMethod,
                                       normalizer1, normalizer2, totalDays):
    X_train = []
    Y_train = []

    X_val = []
    Y_val = []

    X_test = []
    Y_test = []

    for i in range(totalDays - 1, len(csv)):
        days = data_collector.collectDayData(csv, i, totalDays)

        if data_collector.isSameUserAcross(days):
            x = transform_to_train_vec.transform(days, True, "simpleNN",
                                                 totalDays, normalizerMethod,
                                                 normalizer1, normalizer2)

            # put the x vector into the appropriate set (i.e. training, validation, testing)
            if days[0][EMA_INDEX] != '':
                X_train, Y_train, X_val, Y_val, X_test, Y_test = assign_data.independent_assign(
                    False, days[0][1], trainingid, validationid, testingid,
                    X_train, Y_train, X_val, Y_val, X_test, Y_test, x,
                    days[0][EMA_INDEX])

    model = Sequential()
    model.add(Dense(1024, input_dim=len(X_train[0]), activation='relu'))
    model.add(Dense(1024, activation='relu'))
    model.add(
        Dense(1,
              activation='softmax',
              kernel_regularizer=L1L2(l1=0.0, l2=0.15)))

    model.compile(optimizer='rmsprop',
                  loss='mean_squared_error',
                  metrics=['acc'])
    model.fit(X_train, Y_train, epochs=15, validation_data=(X_val, Y_val))

    y_pred = model.predict(X_test)
    return y_pred, Y_test
def regression_participant_dependent(csv, normalizerMethod, normalizer1,
                                     normalizer2, totalDays,
                                     leave_one_patient):
    X_train = []
    Y_train = []

    X_val = []
    Y_val = []

    X_test = []
    Y_test = []

    for i in range(totalDays - 1, len(csv)):
        days = data_collector.collectDayData(csv, i, totalDays)

        userid = days[0][1]

        if data_collector.isSameUserAcross(days):
            x = transform_to_train_vec.transform(days, True, "simpleNN",
                                                 totalDays, normalizerMethod,
                                                 normalizer1, normalizer2)

            if days[0][EMA_INDEX] != '':
                X_train, Y_train, X_val, Y_val, X_test, Y_test = assign_data.dependent_assign(
                    False, 0.60, 0.75, X_train, Y_train, X_val, Y_val, X_test,
                    Y_test, x, days[0][EMA_INDEX], leave_one_patient, userid)

    model = Sequential()
    model.add(Dense(1024, input_dim=len(X_train[0]), activation='relu'))
    model.add(Dense(1024, activation='relu'))
    model.add(
        Dense(1, activation='relu', kernel_regularizer=L1L2(l1=0.0, l2=0.2)))

    model.compile(optimizer='adam', loss='mean_squared_error', metrics=['acc'])
    model.fit(X_train, Y_train, epochs=15, validation_data=(X_val, Y_val))

    y_pred = model.predict(X_test)
    return y_pred, Y_test
예제 #7
0
def classify_participant_dependent(csv, normalizer_type, normalizer1, normalizer2, totalDays, leave_one_patient):
    X_train = []
    Y_train = []

    X_val = []
    Y_val = []

    X_test = []
    Y_test = []

    for i in range(totalDays - 1, len(csv)):
        days = data_collector.collectDayData(csv, i, totalDays)

        userid = days[0][1]

        if data_collector.isSameUserAcross(days):
            x = transform_to_train_vec.transform(
                days,
                False,
                "LSTM",
                totalDays,
                normalizer_type,
                normalizer1,
                normalizer2
            )


            if days[0][EMA_INDEX] != '':

                X_train, Y_train, X_val, Y_val, X_test, Y_test = assign_data.dependent_assign(
                    True,
                    0.60,
                    0.75,
                    X_train,
                    Y_train,
                    X_val,
                    Y_val,
                    X_test,
                    Y_test,
                    x,
                    days[0][EMA_INDEX],
                    leave_one_patient,
                    userid
                )




    model = Sequential()
    model.add(Bidirectional(LSTM(150, return_sequences=False, recurrent_dropout=0.2, bias_initializer = keras.initializers.Constant(value=0.15)), input_shape=(len(X_train[0]), len(X_train[0][0]))))
    model.add(Dense(4, activation='softmax', kernel_regularizer=L1L2(l1=0.0, l2=0.0)))
    model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['categorical_accuracy'])


    if leave_one_patient is None:
        model.fit(X_train, Y_train, epochs=9, validation_data=(X_val, Y_val))
    else:
        model.fit(X_train, Y_train, epochs=9)

    y_pred = model.predict(X_test)
    # return the predictions and the truth values
    return prediction_utilities.convert_preds_into_ema(y_pred), Y_test
예제 #8
0
def regression_participant_dependent(csv, normalizerMethod, normalizer1, normalizer2, totalDays, leave_one_patient):
    X_train = []
    Y_train = []

    X_val = []
    Y_val = []

    X_test = []
    Y_test = []

    for i in range(totalDays - 1, len(csv)):
        days = data_collector.collectDayData(csv, i, totalDays)

        userid = days[0][1]

        if data_collector.isSameUserAcross(days):
            x = transform_to_train_vec.transform(
                days,
                False,
                "LSTM",
                totalDays,
                normalizerMethod,
                normalizer1,
                normalizer2
            )

            if days[0][EMA_INDEX] != '':
                X_train, Y_train, X_val, Y_val, X_test, Y_test = assign_data.dependent_assign(
                    False,
                    0.60,
                    0.75,
                    X_train,
                    Y_train,
                    X_val,
                    Y_val,
                    X_test,
                    Y_test,
                    x,
                    days[0][EMA_INDEX],
                    leave_one_patient,
                    userid
                )
    print(X_test.shape)
    model = Sequential()

    # model.add(Bidirectional(LSTM(128, return_sequences=True), input_shape=(totalDays, len(X_train[0][0]))))
    # model.add(LSTM(128, return_sequences=True, recurrent_dropout=0.20))
    # model.add(LSTM(64))
    # model.add(Dropout(0.4))

    model.add(LSTM(128, return_sequences=True, input_shape=(totalDays, len(X_train[0][0]))))
    model.add(LSTM(128, return_sequences=True, recurrent_dropout=0.2))
    model.add(LSTM(64))
    model.add(Dense(128, activation='tanh'))
    model.add(Dense(1,  activation='relu'))
    model.compile(loss='mean_squared_error', optimizer='adam', metrics=['acc'])

    if leave_one_patient is None:
        model.fit(X_train, Y_train, epochs=25, validation_data=(X_val, Y_val))
    else:
        model.fit(X_train, Y_train, epochs=25)

    y_pred = model.predict(X_test)
    # return the predictions and the truth values
    return y_pred, Y_test