podqast
Machine Learning GuideOCDevelAll episodes

MLG 015 Performance

41 min
Next episodeMLG 016 Consciousness1h 14m
Get its new episodes on Latest. No account

Machine learning performance is graded with metrics like accuracy, precision, recall and F1 on held-out data, and improved with regularization against overfitting, tuned hyperparameters and cleaner data. Also covers confusion matrices, bias vs variance, and validation and test sets.
Links • Notes and resources at ocdevel.com/mlg/15

Loss function vs evaluation metric Each algorithm trains by minimizing its own loss function, such as cross-entropy for logistic regression. An evaluation metric is an objective grade that compares algorithms on held-out data. The loss trains; the metric grades.
Accuracy and class imbalance Accuracy is correct predictions over all predictions. It fails when one class is rare: if 1% of patients have cancer, a model that always answers "no cancer" is 99% accurate and useless.
Confusion matrix A table of predicted against actual classes: true and false positives, true and false negatives. With spam as the positive class, a legitimate email flagged as spam is a false positive, and spam let through is a false negative.
Precision vs recall precision = TP / (TP + FP) recall = TP / (TP + FN) Precision is how many of your positive calls were right; recall, how many actual positives you caught. Raising one usually lowers the other.

F1 and F2 scores An F-score combines precision and recall into one number. F1, their harmonic mean, is the balanced one; F2 weights recall more.
F1 = 2 × precision × recall / (precision + recall) Fβ = (1 + β²) × precision × recall / (β² × precision + recall) Training, validation and test sets Split the data, for example 60/20/20:

One fixed split like this is a hold-out split. k-fold cross-validation instead divides the training data into k folds, trains k times holding out a different fold each time, and averages the scores.
Parameters vs hyperparameters The algorithm learns its parameters; you set its hyperparameters, such as polynomial degree, or the layers and neurons of a neural network. A bigger network needs more data and compute, so use the smallest that does the job. MLG 027 goes deeper.
Overfitting vs underfitting (bias and variance) • Underfitting (high bias): the model is too simple, like a straight line through curved data. More data alone won't fix it; a more flexible model or more features will.

Aim for the simplest model that fits.
Regularization Regularization reduces overfitting. It adds a penalty on large weights to the loss, which shrinks terms like high-degree polynomials, trading a little bias for less variance; too strong a penalty underfits. With an L2 penalty on linear regression, where λ is a hyperparameter:
J(θ) = cost(θ) + λ × Σ θj² Other ways to improve performance • Collect more data, which helps an overfit model.

What to learn next • Finish Andrew Ng's Machine Learning Specialization. Course 1, week 3 covers overfitting and regularization; Course 2, week 3 covers validation and test sets, bias and variance, and precision and recall.

More from Machine Learning Guide