1. Home
  2. Explore
  3. Computer Science
  4. Supervised Machine Learning

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Supervised Machine Learning

Speaker 1Speaker 2

Supervised Machine Learning

13:52
0:00-13:52
  1. Simon

    Welcome back. Today we're focusing on supervised machine learning, where the central goal is to use a data set of features, usually called X, to predict or identify an association with a response, called y.

  2. Corey

    And it helps to contrast that with unsupervised learning. In supervised learning, the response y is available during model development. In unsupervised learning, there is no y; instead, the goal is to discover signal or structure within the feature matrix X.

  3. Simon

    The two main supervised-learning settings are regression and classification. Regression predicts a quantitative response, such as blood pressure, cholesterol level, tumor size, or survival time. Classification predicts a categorical response, such as tumor versus normal tissue, heart disease versus no heart disease, or a disease subtype.

  4. Corey

    The important distinction is the type of the response, not the type of the predictors. Your feature matrix can contain quantitative or categorical measurements, but if y is quantitative, the problem is regression; if y is categorical, it is classification.

  5. Simon

    There are also other forms of supervised learning, such as predicting a survival time when some observations may be censored because a person died or left the study. But the main ideas from regression extend to these other quantitative-response settings, so we'll begin with regression.

  6. Corey

    A useful starting point is the linear model. Suppose we have n observations, and observation i has response y sub i and P features, written x sub i one through x sub i P. The model says that y sub i equals an intercept, beta naught, plus each feature multiplied by its coefficient, plus a noise term.

  7. Simon

    Written out, that is y sub i equals beta naught plus beta one times x sub i one, continuing through beta P times x sub i P, plus epsilon sub i. The unknown coefficients, beta naught through beta P, have to be estimated from the data. Estimating them is what we mean by fitting the model.

  8. Corey

    The classic way to fit this model is least squares. We choose coefficient estimates so that the sum of the squared differences between the observed responses and the model's fitted values is as small as possible. Those differences are residuals, and their squared sum is called the residual sum of squares, or the sum of squared errors.

  9. Simon

    Geometrically, with two predictors, the fitted linear model is a plane rather than a line. Each observation sits above or below that plane, and a vertical segment represents its residual, y sub i minus y-hat sub i. Least squares positions the plane so that the sum of the squared lengths of those vertical segments is minimized.

  10. Corey

    Least squares works especially well in a traditional setting with a large number of observations and only a few variables. But supervised machine learning asks a more important question than, 'How well does the model fit the data we already have?' It asks, 'How well will the model predict a new observation whose response is unknown?'

  11. Simon

    The data used to fit the model are called the training set. We can calculate the mean squared error on that same set by taking the residual sum of squares and dividing by the number of observations. That quantity is called the training error.

  12. Corey

    Training error is usually not the quantity we truly care about. Because the coefficients were chosen specifically to make the training error small, it will look favorable by construction. R-squared is closely related: as R-squared increases, training error decreases.

  13. Simon

    The deeper problem is that training error always decreases, or at least does not increase, when we add variables and make the model more complex. R-squared correspondingly always increases, or stays the same. With a sufficiently complex model, we can even achieve zero training error.

  14. Corey

    But a perfect fit to the training data can be useless for prediction. Imagine predicting survival time from gene-expression measurements. We already know the survival times of the patients used to train the model, so what matters is predicting survival for a new patient who enters the clinic next week.

  15. Simon

    That is why we evaluate test error. For observations not used to fit the model, we compare the actual response with the prediction produced by the training-set model, square those differences, and average them. A useful model is one with a small test error.

  16. Corey

    And test error behaves differently from training error as model complexity changes. Training error keeps falling as complexity increases, but test error typically falls only up to an intermediate level of complexity. After reaching its minimum, test error begins to rise because the model is overfitting.

  17. Simon

    A simple example makes that clear. With about twenty observations and one feature, a least-squares line may leave some points off the line, so its training error is not zero, but it can still generalize reasonably well. With only two observations, however, a line can fit both points perfectly, giving zero training error while making very poor predictions for additional observations.

  18. Corey

    So even a method that sounds simple, like least-squares linear regression, can be too complex for a very small data set. Complexity is not limited to the number of variables, either. The number of variables is one convenient measure in some settings, but complexity also depends on how flexible the fitting procedure is.

  19. Simon

    This leads to the bias-variance trade-off. Bias describes the average difference between the true coefficient and its estimated value across repeated experiments. More complex models generally have lower bias because they can capture more structure.

  20. Corey

    Variance describes how much the estimated coefficients would change across repeated experiments. More complex models generally have higher variance because they are more sensitive to the particular training data. Test error reflects a trade-off between squared bias and variance.

  21. Simon

    A very simple model has high bias and low variance, so it can systematically miss important patterns. An extremely complex model has low bias but high variance, so it can fit the training data while changing dramatically with new data. The desirable region is usually an intermediate complexity where both contributions are reasonably small.

  22. Corey

    To estimate test error, one option is the validation-set approach. Split the observations into two groups, fit the model on one group, and evaluate its error on the other. It's easy, but the estimate can depend on the particular arbitrary split.

  23. Simon

    Leave-one-out cross-validation addresses that instability by fitting the model n times. Each time, one observation is left out, the model is fit on the other n minus one observations, and the prediction error is measured on the one held-out observation. Averaging those n errors gives an estimate of test error.

  24. Corey

    The drawback is computational cost, especially when n is large, because we have to fit n models. K-fold cross-validation is often preferred. For five-fold cross-validation, for example, we divide the observations into five groups, train on four groups, test on the fifth, repeat until every group has been held out, and average the five error estimates.

  25. Simon

    The specific choice among a validation set, leave-one-out cross-validation, and k-fold cross-validation can depend on the situation. The essential point is to estimate performance on data not used for fitting, rather than selecting a model merely because it has a small training error.

  26. Corey

    Biomedical big data creates a particular challenge: there may be far more features than observations. Predictors might include expression levels for twenty thousand genes, large numbers of proteins, or DNA-sequencing measurements. In that setting, ordinary least squares can fit a highly flexible model with excellent training error but poor test error.

  27. Simon

    A model with low training error and high test error has overfit the data. Two important alternatives to least squares are ridge regression and the lasso. Both are regularization, or penalization, approaches that shrink coefficients and thereby control model complexity.

  28. Corey

    Ridge regression minimizes the residual sum of squares plus a penalty equal to lambda times the sum of the squared coefficients. Lambda is a nonnegative tuning parameter. When lambda is zero, ridge regression becomes ordinary least squares; as lambda increases, the coefficients are pushed closer to zero.

  29. Simon

    You can think of ridge regression as balancing two goals: fitting the training data well and keeping the model from becoming too complex. With a very large lambda, the coefficients become tiny, producing a low-variance but potentially high-bias model. The useful value of lambda is normally selected by estimating test error.

  30. Corey

    One limitation is that ridge regression does not set coefficients exactly equal to zero. Even with strong shrinkage, all the variables remain in the final model, although their coefficients may be extremely small. That can be inconvenient when a practical diagnostic or predictor should use only a small subset of thousands of measurements.

  31. Simon

    The lasso changes the penalty from the sum of squared coefficients to the sum of the absolute values of the coefficients. That small mathematical change has an important consequence: lasso can set some coefficients exactly to zero. Therefore, it produces a sparse model and performs feature selection.

  32. Corey

    As with ridge regression, lambda controls the lasso's complexity. At lambda equal to zero, it reduces to least squares. For an intermediate lambda, perhaps only four of twenty thousand features have nonzero coefficients; with a stronger penalty, perhaps only one remains. The appropriate lambda is chosen using an estimate of test error.

  33. Simon

    Principal components regression offers another route to a less complex linear model. The original observations live in a P-dimensional feature space, but some dimensions may be redundant because features are highly correlated, while others may be uninformative noise.

  34. Corey

    Principal components regression creates new predictors, called principal components, as linear combinations of the original features. These components are chosen to capture as much variability in the feature data as possible. We then fit a least-squares model using only the first m components instead of all P original predictors.

  35. Simon

    If m equals P, principal components regression is essentially back to least squares. If m is smaller than P, the model is less complex. But this method does not perform feature selection: all the original predictors can still contribute to the components and therefore to the final model.

  36. Corey

    There is also a limitation. The components that explain the most variation in X are not guaranteed to be the components most predictive of y. Principal components regression can work well, but it can fail when the major directions of variation in the features do not carry much information about the response. Partial least squares is a similar type of dimension-reduction approach.

  37. Simon

    Sometimes the problem is the opposite: least squares may be too simple. If there are only a dozen measured features and twenty thousand observations, we can make the model more complex by adding transformations such as x sub j squared, x sub j cubed, or an exponential transformation, as well as products such as x sub j times x sub k.

  38. Corey

    Those transformed or combined features can then be used with least squares, ridge regression, or the lasso. But whenever we increase flexibility, we still have to estimate test error. A more complex model is not automatically better.

  39. Simon

    The same broad ideas apply to classification. The response is categorical rather than quantitative, but we still need to control model complexity, distinguish training performance from performance on new observations, and estimate out-of-sample error.

  40. Corey

    Another supervised-learning approach is the decision tree. Instead of fitting one global linear equation, a tree partitions the range of the features into regions, or boxes, and makes a prediction within each region.

  41. Simon

    For a regression tree predicting baseball-player salaries, you might first ask whether a player has been playing for fewer than four and a half years. A yes answer sends you left and a no answer sends you right. Additional questions about hits, runs, walks, or years of experience lead to a terminal region, where the prediction is the average response of the observations in that region.

  42. Corey

    In the example, salary was modeled on a logarithmic scale, so a terminal value such as 5.183 represents a salary obtained by calculating e to the 5.183 and multiplying by one thousand. Modeling salary on a log scale was described as preferable to modeling it directly on a linear scale.

  43. Simon

    Decision trees are attractive because they are highly interpretable. A tree can be displayed as a diagram that someone can follow without working through the underlying mathematics, which could be useful in an emergency room or at a nurse's station.

  44. Corey

    The trade-off is predictive accuracy. Large trees tend to overfit, giving low bias and high variance, while small trees can underfit, giving low variance but potentially high bias. We choose the tree size by estimating test error, just as we choose complexity for the other methods.

  45. Simon

    There is one final issue that can undermine even sophisticated machine learning: experimental design. In biomedical data, batch effects occur when variability comes from nonbiological factors. For example, measurements may differ because of processing conditions, laboratories, or other aspects of how the data were collected.

  46. Corey

    Good design can help prevent batch effects. Sample run times should be randomized, rather than running all cases first and all controls later, and researchers should reduce extraneous sources of variation. It is also generally better to fit models using multiple data sets collected in different laboratories or institutions than to rely on one data set.

  47. Simon

    Most importantly, findings should be validated on independent data collected in a different laboratory or institution. Batch effects can make a model look successful, even on an apparently favorable test set, while performance collapses on truly independent data.

  48. Corey

    So there is no single best supervised-learning method. Different approaches can work better in different situations, and many methods exist beyond the ones we've discussed. But although no method is universally best, some procedures are definitely wrong—for example, performing cross-validation incorrectly and then trusting an invalid test-error estimate.

  49. Simon

    The core lesson is simple: prioritize test error. Training error and R-squared can reward unnecessary complexity, while the real goal is reliable prediction for new observations. Choose model complexity, tuning parameters, and even among different model types by carefully estimating out-of-sample performance, and validate important results on genuinely independent data.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent