Decision Making Using Machine Learning
Machine Learning for Engineering Decisions
Many engineering choices are yes-or-no decisions made under uncertainty: inspect a weld or pass it, take a pump offline or keep it running, replace a bearing now or at the next shutdown. A machine-learning classifier trained on past sensor readings, images or test records can estimate how likely each case is to be faulty. That estimate is not yet a decision. You turn it into one with a threshold chosen from the costs of being wrong, and you judge the result by counting outcomes on data the model has never seen.
From a probability to an action
A binary classifier returns a score p between 0 and 1 for each case. When the model is well calibrated, p estimates the probability that the case belongs to the positive class. By convention the positive class is the condition you are trying to catch, such as a fault, a defect or a crack. The decision rule is
where t is the decision threshold. Many software libraries default to t=0.5, which is the right choice only when both kinds of mistake cost the same.
Let CFP be the extra cost of a false alarm and CFN the extra cost of a missed fault, each measured against the correct decision for the same case. Acting on a case with probability p has expected extra cost (1−p)CFP; not acting has expected extra cost pCFN. Acting is cheaper when
If a false alarm adds $400 and a miss adds $7 600, then t∗=400/8000=0.05: flag every part whose estimated fault probability exceeds 5%. When misses are expensive, the best threshold sits far below 0.5.
The formula assumes calibrated probabilities. If the scores are only useful as a ranking, choose t by computing the total cost directly on validation data at several candidate thresholds.
Counting outcomes with a confusion matrix
Once t is fixed, every case in an evaluation set lands in one cell of the confusion matrix:
Actually faulty | Actually healthy | |
|---|---|---|
Flagged (p≥t) | true positive (TP) | false positive (FP) |
Not flagged (p<t) | false negative (FN) | true negative (TN) |
The counts give the standard performance measures:
- Accuracy =(TP+TN)/N, the fraction of all N cases classified correctly.
- Recall (sensitivity) =TP/(TP+FN), the fraction of real faults that are caught.
- Precision =TP/(TP+FP), the fraction of alarms that are real faults.
- False positive rate =FP/(FP+TN), the fraction of healthy cases that raise an alarm.
The quantity the decision should minimize is the total cost of mistakes,
Lowering t catches more faults (higher recall) at the price of more false alarms; raising t does the reverse. Accuracy weighs every mistake equally, so it can mislead badly when faults are rare: if 1% of parts are faulty, a model that never flags anything is 99% accurate and catches nothing. Precision also depends on how common faults are. With the same recall and false positive rate, a population with fewer faults has more healthy cases available to produce false alarms, so precision falls.
Judging a model on data it has not seen
A model scored on the data it was trained on usually looks better than it will perform in service. Split the records into three parts: a training set to fit the model, a validation set to compare models and choose t, and a test set used once, at the end, to estimate the cost you should expect. Every choice made by looking at a set makes that set's result optimistic, which is why the test set stays untouched until the end.
When records come in groups, such as many readings from one machine or many photos of one structure, split by group so that no machine or structure appears on both sides. Otherwise near-duplicate records leak from training into evaluation and inflate the score.
What to remember
- Turn a predicted probability into an action with a threshold; for calibrated probabilities the cost-optimal value is t∗=CFP/(CFP+CFN).
- Measure both costs relative to the correct decision for the same case.
- Report recall and precision, not accuracy alone, when faults are rare; precision changes with how common faults are.
- Choose models and thresholds on validation data, estimate cost once on test data, and split grouped records by group.
Example: Setting an alarm threshold for pump bearing faults
A water utility trains a classifier on vibration and temperature data to estimate the probability that a pump bearing will fail within the next 30 days. On a validation set of 2 000 pump-months, 100 of which ended in a bearing failure, the model gives these counts at two candidate thresholds:
Threshold t | TP | FN | FP | TN |
|---|---|---|---|---|
0.5 | 60 | 40 | 30 | 1 870 |
0.1 | 90 | 10 | 190 | 1 710 |
Compared with the correct decision, an unnecessary inspection (false alarm) adds $500 and a missed failure adds $20 000 in emergency repair and lost pumping. Correct decisions add no extra cost.
a) Find the accuracy, precision and recall at t=0.5.
At t=0.5 the counts are TP = 60, FN = 40, FP = 30 and TN = 1 870, with N=2000.
The model is right 96.5% of the time and two in three alarms are real failures, yet it misses 40 of the 100 failures.
b) Repeat part a) at t=0.1.
At t=0.1 the counts are TP = 90, FN = 10, FP = 190 and TN = 1 710.
Lowering the threshold catches ________ more failures but adds ________ false alarms, so accuracy and precision both drop while recall rises.
c) Compute the total cost of mistakes on the validation set and the cost per pump-month for each threshold. Which threshold should the utility prefer?
The total cost is Ctotal=FP⋅CFP+FN⋅CFN, in dollars.
Per pump-month, divide by 2 000: $407.50 at t=0.5 and $147.50 at t=0.1.
The utility should prefer t=0.1, which saves $520 000 per 2 000 pump-months even though its accuracy is lower. Check the saving from the changes in counts: 30 extra caught failures save 30×20000=600000 dollars, and 160 extra false alarms cost 160×500=80000 dollars, a net saving of 520 000 dollars.
A second check against trivial policies: flagging nothing costs 100×20000=2000000 dollars and flagging everything costs 1900×500=950000 dollars, so t=0.1 beats both.
d) If the model's probabilities are well calibrated, what threshold minimizes expected cost, and what should the utility do next?
Both tested thresholds lie above 0.024, so at t=0.1 the model is probably still passing over pumps whose failure risk justifies an inspection. The next step is to compute the validation cost at several lower thresholds, for example 0.05 and 0.02, and keep the cheapest; calibration is rarely perfect, so the measured cost decides rather than the formula alone. The chosen threshold's in-service cost should then be estimated once on a separate test set of pump-months from pumps not used for training or validation.
A foundry uses a classifier to estimate the probability p that each aluminium casting contains internal porosity. Flagged castings go to CT inspection. Compared with the correct decision for the same casting, the extra cost of each mistake is:
Decision error | Extra cost |
|---|---|
Sound casting sent for CT inspection (false alarm) | $150 |
Porous casting shipped (missed defect) | $1 350 |
Correct decisions add no extra cost. Assuming the model's probabilities are well calibrated, find the threshold t∗ above which flagging a casting has the lower expected cost. Give your answer as a decimal probability to three decimal places.
A calibrated model estimates a 0.30 probability that a particular cooling-water pump will fail before the next planned shutdown. Compared with the correct decision, an unnecessary early overhaul adds $3 000 and an unplanned failure adds $9 000. What should the engineer do, and why?