outputs=[output_readm, output_cooccur])

    adam = Adam(lr=lr)
    model.compile(loss={
        'readm': 'categorical_crossentropy',
        'cooccur': loss_cooccur
    },
                  optimizer=adam,
                  loss_weights={
                      'readm': 1.,
                      'cooccur': loss_weight
                  })

    auccheckpoint = AUCCheckPoint(filepath=model_path + 'embeding_nn_temp' +
                                  str(job_index) + '.h5',
                                  validation_x=val_x,
                                  validation_y=val_y,
                                  auc_output_idx=[0])
    reduce_lr = ReduceLROnPlateau(monitor='val_loss',
                                  factor=0.2,
                                  patience=10,
                                  min_lr=K.epsilon())

    class_weight = {'readm': {0: 1., 1: minor_class_weight}}

    hist = model.fit_generator(generator=trn_gen,
                               validation_data=val_gen,
                               epochs=100,
                               verbose=2,
                               callbacks=[auccheckpoint, reduce_lr],
                               class_weight=class_weight)
Beispiel #2
0
     x = Dense(fc_width, activation='relu')(merged)
     x = Dropout(dropout)(x)
     prediction = Dense(2, activation='softmax', name='prediction')(x)
     model = Model(inputs=[input_DX1, input_DX, input_PR, input_demo], outputs=prediction)
     X_trn = [DX1_array_trn, DX_mat_trn, PR_mat_trn, demo_mat_trn]
     X_val = [DX1_array_val, DX_mat_val, PR_mat_val, demo_mat_val]
     X_tst = [DX1_array_tst, DX_mat_tst, PR_mat_tst, demo_mat_tst]
       
 for l in model.layers:
     if l.name=='DX_embed' or l.name=='PR_embed' or l.name=='DX1_embed':
         l.trainable = False
         
 adam = Adam(lr=lr1)
 model.compile(optimizer=adam, loss='binary_crossentropy')
 
 auccheckpoint = AUCCheckPoint(filepath=model_path+'ami_glove_auc_temp1_'+str(job_index)+'.h5', validation_y=Y_val, 
                              validation_x=X_val)
 reduce_lr = ReduceLROnPlateau(monitor='val_loss', factor=0.2, patience=10, min_lr=K.epsilon())
 earlystop = EarlyStopping(monitor='val_loss', patience=20)
 
 class_weight = {0:(Y_trn.shape[0]/sum(Y_trn[:, 0])), 1:(Y_trn.shape[0]/sum(Y_trn[:, 1]))}
     
 hist = model.fit(X_trn, Y_trn, batch_size=batchsize, epochs=50, callbacks=[auccheckpoint, reduce_lr, earlystop], 
                  validation_data=[X_val, Y_val], verbose=2)
 
 model.load_weights(model_path+'ami_glove_auc_temp1_'+str(job_index)+'.h5')
 y = model.predict(X_tst, verbose=0)
 y_pred = y[:, 1]
 fpr, tpr, _ = roc_curve(y_true, y_pred)
 roc_auc = auc(fpr, tpr)
 auc_freeze_lst.append(roc_auc)
 
Beispiel #3
0
x = base_model.output
x = GlobalAveragePooling2D()(x)

output1 = Dense(2, activation='softmax', name='split0_123')(x)
output2 = Dense(2, activation='softmax', name='split01_23')(x)
output3 = Dense(2, activation='softmax', name='split012_3')(x)

model = Model(inputs=base_model.input, outputs=[output1, output2, output3])

adam = Adam()
model.compile(optimizer=adam, loss='categorical_crossentropy')

checkpointer = ModelCheckpoint(filepath=model_path+'binary3_valloss5.h5', verbose=0, save_best_only=True, 
                               save_weights_only=True)
auccheckpt = AUCCheckPoint(filepath=model_path+'binary3_auc5.h5', 
                           validation_y=val_df[['split0_123', 'split01_23', 'split012_3']].values,
                          validation_itr=val_itr)
reduce_lr = ReduceLROnPlateau(monitor='loss', factor=0.2, patience=5, min_lr=1.e-8)
earlystop = EarlyStopping(monitor='val_loss', patience=30)

class_weight = {'split0_123':{0:len(trn_df)/sum(trn_df.split0_123==0), 1:len(trn_df)/sum(trn_df.split0_123==1)}, 
               'split01_23':{0:len(trn_df)/sum(trn_df.split01_23==0), 1:len(trn_df)/sum(trn_df.split01_23==1)}, 
               'split012_3':{0:len(trn_df)/sum(trn_df.split012_3==0), 1:len(trn_df)/sum(trn_df.split012_3==1)}}

hist = model.fit_generator(trn_itr, steps_per_epoch=trn_itr.n // batch_size, epochs=200, 
                              validation_data=val_itr, validation_steps=val_itr.n // batch_size, 
                              callbacks=[checkpointer, auccheckpt, reduce_lr, earlystop], 
                                verbose=2)

#with open('output/binary3_0528.pkl', 'wb') as f:
#    pickle.dump(hist.history, f, -1)
Beispiel #4
0
 input_other = Input(shape=(other_mat.shape[1], ))
 merged = Concatenate(axis=1)([DX1_embed, DX_embed, PR_embed, input_other])
 x = Dense(fc_width, activation='relu')(merged)
 x = Dropout(dropout)(x)
 x = Concatenate(axis=1)([x, hosp_embed])
 prediction = Dense(1, activation='sigmoid', name='prediction', use_bias=False)(x)
 model = Model(inputs=[input_DX1, input_DX, input_PR, input_hosp, input_other], outputs=prediction)     
 
 for l in model.layers:
     if l.name=='DX_embed' or l.name=='PR_embed' or l.name=='DX1_embed':
         l.trainable = False
         
 adam = Adam(lr=lr1)
 model.compile(optimizer=adam, loss='binary_crossentropy')
 
 checkpoint = AUCCheckPoint(filepath=model_path+'temp/{}/inference_temp1.h5'.format(job_index), validation_y=y_val, 
                              validation_x=[DX1_array_val, DX_mat_val, PR_mat_val, hosp_array_val, other_mat_val])
 reduce_lr = ReduceLROnPlateau(monitor='val_loss', factor=0.2, patience=10, min_lr=K.epsilon())
 earlystop = EarlyStopping(monitor='val_loss', patience=20)
 
 hist = model.fit([DX1_array_trn, DX_mat_trn, PR_mat_trn, hosp_array_trn, other_mat_trn], y_trn, 
                  batch_size=batchsize, epochs=50, callbacks=[checkpoint, reduce_lr, earlystop], 
                  validation_data=[[DX1_array_val, DX_mat_val, PR_mat_val, hosp_array_val, other_mat_val], y_val], 
                 verbose=2)
 
 model.load_weights(model_path+'temp/{}/inference_temp1.h5'.format(job_index))
 
 for l in model.layers:
     if l.name=='DX_embed' or l.name=='PR_embed' or l.name=='DX1_embed':
         l.trainable = True
 adam = Adam(lr=lr2)
 model.compile(optimizer=adam, loss='binary_crossentropy')
Beispiel #5
0
        prediction = Dense(2, activation='softmax')(merged)
        model = Model(
            inputs=[input_DX1, input_DX, input_PR, input_hosp, input_other],
            outputs=prediction)

    for l in model.layers:
        if l.name == 'DX_embed' or l.name == 'PR_embed' or l.name == 'DX1_embed':
            l.trainable = False

    adam = Adam(lr=lr1)
    model.compile(optimizer=adam, loss='categorical_crossentropy')

    auccheckpoint = AUCCheckPoint(
        filepath=model_path + 'embeding_nn_sub_temp1_' + str(job_index) +
        '.h5',
        validation_y=Y_val[:, 1],
        validation_x=[
            DX1_array_val, DX_mat_val, PR_mat_val, hosp_array_val,
            other_mat_val
        ])
    reduce_lr = ReduceLROnPlateau(monitor='val_loss',
                                  factor=0.2,
                                  patience=10,
                                  min_lr=K.epsilon())
    earlystop = EarlyStopping(monitor='val_loss', patience=20)

    class_weight = {
        0: (Y_trn.shape[0] / sum(Y_trn[:, 0])),
        1: (Y_trn.shape[0] / sum(Y_trn[:, 1]))
    }

    hist = model.fit(
Beispiel #6
0
        model = Model(
            inputs=[input_DX1, input_DX, input_PR, input_hosp, input_other],
            outputs=prediction)

        for l in model.layers:
            if l.name == 'DX_embed' or l.name == 'PR_embed' or l.name == 'DX1_embed':
                l.trainable = False

        adam = Adam(lr=lr1)
        model.compile(optimizer=adam, loss='binary_crossentropy')

        if checkpoint_monitor == 'auc':
            checkpoint = AUCCheckPoint(
                filepath=model_path + 'ami_glove_auc_temp1_' + str(job_index) +
                '.h5',
                validation_y=y_val,
                validation_x=[
                    DX1_array_val, DX_mat_val, PR_mat_val, hosp_array_val,
                    other_mat_val
                ])
        elif checkpoint_monitor == 'valloss':
            checkpoint = ModelCheckpoint(
                filepath=model_path + 'ami_glove_auc_temp1_' + str(job_index) +
                '.h5',
                save_best_only=True,
                save_weights_only=True)
        reduce_lr = ReduceLROnPlateau(monitor='val_loss',
                                      factor=0.2,
                                      patience=10,
                                      min_lr=K.epsilon())
        earlystop = EarlyStopping(monitor='val_loss', patience=20)
Beispiel #7
0
                       loss_weights={
                           'CD_Active_AnyLocation': 1.,
                           'Fistula_Any': 1.,
                           'Abscess_any': 1.
                       })

#parallel_model.compile(optimizer='adam', loss={'Abscess_any':'binary_crossentropy'}, metrics=['accuracy'])

checkpointer = ModelCheckpoint(filepath=model_path +
                               'dense121_gr12_3output0611.h5',
                               verbose=0,
                               save_best_only=True,
                               save_weights_only=True)
auccheckpoint = AUCCheckPoint(
    filepath=model_path + 'dense121_gr12_3output_auc0611.h5',
    validation_y=val_df[[
        'CD_Active_AnyLocation', 'Fistula_Any', 'Abscess_any'
    ]].values,
    validation_itr=val_itr)
reduce_lr = ReduceLROnPlateau(monitor='loss',
                              factor=0.2,
                              patience=5,
                              min_lr=1.e-7)
earlystop = EarlyStopping(monitor='val_loss', patience=30)

hist = parallel_model.fit_generator(
    trn_itr,
    steps_per_epoch=trn_itr.n // (batch_size * G),
    epochs=200,
    validation_data=val_itr,
    validation_steps=val_itr.n // (batch_size * G),
    callbacks=[checkpointer, auccheckpoint, reduce_lr, earlystop],
Beispiel #8
0
output2 = Dense(1, activation='sigmoid', name='Inflamm_Mayo_2')(x)
output3 = Dense(1, activation='sigmoid', name='Inflamm_Mayo_3')(x)

model = Model(inputs=base_model.input,
              outputs=[output0, output1, output2, output3])

adam = Adam()
model.compile(optimizer=adam, loss='binary_crossentropy')

checkpointer = ModelCheckpoint(filepath=model_path + 'binary4_valloss_0528.h5',
                               verbose=0,
                               save_best_only=True,
                               save_weights_only=True)
auccheckpt = AUCCheckPoint(filepath=model_path + 'binary4_auc_0528.h5',
                           validation_y=val_df[[
                               'Inflamm_Mayo_0', 'Inflamm_Mayo_1',
                               'Inflamm_Mayo_2', 'Inflamm_Mayo_3'
                           ]].values,
                           validation_itr=val_itr)
reduce_lr = ReduceLROnPlateau(monitor='loss',
                              factor=0.2,
                              patience=5,
                              min_lr=1.e-8)
earlystop = EarlyStopping(monitor='val_loss', patience=30)

#class_weights = {0:(5895/4467.), 1:(5895./828), 2:(5895./389), 3:(5895./211)}

hist = model.fit_generator(
    trn_itr,
    steps_per_epoch=trn_itr.n // batch_size,
    epochs=200,
    validation_data=val_itr,
Beispiel #9
0
merged = Dense(fc_width, activation='relu')(merged)
merged = Dropout(dropout)(merged)
prediction = Dense(2, activation='softmax', name='prediction')(merged)
model = Model(inputs=[
    input_DX1, input_DX, input_PR, input_hosp, input_other,
    input_labels_flatten, input_conditions
],
              outputs=[prediction, cr])

adam = Adam(lr=lr1)
model.compile(optimizer=adam, loss=[K.binary_crossentropy, zero_loss])

auccheckpoint = AUCCheckPoint(
    filepath=model_path + 'skipgram_temp' + str(job_index) + '.h5',
    validation_y=[Y_val, np.random.randn(Y_val.shape[0], 1)],
    validation_x=[
        DX1_array_val, DX_mat_val, PR_mat_val, hosp_array_val, other_mat_val,
        labels_flatten_val, conditions_val
    ],
    auc_output_idx=[0])
reduce_lr = ReduceLROnPlateau(monitor='val_loss',
                              factor=0.2,
                              patience=10,
                              min_lr=K.epsilon())
earlystop = EarlyStopping(monitor='val_loss', patience=30)

class_weight = {
    0: (Y_trn.shape[0] / sum(Y_trn[:, 0])),
    1: (Y_trn.shape[0] / sum(Y_trn[:, 1]))
}

hist = model.fit([
Beispiel #10
0
base_model = InceptionV3(weights='imagenet', include_top=False)
x = base_model.output
x = GlobalAveragePooling2D()(x)
output1 = Dense(2, activation='softmax', name='split0_123')(x)
output2 = Dense(2, activation='softmax', name='split01_23')(x)
output3 = Dense(2, activation='softmax', name='split012_3')(x)
model = Model(inputs=base_model.input, outputs=[output1, output2, output3])

model.compile(optimizer='adam', loss='categorical_crossentropy')

checkpointer = ModelCheckpoint(filepath=model_path + 'binary3_valloss_all.h5',
                               verbose=0,
                               save_best_only=True,
                               save_weights_only=True)
auccheckpt = AUCCheckPoint(filepath=model_path + 'binary3_auc_all.h5',
                           validation_itr=val_itr)
reduce_lr = ReduceLROnPlateau(monitor='loss',
                              factor=0.2,
                              patience=5,
                              min_lr=K.epsilon())
earlystop = EarlyStopping(monitor='val_loss', patience=30)

class_weight = {
    'split0_123': {
        0: len(train_df) / sum(train_df.split0_123 == 0),
        1: len(train_df) / sum(train_df.split0_123 == 1)
    },
    'split01_23': {
        0: len(train_df) / sum(train_df.split01_23 == 0),
        1: len(train_df) / sum(train_df.split01_23 == 1)
    },
Beispiel #11
0
    input_code = Input(shape=(len(code_cat), ))
    input_hosp = Input(shape=(len(hosp_cat), ))
    input_other = Input(shape=(other_mat_train.shape[1], ))
    merged = Concatenate(axis=1)([input_code, input_hosp, input_other])
    x = Dense(fc_width1, activation='relu')(merged)
    x = Dense(fc_width2, activation='relu')(x)
    x = Dropout(dropout)(x)
    prediction = Dense(2, activation='softmax')(x)
    model = Model(inputs=[input_code, input_hosp, input_other],
                  outputs=prediction)

    adam = Adam(lr=lr)
    model.compile(optimizer=adam, loss='categorical_crossentropy')

    auccheckpoint = AUCCheckPoint(
        filepath=model_path + 'ohe_temp1_' + str(job_index) + '.h5',
        validation_y=Y_val[:, 1],
        validation_x=[code_ohe_val, hosp_ohe_val, other_mat_val])
    reduce_lr = ReduceLROnPlateau(monitor='val_loss',
                                  factor=0.2,
                                  patience=5,
                                  min_lr=K.epsilon())
    earlystop = EarlyStopping(monitor='val_loss', patience=10)

    #class_weight = {0:(Y_trn.shape[0]/sum(Y_trn[:, 0])), 1:(Y_trn.shape[0]/sum(Y_trn[:, 1]))}
    class_weight = {0: 1., 1: 1.}

    hist = model.fit(
        [code_ohe_trn, hosp_ohe_trn, other_mat_trn],
        Y_trn,
        batch_size=batchsize,
        epochs=10,
Beispiel #12
0
output1 = Dense(2, activation='softmax', name='split0_123')(x)
output2 = Dense(2, activation='softmax', name='split01_23')(x)
output3 = Dense(2, activation='softmax', name='split012_3')(x)

model = Model(inputs=base_model.input, outputs=[output1, output2, output3])

adam = Adam()
model.compile(optimizer=adam, loss='categorical_crossentropy')

checkpointer = ModelCheckpoint(
    filepath=model_path + 'weighted_valloss{}{}.h5'.format(tst_seed, val_seed),
    verbose=0,
    save_best_only=True,
    save_weights_only=True)
auccheckpt = AUCCheckPoint(filepath=model_path +
                           'weighted_auc{}{}.h5'.format(tst_seed, val_seed),
                           validation_itr=val_itr)
reduce_lr = ReduceLROnPlateau(monitor='val_loss',
                              factor=0.2,
                              patience=15,
                              min_lr=K.epsilon())
earlystop = EarlyStopping(monitor='val_loss', patience=30)

class_weight = {
    'split0_123': {
        0: sum(trn_df.split0_123 == 1) / len(trn_df),
        1: sum(trn_df.split0_123 == 0) / len(trn_df)
    },
    'split01_23': {
        0: sum(trn_df.split01_23 == 1) / len(trn_df) * 2,
        1: sum(trn_df.split01_23 == 0) / len(trn_df) * 2