Applications: Vision, Speech, Finance, Healthcare, Robotics
Machine learning is used wherever there are many examples of a decision and the decision is hard to write as rules. This lesson tours five major areas, shows three of them in miniature with runnable code, and points out what makes each area difficult.
Five areas at a glance
| Area | Typical input | Typical output | Common learning type | Main difficulties |
|---|---|---|---|---|
| Computer vision | images, video frames | class labels, boxes around objects, pixel masks | supervised, self-supervised pretraining | lighting and camera changes, labelling cost |
| Speech and audio | sound waves | text (transcription), speaker, command | supervised, self-supervised | accents, background noise, privacy |
| Finance | transactions, account histories, prices | fraud score, credit risk, forecast | supervised, anomaly detection | rare positives, changing behaviour, regulation |
| Healthcare | scans, lab results, records | diagnosis support, risk score, triage | supervised, semi-supervised | few labels, high cost of errors, privacy, bias |
| Robotics | camera, joint angles, sensors | motor commands | reinforcement, imitation learning | safety, simulation-to-reality gap |
Other areas use the same building blocks: recommendation (what to watch or buy next), language (translation, search, chat assistants, see the ai-llm course), manufacturing (defect detection, predictive maintenance), agriculture, energy and science.
Vision in miniature: reading handwritten digits
Computer vision treats an image as a grid of numbers. The load_digits images have pixels with brightness 0 to 16. The example prints one image as characters, then trains a support vector machine on 1257 images and tests it on 540 others.
import numpy as np
from sklearn.datasets import load_digits
from sklearn.model_selection import train_test_split
from sklearn.svm import SVC
digits = load_digits()
img = digits.images[42] # one 8x8 grey-scale image, values 0..16
for row in img:
print("".join(" .:-=+*#%@"[int(v) * 9 // 16] for v in row))
print("label:", digits.target[42])
X_train, X_test, y_train, y_test = train_test_split(digits.data, digits.target, test_size=0.3, random_state=0)
model = SVC(gamma=0.001).fit(X_train, y_train)
print("predicted:", model.predict(digits.data[42:43])[0])
print("test accuracy on", len(y_test), "images:", round(model.score(X_test, y_test), 3)) *:
.@*
*@*
.*@@+
-*:%-
@+
.@*
.@=
label: 1
predicted: 1
test accuracy on 540 images: 0.993
99.3 % on tiny, clean, centred digits. Real photos have millions of pixels, clutter, and objects at any position and scale, which is why modern vision uses deep convolutional networks and transformers (the Computer Vision course).
Speech in miniature: high or low voice
Audio is a long sequence of numbers: the air pressure measured thousands of times per second. A common first step turns the wave into frequencies with a Fourier transform. Here each quarter-second clip is a tone (a "low voice" around 90–150 Hz or a "high voice" around 190–250 Hz) buried in noise, and the only feature is the strongest frequency.
import numpy as np
from sklearn.linear_model import LogisticRegression
# Speech in miniature: is a short sound a low voice (~120 Hz) or a high voice (~220 Hz)?
rate = 2000 # samples per second
t = np.arange(0, 0.25, 1 / rate) # a quarter of a second
rng = np.random.default_rng(5)
def clip(pitch):
return np.sin(2 * np.pi * pitch * t) + 0.8 * rng.normal(size=t.size) # tone + background noise
def features(signal):
spectrum = np.abs(np.fft.rfft(signal))
freqs = np.fft.rfftfreq(signal.size, 1 / rate)
return [freqs[np.argmax(spectrum)]] # the strongest frequency, in Hz
X, y = [], []
for i in range(200):
high = i % 2
pitch = rng.uniform(190, 250) if high else rng.uniform(90, 150)
X.append(features(clip(pitch)))
y.append(high)
X, y = np.array(X), np.array(y)
model = LogisticRegression().fit(X[:150], y[:150])
print("first clips, strongest frequency (Hz):", X[:4, 0])
print("accuracy on 50 new clips:", model.score(X[150:], y[150:]))first clips, strongest frequency (Hz): [140. 212. 96. 248.]
accuracy on 50 new clips: 1.0
The frequencies come out in steps of 4 Hz because a quarter-second clip resolves frequencies only to Hz. With one well-chosen feature the task is easy. Real speech recognition must turn 16,000 numbers per second into words, across speakers, accents and microphones; deep networks trained on thousands of hours of audio do this today.
Finance in miniature: catching rare fraud
In finance the interesting events are rare. Of 2000 test payments here, only 50 are fraudulent (2.5 %). That makes accuracy a misleading score, as the example shows.
import numpy as np
from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import recall_score
# Finance: card payments, about 2 % fraudulent (class 1).
X, y = make_classification(n_samples=5000, n_features=10, n_informative=5, weights=[0.98],
class_sep=2.0, random_state=0)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.4, random_state=0, stratify=y)
print("fraud cases in the test set:", y_test.sum(), "of", len(y_test))
always_ok = np.zeros_like(y_test) # a "model" that never flags anything
print("never flag: accuracy", round(np.mean(always_ok == y_test), 3), " fraud caught", recall_score(y_test, always_ok))
model = RandomForestClassifier(n_estimators=100, class_weight="balanced", random_state=0).fit(X_train, y_train)
pred = model.predict(X_test)
print("random forest: accuracy", round(np.mean(pred == y_test), 3), " fraud caught", round(recall_score(y_test, pred), 3))fraud cases in the test set: 50 of 2000
never flag: accuracy 0.975 fraud caught 0.0
random forest: accuracy 0.992 fraud caught 0.7
A "model" that never flags anything is 97.5 % accurate and completely useless. The random forest is only 1.7 points more accurate, yet it catches 70 % of the fraud (the recall, 35 of 50 cases). In rare-event problems, measure what matters: the share of positives caught, and how many false alarms it costs. The Training, Evaluation & Improvement course covers these metrics, and the Machine Learning course has a hands-on lesson on imbalanced data.
Healthcare
Models read X-rays, flag diabetic eye disease in retina photos, predict which patients will deteriorate, and help find drug candidates. The mini project of this course builds a classifier for breast-tumour measurements from a public research data set. Three things make healthcare special:
- Errors have unequal costs. Missing a tumour is much worse than a false alarm that leads to a second test, so the metric and the decision threshold must reflect that.
- Labels are expensive and sometimes disputed. Expert time is scarce, and experts disagree. This motivates semi-supervised and active learning.
- Data is personal. Privacy law, consent and the risk of a model performing worse for under-represented groups shape every step. Models support clinicians; they do not replace their judgement.
Robotics
A robot must act, not just predict, and each action changes what it sees next. Learning here often uses reinforcement learning (trial and error with rewards), usually in a simulator first, because trial and error on real hardware is slow and can break things. Imitation learning, learning from human demonstrations, is the other common route. Most robots combine learned perception (deep vision models) with classical control and planning.
What all applications share
Whatever the area, the same questions decide success: Is there enough representative, correctly labelled data? Which metric reflects the real cost of errors? What happens when the model is wrong? How will we notice when the world changes? The next lesson, the ML system lifecycle, organises these questions into stages.
Practice
- A hospital model flags pneumonia on chest X-rays. Which is worse, a false positive or a false negative, and how should that affect the metric you report?
Answer
A false negative (a missed pneumonia) is usually worse, because the patient goes untreated. Report recall (sensitivity) prominently alongside the false-positive rate, and choose the decision threshold so that recall is high enough, accepting more false alarms.
- In the fraud example the random forest classified 1985 of the 2000 test payments correctly (the printed accuracy 0.992 is 0.9925 rounded), and its recall is 0.7 on 50 fraud cases. How many legitimate payments did it wrongly flag?
Answer
mistakes in total. Of the 50 frauds, 35 were caught, so 15 were missed. All 15 mistakes are missed frauds, which leaves false alarms. This model is cautious: it never bothers an honest customer but lets 30 % of the fraud through. Lowering its decision threshold would trade some false alarms for more fraud caught.
Test yourself
Why is accuracy misleading in the fraud example?
- Fraud is rare, so never flagging anything already scores 97.5 %
- Random forests cannot compute accuracy
- The test set is too large
- Accuracy is always misleading
Which learning type is most typical for training a robot to walk in a simulator?
- Unsupervised learning
- Reinforcement learning
- Batch regression
- Clustering
In the speech example, why do the frequencies come out in steps of 4 Hz?
- The microphone is broken
- A clip of 0.25 s resolves frequencies only in steps of Hz
- Logistic regression rounds them
- The noise is 4 Hz