← krovix@sec:~$ cd /work
HIGHBUILTML & AI Security

AI Safety Risk Classifier

A decision tree built from scratch - Gini impurity, recursive splitting, prediction - to triage AI-safety risk. It hits 83% on held-out data, and then I turned it on itself to find where it fails.

017 binary risk features
→
02Gini impurity, recursive best-split
→
03Grow tree, then predict
→
0483% held-out vs sklearn baseline
→
05Failure analysis: where does it under-call?

Overview

An interpretable classifier that triages a scenario into a risk level from seven binary features. The point was to understand the model rather than call an API - so the decision tree is written from scratch in Python and NumPy: Gini impurity for split quality, a recursive search for the best split at each node, tree growth, and prediction. A scikit-learn tree trained on the same data acts as the baseline to measure against.

How it works

At every node the classifier scores each candidate split by the Gini impurity of the resulting groups and keeps the best one, recursing until the data is separated. Because it is a plain tree over binary features, the decision path for any prediction is fully readable - you can trace exactly which features drove a risk call, which matters more for a safety tool than a fraction of a point of accuracy.

The failure that mattered

The from-scratch tree (depth 3) reached 83.3% held-out accuracy - 30 of 36 - matching the scikit-learn baseline exactly. The more useful result came from the failure analysis: all six misclassifications collapsed into the medium class. Four were low-risk cases over-rated, and two were high-risk cases under-rated as medium. For a risk-triage system, under-calling high risk is the dangerous direction to be wrong in - and that is exactly the kind of finding a plain accuracy number would have hidden.

Honest limitations

The dataset is small, synthetic and hand-labelled, so the accuracy figure is a demonstration of the method, not a benchmark. The value here is the pipeline and the discipline of interrogating the model's mistakes - which is exactly what a from-scratch build lets you do.

Results
ModelHeld-out accuracyFailure mode
Custom tree (d=3)83.3% (30/36)All 6 errors collapse to medium
scikit-learn (d=3)83.3% (30/36)Matched, for validation
Evidence
Confusion matrix, the two under-called high-risk cases, and the split-by-split decision path - screenshots dropping in here.
#Python#scikit-learn#NumPy#Decision Trees#ML
← all projects