Exemplo n.º 1
0
model.fit(
    train_X,
    train_y,
    epochs=epochs,
    # callbacks=[early_stopping, checkpoint],
    batch_size=batch_size,
    validation_split=0.1,
    validation_data=(val_X, val_y),
    # class_weight={0:1, 1:3}, # 样本均衡
)

print('test AUC: %f' % model.evaluate(test_X, test_y)[1])

# ------------- model evaluation in test dataset ----

train_predictions_weighted = model.predict(train_X, batch_size=batch_size)
test_predictions_weighted = model.predict(test_X, batch_size=batch_size)

# ------------- confusion matrix
from sklearn.metrics import confusion_matrix, roc_curve
import matplotlib.pyplot as plt
import seaborn as sns


def plot_cm(labels, predictions, p=0.5):
    cm = confusion_matrix(labels, predictions > p)
    plt.figure(figsize=(5, 5))
    sns.heatmap(cm, annot=True, fmt="d")
    plt.title('Confusion matrix @{:.2f}'.format(p))
    plt.ylabel('Actual label')
    plt.xlabel('Predicted label')
Exemplo n.º 2
0
deep_input.append(wide_features.values)

my_callbacks = [
    EarlyStopping(monitor='loss',
                  min_delta=1e-5,
                  patience=3,
                  verbose=1,
                  mode='min')
]
model.fit(x=deep_input,
          y=final_tags,
          batch_size=64,
          epochs=100,
          verbose=1,
          callbacks=my_callbacks)

pred = model.predict(deep_input, batch_size=2**14)

pred_real = target_mms.inverse_transform(pred)

s0, s1 = 0, 0
for i, x in enumerate(pred_real):
    if pred[i] > 0:
        s1 += 1
        print(deep_features.iloc[i, 0], deep_features.iloc[i, -1],
              final_tags[i], pred[i])
    else:
        s0 += 1
print('s0:', s0, 's1:', s1)