Portfolio / Projects / forensic-glass-classification

Forensic ML · Multiclass classification · Academic project

Can a glass fragment’s chemical composition reveal its glass type?

At a crime scene, a glass fragment may come from a window, a headlamp or a bottle. I tested three models on 213 laboratory-analysed samples, with an evaluation designed for a very small dataset.

0.735Macro F1Random Forest
75.6%Accuracy5-fold mean
76.6%Balanced accuracyRandom Forest
0.474Type 3 F1hardest class

Tools & technologies

Pythonscikit-learnSMOTERandom Foreststratified cross-validation

01 / Context & question

A glass fragment can guide an investigation, provided we know what kind of glass it is.

Each sample is described by its refractive index (RI) and its content of eight elements: sodium (Na), magnesium (Mg), aluminium (Al), silicon (Si), potassium (K), calcium (Ca), barium (Ba) and iron (Fe). The task is to predict its type among six.

Type 1Building windowsfloat process
Type 2Building windowsnon-float process
Type 3Vehicle windowsfloat process
Type 5Containersbottles, jars
Type 6Tablewareglasses, plates
Type 7Headlampsvehicle lights
Type 4 is missing.

The classification scheme has seven types, but no non-float vehicle-window sample (Type 4) exists in the data, so the problem has six classes.

The project question

With so few samples, which model classifies the six types best, and which ones remain hard to separate?

Before comparing models, I needed to understand the shape of these 214 measurements.

02 / What the data shows before modeling

Barium strongly separates headlamps, while several window-glass types remain chemically close.

BariumDistinctive signal

Headlamp fragments show clearly higher barium levels.

MagnesiumAnother useful split

Containers and headlamps show little magnesium compared with several building-window classes.

DifficultyTypes 1, 2 and 3 overlap

Their chemistry overlaps more, foreshadowing the errors later visible in the confusion matrix.

Why this matters: EDA is not only preprocessing. It already explains why some classes are easier to recognize and others remain ambiguous.

03 / Exploratory data analysis (EDA)

Exploration reveals a tiny, very imbalanced dataset with extreme values that may well be real.

Exploratory data analysis (EDA) means examining the data before any modelling: counts, duplicates, distributions, extreme values and visible differences between classes. Here it decides both how the models must be evaluated and what can be expected from them.

What I checked
  1. missing values and duplicates;
  2. number of samples per type;
  3. distribution of each measurement and extreme values;
  4. correlations between measurements;
  5. chemical profiles that set some types apart.
Samples213

214 rows, one exact duplicate removed.

Largest class76

Type 2, non-float windows.

Smallest class9

Type 6, tableware.

Glass type distribution
Building windows (Types 1 and 2) dominate; tableware has only 9 samples.
Standardised distributions and extreme values
Ba, K and Fe show isolated spikes; RI and Si stay tightly grouped.

I kept the extreme values: in such a small dataset, a high barium content may describe a real composition (a headlamp glass, for example) rather than a measurement error.

Barium by glass type
Barium singles out headlamps: median 0.81 for Type 7, 0.00 for the others.
Magnesium by glass type
Containers and headlamps contain very little magnesium, unlike most windows.
Correlations between chemical measurements
Refractive index and calcium move together (0.81); the other measurements stay fairly independent, so all are kept.
What these findings change

The small size makes a single train/test split too fragile: the 9 tableware samples could almost all land on the same side. The imbalance calls for a metric that gives weight to small classes. And the chemical profiles suggest headlamps and containers will be easier than telling windows apart.

The first method choice follows directly from the small number of samples: how to evaluate.

04 / Evaluating with cross-validation

Five cross-validation folds instead of a single fortunate split.

Fold 1learns on 2-3-4-5, tests on 1
Fold 2learns on 1-3-4-5, tests on 2
Fold 3learns on 1-2-4-5, tests on 3
Fold 4learns on 1-2-3-5, tests on 4
Fold 5learns on 1-2-3-4, tests on 5

This frame imposes a strict rule on every preparation step: it must happen inside each fold.

05 / Preparing the data inside each fold

Scale and rebalance, without ever touching the evaluated samples.

Why inside the folds.

If scaling or SMOTE also used the evaluated group, information from that group would leak into training and the score would look artificially good. Evaluated samples therefore always remain real, unseen samples.

With this protocol fixed, I could compare three model families under identical conditions.

06 / Three models compared

A simple model, a neural network and a forest of trees.

BaselineLogistic Regression

Draws linear boundaries between types from the scaled measurements. If it is enough, there is no need to go further.

Deep learningNeural network

Two hidden layers with dropout (neurons randomly switched off during training to avoid memorising).

Tree ensembleRandom Forest

Many decision trees, each learned on a different draw of the data, voting together. Handles non-linear relationships without scaling.

The three models were then evaluated on the same five folds.

07 / Results

Random Forest is clearly ahead; the neural network adds nothing here.

ModelAccuracyBalanced acc.Macro F1
Random Forest75.6%76.6%0.735
Logistic Regression62.5%73.0%0.668
Neural network62.9%65.4%0.624
Mean Macro F1 of the three models over the 5 folds
Mean and standard deviation over the five folds: Random Forest leads on average, but its bars overlap with Logistic Regression’s, a sign of the instability caused by the small sample.
Random Forest confusion matrix over all folds
Every sample appears once, predicted by the model that had not seen it. Errors concentrate among windows (Types 1, 2 and 3).
TypeF1SamplesReading
Type 6 · tableware0.9009good, but very few examples
Type 7 · headlamps0.87329barium sets it apart
Type 2 · non-float windows0.78476confused with Type 1
Type 1 · float windows0.75969confused with Types 2 and 3
Type 5 · containers0.64313few examples
Type 3 · vehicle windows0.47417the hardest

These results say as much about the data as about the models.

08 / Interpretation & real-world value

Match model complexity to the size and shape of the data.

With 213 chemical measurements, a neural network has too few examples to learn reliable boundaries, while the forest makes good use of simple thresholds such as “little magnesium and a lot of barium”. Logistic Regression gets a decent balanced accuracy but a low accuracy: it recognises small classes at the cost of errors on large ones.

Random Forest feature importance
Magnesium, potassium, sodium, calcium and aluminium are the measurements the forest uses most.
Importance does not mean cause.

This ranking describes what this model uses to decide; it is not a chemical conclusion about what makes glasses differ.

Real useA triage aid, not proof

The model can point an expert to the most likely types for a fragment; it replaces neither laboratory analysis nor forensic interpretation.

Weak spotTelling windows apart

Types 1, 2 and 3 have close compositions: that is where more samples or additional measurements would be needed.

These conclusions remain bounded by the size of the dataset.

09 / Limits & lessons

Cross-validation stabilises the evaluation, but it cannot create new data.

  • Only 213 samples, 9 of them tableware.
  • SMOTE helps learning but does not replace real samples.
  • No external dataset to confirm the results.
  • No claim of court or production use: the model can help prioritise an analysis, but it is not forensic evidence on its own.
What I learned

On a small tabular dataset, the evaluation method matters as much as the model. Stratified cross-validation and preparation confined to the folds give modest but credible scores, and they show that a more complex model is not necessarily better.

Going further

I would extend the study with an independent glass dataset, measurements that separate windows better and probability calibration for decision support. The notebook details every step and its outputs.

Next project

Network Pivoting with Ligolo-ng: see how a dual-homed machine becomes a network pivot.