A random forest is an ensemble model that combines decision trees trained on different data subsets and feature samples. Each tree makes conditional splits on feature values; together, the forest classifies transactions as genuine or fraudulent. This makes it useful for tabular fraud data with categorical features, where tree splits can be made without explicit feature scaling. section 3.4 section 3.9
Train the model after selecting and splitting features into time-respecting training and test data. Use randomized hyperparameter search with time-series cross-validation, varying tree depth, number of trees, and class weights. Evaluate candidates with AUPRC, then retain the configuration with the highest validation score. Class weighting increases the penalty for mistakes on the rare fraud class; `balanced` weights classes inversely to their frequency. section 3.4.2 section 3.9
Keep the workflow practical and interpretable:
- Limit depth and the search range when training time and model interpretability matter. section 3.4.2
- Compare precision-recall curves and AUPRC against earlier models on the same test set; added engineered features can materially improve results. section 3.7.3
- Inspect feature importance to identify inputs that repeatedly separate fraud from genuine transactions across tree nodes. section 3.4.4
- Plot an individual constituent tree to inspect feature thresholds, sample counts, class values, majority labels, and Gini impurity. section 3.4.4
Six-tree transaction classifier
A tuned classifier can use a maximum depth of 4, six estimators, and class weights of genuine:fraction 1 to fraud:2. In one tree, a `TRANSFER` value above 0.5 routes a transaction to a subtree, ending at a leaf labeled by the majority class. A node’s Gini impurity indicates how mixed its genuine and fraudulent samples are. section 3.4.2 section 3.4.4
For deployment, save the trained forest together with its ordered feature names and decision threshold. An inference service must recreate engineered features from each incoming transaction, arrange them in the saved order, obtain prediction probabilities, apply the threshold, and return a human-readable fraud decision. Flask can expose this path as a prediction endpoint, and Docker can containerize the service. section 3.8 section 3.8.1 section 3.8.2
Figure 3.14 Tree plot of one of the six constituent decision trees of the random forest model. Each node (box) in the tree contains information such as the name of the feature and the feature threshold value (on which a decision split is made from that node), the gini impurity score of that node, the number of training data samples that end up in that node, the number of genuine versus fraudulent transactions (inside the value list), and the overall class of the node based on the majority transactions class (genuine or fraud).
Inspect one tree in the forest to connect a feature threshold and Gini score to the resulting fraud or genuine leaf decision. section 3.4.4
















