MLG 015 Performance
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 Join the free MLG group: listen to my other AI shows, ask me questions, and talk with other listeners 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. Cancer screening wants high recall: a false alarm beats a missed case. A spam filter wants high precision: some spam in the inbox beats a real email in the spam folder. 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: Training set: the algorithm learns its parameters. Validation set: the midterm. Check the score, adjust hyperparameters, retrain. Test set: the final exam, used once at the end. 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. Overfitting (high variance): the model is too complex, like a polynomial through every training point. It does well in training and fails on new data. 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. Fill in missing values. Normalize features, such as bedrooms and distance in feet, to a common scale. 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. The Deep Learning book by Goodfellow, Bengio and Courville: chapter 5 for these basics, 7 for regularization, 11 for metrics. Start coding in Python with PyTorch, now the usual first framework. Next: MLG 016, on consciousness.
Embed this episode
No transcript yet.