
Image by Editor | Midjourney
Model evaluation in fraud detection requires a comprehensive understanding of performance across multiple metrics. While we explored Yellowbrick’s Confusion Matrix in a separate post, the library offers several other powerful visualization tools for assessing model performance. In this article, we’ll focus on the Classification Report visualizer, which provides a detailed view of precision, recall, and F1 scores for each class.
Understanding Classification Reports vs Confusion Matrices
A classification report builds upon the insights provided by confusion matrices, offering a more granular analysis of model performance. Where confusion matrices show us raw counts of correct and incorrect predictions, classification reports transform these numbers into performance ratios that help us understand our model’s strengths and weaknesses for each class. This is particularly valuable in fraud detection, where class imbalance makes accuracy an insufficient metric on its own.
Setting Up Our Model
We’ll continue working with the healthcare provider dataset, using the aggregated features we created by combining inpatient and outpatient claims data. If you’d like to see how we constructed this dataset, please refer to our article on “How to Analyze Features Using Yellowbrick“. Once you have properly set up your ‘final_df’, the following code should run smoothly.
Let’s prepare our data and train a logistic regression model:
from sklearn.model_selection import train_test_split from sklearn.preprocessing import LabelEncoder, StandardScaler from sklearn.linear_model import LogisticRegression # Encode the PotentialFraud column as a binary variable le = LabelEncoder() final_df["PotentialFraud"] = le.fit_transform(final_df["PotentialFraud"]) # 1 = Fraud, 0 = Non-Fraud # Define features and target variable X = final_df[["IP_Claims_Total", "OP_Claims_Total"]] y = final_df["PotentialFraud"] # Standardize the features scaler = StandardScaler() X_scaled = scaler.fit_transform(X) # Split the dataset into training and testing sets (80-20 split) X_train, X_test, y_train, y_test = train_test_split(X_scaled, y, test_size=0.2, random_state=42) # Train a logistic regression model log_reg = LogisticRegression(random_state=42) log_reg.fit(X_train, y_train)
This code block handles several preprocessing steps. We first encode our target variable, converting “Yes”/”No” fraud labels into binary values. We then standardize our feature scales and split our data into training and testing sets before fitting a logistic regression model.
Creating the Classification Report Visualization
Now that we have our trained model, let’s use Yellowbrick’s Classification Report visualizer to evaluate its performance. This visualization will help us understand how well our model identifies both fraudulent and non-fraudulent providers across different metrics.
# Yellowbrick's Classification Report from yellowbrick.classifier import ClassificationReport import matplotlib.pyplot as plt cr = ClassificationReport(log_reg, classes=['No Fraud', 'Fraud']) cr.fit(X_train, y_train) cr.score(X_test, y_test) cr.finalize() plt.tight_layout() plt.show()

Image By Author
Interpreting the Results
The classification report visualization displays three key metrics for each class:
Precision (0.816 for Fraud): When our model predicts a provider is fraudulent, it is correct 81.6% of the time. This indicates that among all providers our model flags as fraudulent, about 18.4% are false alarms.
Recall (0.385 for Fraud): Our model identifies 38.5% of all actually fraudulent providers. This relatively low recall suggests that our model misses more than half of the fraudulent cases, which we also observed in our confusion matrix analysis.
F1-Score (0.523 for Fraud): The F1-score represents the harmonic mean of precision and recall, providing a balanced metric that considers both false positives and false negatives. Our score of 0.523 for fraud detection indicates room for improvement in balancing precision and recall.
For the non-fraud class, we see notably higher metrics:
- Precision: 0.938
- Recall: 0.991
- F1-Score: 0.964
These higher values for non-fraudulent cases are expected given the class imbalance in our dataset, but they don’t necessarily indicate superior model performance. In fraud detection, we often need to prioritize identifying fraudulent cases (higher recall) even if it means investigating some false positives (lower precision).
Improving Model Performance
The classification report highlights areas where our model could be enhanced:
1. The low recall for fraud detection suggests we might benefit from techniques like:
- Adjusting class weights in our logistic regression
- Implementing more sophisticated sampling techniques
- Incorporating additional relevant features
2. The high precision for fraud detection indicates that when our model does flag a provider as fraudulent, it’s usually correct. This suggests our features capture meaningful patterns in fraudulent behavior.
3. The strong performance on non-fraud cases (high precision and recall) confirms our model’s ability to identify normal claiming patterns, providing a solid foundation for detecting anomalies.
Conclusion
Yellowbrick’s Classification Report visualizer offers a comprehensive view of model performance, revealing details that might be missed when looking at accuracy alone. By examining precision, recall, and F1-scores for each class, we can better understand our model’s strengths and limitations in healthcare fraud detection. This insight guides us toward specific improvements that could enhance our model’s ability to identify fraudulent providers while maintaining high accuracy for legitimate cases.
