Model Evaluation

Evaluate Binary Classification Performance

binary_classification_eval(df, true_column, predict_column)

Evaluate binary classification performance.

Parameters:
  • df (pandas.DataFrame) – DataFrame containing the true and predicted labels.

  • true_column (str) – Name of the column containing true class labels.

  • predict_column (str) – Name of the column containing predicted class labels.

Returns:

Dictionary containing evaluation metrics.

Return type:

dict

Raises:

AssertionError – If specified columns are not found in the DataFrame.

This function computes common binary classification evaluation metrics, including accuracy, precision, recall, F1 score, confusion matrix, KS statistic, and Gini coefficient.

The returned dictionary has the following structure:

{
    'Confusion_Matrix': array,
    'Accuracy': float,
    'Precision': float,
    'Recall': float,
    'F1_Score': float,
    'KS_Statistic': float,
    'Gini_Coefficient': float
}

Example

from df_csv_excel.eval_model import binary_classification_eval

result = binary_classification_eval(df, 'true_labels', 'predicted_labels')
print(result)

Metrics Included:

  • Confusion Matrix

  • Accuracy

  • Precision

  • Recall

  • F1 Score

  • KS Statistic

  • Gini Coefficient