Model Comparism Curve
Thu Aug 11 2022 15:13:49 GMT+0000 (Coordinated Universal Time)
Saved by @mnis00014
def roc_auc_multiple(df, model_1, model_2, model_3, model_4, model_5, model_6, model_7, model_8): import sklearn.metrics as metrics num_label = {'ok': 1, 'nok' : 0} Y_test = df_test['class'].copy().map(num_label).astype('int') # df.reset() predictions_1 = model_1.predict(df, steps=len(df), verbose=0) pred_labels_1 = np.where(predictions_1>0.5, 1, 0) predictions_2 = model_2.predict(df, steps=len(df), verbose=0) pred_labels_2 = np.where(predictions_2>0.5, 1, 0) predictions_3 = model_3.predict(df, steps=len(df), verbose=0) pred_labels_3 = np.where(predictions_3>0.5, 1, 0) predictions_4 = model_4.predict(df, steps=len(df), verbose=0) pred_labels_4 = np.where(predictions_4>0.5, 1, 0) predictions_5 = model_5.predict(df, steps=len(df), verbose=0) pred_labels_5 = np.where(predictions_5>0.5, 1, 0) predictions_6 = model_6.predict(df, steps=len(df), verbose=0) pred_labels_6 = np.where(predictions_5>0.5, 1, 0) predictions_7 = model_7.predict(df, steps=len(df), verbose=0) pred_labels_7 = np.where(predictions_5>0.5, 1, 0) predictions_8 = model_8.predict(df, steps=len(df), verbose=0) pred_labels_8 = np.where(predictions_5>0.5, 1, 0) roc_auc_1 = metrics.roc_auc_score(Y_test, predictions_1) roc_auc_2 = metrics.roc_auc_score(Y_test, predictions_2) roc_auc_3 = metrics.roc_auc_score(Y_test, predictions_3) roc_auc_4 = metrics.roc_auc_score(Y_test, predictions_4) roc_auc_5 = metrics.roc_auc_score(Y_test, predictions_5) roc_auc_6 = metrics.roc_auc_score(Y_test, predictions_6) roc_auc_7 = metrics.roc_auc_score(Y_test, predictions_7) roc_auc_8 = metrics.roc_auc_score(Y_test, predictions_8) print('ROC_AUC_1: ', roc_auc_1) print('ROC_AUC_2: ', roc_auc_2) print('ROC_AUC_3: ', roc_auc_3) print('ROC_AUC_4: ', roc_auc_4) print('ROC_AUC_5: ', roc_auc_5) print('ROC_AUC_6: ', roc_auc_6) print('ROC_AUC_7: ', roc_auc_7) print('ROC_AUC_8: ', roc_auc_8) plt.rcParams['figure.figsize'] = (20 , 20) fpr_1, tpr_1, thresholds_1 = metrics.roc_curve(Y_test, predictions_1) plt.plot(fpr_1, tpr_1, label = 'Model: 01 = %0.3f' % roc_auc_1) fpr_2, tpr_2, thresholds_2 = metrics.roc_curve(Y_test, predictions_2) plt.plot(fpr_2, tpr_2, label = 'Model: 02 = %0.3f' % roc_auc_2) fpr_3, tpr_3, thresholds_3 = metrics.roc_curve(Y_test, predictions_3) plt.plot(fpr_3, tpr_3, label = 'Model: 03 = %0.3f' % roc_auc_3) fpr_4, tpr_4, thresholds_4 = metrics.roc_curve(Y_test, predictions_4) plt.plot(fpr_4, tpr_4, label = 'Model: 04 = %0.3f' % roc_auc_4) fpr_5, tpr_5, thresholds_5 = metrics.roc_curve(Y_test, predictions_5) plt.plot(fpr_5, tpr_5, label = 'Model: 05 = %0.3f' % roc_auc_5) fpr_6, tpr_6, thresholds_6 = metrics.roc_curve(Y_test, predictions_6) plt.plot(fpr_5, tpr_5, label = 'Model: 06 = %0.3f' % roc_auc_6) fpr_7, tpr_7, thresholds_7 = metrics.roc_curve(Y_test, predictions_7) plt.plot(fpr_7, tpr_7, label = 'Model 07 = %0.3f' % roc_auc_7) fpr_8, tpr_8, thresholds_8 = metrics.roc_curve(Y_test, predictions_8) plt.plot(fpr_8, tpr_8, label = 'Model_08 = %0.3f' % roc_auc_8) plt.xlabel("False Positive Rate", fontsize= 12) plt.ylabel("True Positive Rate", fontsize= 12) plt.legend(loc="lower right") fig1 = plt.gcf() plt.show() plt.draw() fig1.savefig('roc_auc_multiple.png', dpi=50) -------------------------------------------- def plot_performance_validation_loss(hist, hist_one, hist_two, hist_three, hist_four, hist_five, hist_six, hist_seven): plt.rcParams['figure.figsize'] = (20, 20) hist_00 = hist.history epochs_00 = hist.epoch hist_01 = hist_one.history epochs_01 = hist_one.epoch hist_02 = hist_two.history epochs_02 = hist_two.epoch hist_03 = hist_three.history epochs_03 = hist_three.epoch hist_04 = hist_four.history epochs_04 = hist_four.epoch hist_05 = hist_five.history epochs_05 = hist_five.epoch hist_06 = hist_six.history epochs_06 = hist_six.epoch hist_07 = hist_seven.history epochs_07 = hist_seven.epoch # plt.subplot(1, 2, 1) # row 1, col 2 index 1 # plt.plot(epochs_00, hist_00['loss'], label='Learning Rate: 0.1') # plt.plot(epochs_01, hist_01['loss'], label='Learning Rate: 0.01') # plt.plot(epochs_02, hist_02['loss'], label='Learning Rate: 0.001') # plt.plot(epochs_03, hist_03['loss'], label='Learning Rate: 0.0001') # plt.plot(epochs_04, hist_04['loss'], label='Learning Rate: 0.00001') # plt.plot(epochs_05, hist_05['loss'], label='Learning Rate: 0.00001') # plt.xlabel('Epochs') # plt.ylabel('Loss') # plt.ylim([-0.001, 2.0]) # plt.title('Training loss with Adam') # plt.legend(loc = 'upper right') # plt.subplot(1, 2, 2) # row 1, col 2 index 1 plt.plot(epochs_00, hist_00['val_loss'], label='Model: 01') plt.plot(epochs_01, hist_01['val_loss'], label='Model: 02') plt.plot(epochs_02, hist_02['val_loss'], label='Model: 03') plt.plot(epochs_03, hist_03['val_loss'], label='Model: 04') plt.plot(epochs_04, hist_04['val_loss'], label='Model: 05') plt.plot(epochs_05, hist_05['val_loss'], label='Model: 06') plt.plot(epochs_06, hist_06['val_loss'], label='Model: 07') plt.plot(epochs_07, hist_07['val_loss'], label='Model: 08') plt.xlabel('Epochs') plt.ylabel('Loss') # plt.ylim([-0.001, 0.8]) plt.title('Validation loss with SGD') plt.legend(loc = 'upper right') # plt.tight_layout(2) fig1 = plt.gcf() plt.show() plt.draw() fig1.savefig('loss_comparism_validation.png', dpi=50) --------------------------------------- def plot_performance_train_validation_loss(hist, hist_one, hist_two, hist_three, hist_four, hist_five, hist_six, hist_seven): plt.rcParams['figure.figsize'] = (20, 20) hist_00 = hist.history epochs_00 = hist.epoch hist_01 = hist_one.history epochs_01 = hist_one.epoch hist_02 = hist_two.history epochs_02 = hist_two.epoch hist_03 = hist_three.history epochs_03 = hist_three.epoch hist_04 = hist_four.history epochs_04 = hist_four.epoch hist_05 = hist_five.history epochs_05 = hist_five.epoch hist_06 = hist_six.history epochs_06 = hist_six.epoch hist_07 = hist_seven.history epochs_07 = hist_seven.epoch plt.subplot(1, 2, 1) # row 1, col 2 index 1 plt.plot(epochs_00, hist_00['loss'], label='Model: 01') plt.plot(epochs_01, hist_01['loss'], label='Model: 02') plt.plot(epochs_02, hist_02['loss'], label='Model: 03') plt.plot(epochs_03, hist_03['loss'], label='Model: 04') plt.plot(epochs_04, hist_04['loss'], label='Model: 05') plt.plot(epochs_05, hist_05['loss'], label='Model: 06') plt.plot(epochs_06, hist_06['loss'], label='Model: 07') plt.plot(epochs_07, hist_07['loss'], label='Model: 08') plt.xlabel('Epochs') plt.ylabel('Loss') # plt.ylim([-0.001, 2.0]) plt.title('Training loss') plt.legend(loc = 'upper right') plt.subplot(1, 2, 2) # row 1, col 2 index 1 plt.plot(epochs_00, hist_00['val_loss'], label='Model: 01') plt.plot(epochs_01, hist_01['val_loss'], label='Model: 02') plt.plot(epochs_02, hist_02['val_loss'], label='Model: 03') plt.plot(epochs_03, hist_03['val_loss'], label='Model: 04') plt.plot(epochs_04, hist_04['val_loss'], label='Model: 05') plt.plot(epochs_05, hist_05['val_loss'], label='Model: 06') plt.plot(epochs_06, hist_06['val_loss'], label='Model: 07') plt.plot(epochs_07, hist_07['val_loss'], label='Model: 08') plt.xlabel('Epochs') plt.ylabel('Loss') # plt.ylim([-0.001, 0.8]) plt.title('Validation loss') plt.legend(loc = 'upper right') # plt.tight_layout(2) fig1 = plt.gcf() plt.show() plt.draw() fig1.savefig('train_validation_loss_com.png', dpi=50)
Comments