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

Supervised Machine Learning: Models, Complexity, and Test Error

Supervised machine learning is a framework for using observed data to predict an associated response. The central goal is not merely to describe data that have already been collected, but to make useful predictions for new observations whose responses are unknown.

A supervised-learning problem contains:

  • A set of input measurements, usually represented by a data matrix XXX
  • A response or outcome, represented by yyy
  • A model that learns the relationship between XXX and yyy
  • A method for evaluating how well the model predicts new data

For example, a biomedical study might use gene-expression measurements, protein levels, or DNA-sequencing results to predict a patient’s blood pressure, tumor size, disease status, or survival time.

Supervised and Unsupervised Learning

Machine learning is commonly divided into two broad categories.

In supervised learning, the response yyy is available during model training. The model examines both the predictors in XXX and the known responses in yyy to learn an association that can later be used for prediction.

In unsupervised learning, no response yyy is provided. Instead, the goal is to discover patterns or signals within the data matrix XXX itself. For example, an unsupervised method might search for groups of similar observations or summarize many variables using a smaller number of dimensions.

This lesson focuses on supervised learning.

Supervised learning uses known responses to learn how input features relate to an outcome that must later be predicted for new observations.

Regression and Classification

The two main forms of supervised learning are regression and classification. The distinction depends entirely on the type of response variable yyy, not on the type of predictors in XXX.

Regression

Regression is used when the response is quantitative, meaning that it has numerical values on which arithmetic comparisons make sense.

Examples include predicting:

  • Blood pressure
  • Cholesterol level
  • Tumor size
  • Survival time
  • A patient’s response to chemotherapy

If yyy is quantitative, the problem is a regression problem even if some or all of the predictors are categorical.

Classification

Classification is used when the response is categorical or qualitative.

Examples include predicting:

  • Tumor tissue versus normal tissue
  • Heart disease versus no heart disease
  • One disease subtype versus another
  • A positive versus negative diagnostic result

The predictors can be numerical, categorical, or a mixture of both. Classification is still classification because the response is categorical.

Other supervised-learning settings exist. For example, predicting a survival time may require special treatment when the time is censored, meaning that the exact event time is unknown because a person left the study or because the study ended before the event occurred. Nevertheless, many of the central ideas from regression—especially model complexity and test error—still apply.

Regression predicts a quantitative response; classification predicts a categorical response. The nature of the predictors does not determine this distinction.

Think About It

If a study uses categorical variables such as sex and treatment group to predict a numerical cholesterol level, is the problem regression or classification? The answer depends on the response: it is regression because cholesterol level is quantitative.

Linear Models for Regression

A particularly flexible framework for regression is the linear model. In many supervised-learning applications, a large portion of the essential reasoning can be understood through linear models.

Suppose there are nnn observations and PPP features. For observation iii:

  • The response is yiy_iyi​
  • The features are xi1,xi2,…,xiPx_{i1}, x_{i2}, \ldots, x_{iP}xi1​,xi2​,…,xiP​

A linear model represents the response as

yi=β0+β1xi1+β2xi2+⋯+βPxiP+ϵi.y_i = \beta_0 + \beta_1x_{i1} + \beta_2x_{i2} + \cdots + \beta_Px_{iP} + \epsilon_i.yi​=β0​+β1​xi1​+β2​xi2​+⋯+βP​xiP​+ϵi​.

Here:

  • β0\beta_0β0​ is the intercept
  • β1,…,βP\beta_1,\ldots,\beta_Pβ1​,…,βP​ are coefficients
  • ϵi\epsilon_iϵi​ is the noise associated with observation iii

The coefficients describe how the predicted response changes as the features change. The intercept is the model’s baseline value, while each coefficient determines the contribution of one feature after accounting for the others.

The coefficients are unknown, so the model must be fit to the data. Fitting means choosing coefficient estimates, written with hats:

β^0,β^1,…,β^P.\hat{\beta}_0,\hat{\beta}_1,\ldots,\hat{\beta}_P.β^​0​,β^​1​,…,β^​P​.

Least Squares

The traditional method for fitting a linear model is least squares. The fitted value for observation iii is

y^i=β^0+β^1xi1+⋯+β^PxiP.\hat{y}_i = \hat{\beta}_0 + \hat{\beta}_1x_{i1} + \cdots + \hat{\beta}_Px_{iP}.y^​i​=β^​0​+β^​1​xi1​+⋯+β^​P​xiP​.

The difference between the actual response and the fitted response is the residual:

yi−y^i.y_i-\hat{y}_i.yi​−y^​i​.

Least squares chooses the coefficient estimates that minimize the residual sum of squares, also called the sum of squared errors:

RSS⁡=∑i=1n(yi−y^i)2.\operatorname{RSS} = \sum_{i=1}^{n}(y_i-\hat{y}_i)^2.RSS=i=1∑n​(yi​−y^​i​)2.

The squaring serves two purposes. It prevents positive and negative errors from canceling each other, and it gives greater weight to large errors. The fitted model is therefore the line, plane, or higher-dimensional linear surface that makes the total squared discrepancy as small as possible.

With one predictor, the least-squares fit is a line. With two predictors, it is a plane. With many predictors, it is a hyperplane in a higher-dimensional space.

For a model with two predictors, each observation can be pictured as a point above or below the fitted plane. The vertical distance from the point to the plane is its residual. Least squares positions the plane so that the sum of the squared vertical distances is minimized.

Least squares often works well when the number of observations nnn is large and the number of features PPP is small. However, it can perform poorly when there are many features relative to the available observations.

Training Error Versus Test Error

The machine-learning perspective distinguishes sharply between performance on data used to fit a model and performance on new data.

Training Data and Training Error

The training set is the data used to estimate the model’s coefficients. The model’s mean squared error on this data is

MSE⁡training=1n∑i=1n(yi−y^i)2.\operatorname{MSE}_{\text{training}} = \frac{1}{n} \sum_{i=1}^{n}(y_i-\hat{y}_i)^2.MSEtraining​=n1​i=1∑n​(yi​−y^​i​)2.

This is called the training error.

Least squares deliberately chooses the coefficients to make the training error small. Therefore, a small training error is not surprising. It is partly a consequence of the fitting procedure itself.

The coefficient of determination, commonly called R2R^2R2, is closely related to training error. A larger R2R^2R2 generally corresponds to a smaller training error. However, neither quantity directly measures how well the model will predict new observations.

Adding more variables to a model will always make the training error decrease or remain unchanged. Correspondingly, R2R^2R2 will increase or remain unchanged. This happens because the larger model has more flexibility to adapt to the existing training observations.

If enough variables or flexibility are added, a model can achieve a training error of zero. It can pass exactly through every training observation. That does not mean that the model has learned the true underlying relationship.

Test Error

The real goal is usually to predict the response for a new observation. A test set consists of observations that were not used to fit the model.

For a test observation, the prediction is y^test\hat{y}_{\text{test}}y^​test​, while the actual response is ytesty_{\text{test}}ytest​. The squared prediction error is

(ytest−y^test)2.(y_{\text{test}}-\hat{y}_{\text{test}})^2.(ytest​−y^​test​)2.

Averaging this quantity over many test observations gives the test error:

MSE⁡test=1ntest∑(ytest−y^test)2.\operatorname{MSE}_{\text{test}} = \frac{1}{n_{\text{test}}} \sum \left(y_{\text{test}}-\hat{y}_{\text{test}}\right)^2.MSEtest​=ntest​1​∑(ytest​−y^​test​)2.

A useful model is one with a small test error. The purpose of supervised learning is therefore not to obtain the smallest possible training error, but to obtain predictions that remain accurate beyond the training data.

For instance, if a model predicts survival time using gene-expression measurements, the survival times of the training patients are already known. Perfectly predicting those patients is not the important challenge. The important challenge is predicting survival for a new patient entering the clinic.

Overfitting

Overfitting occurs when a model learns the training data too closely, including accidental patterns or noise that do not generalize to new observations.

An overfit model typically has:

  • Very small training error
  • Large test error
  • Excessive complexity relative to the available data

Training error can therefore give a misleading impression of success. As model complexity increases, training performance improves continuously, but test performance usually improves only up to a point.

The typical pattern is:

  1. A very simple model has high training error and high test error.
  2. Increasing complexity improves both training and test performance.
  3. At an intermediate complexity, test error reaches its minimum.
  4. Further complexity continues to reduce training error but causes test error to rise.

The optimal model is usually found near the point where test error is smallest—not where training error is smallest.

A Small Example

Imagine a dataset with one predictor and one response.

With about twenty observations, a straight-line model may leave some points above or below the line, creating a nonzero training error. However, the relationship may still be represented reasonably well, so the model may have a modest test error.

Now imagine fitting a line using only two observations. A line can pass exactly through both points, giving a training error of zero. Yet the line may be a poor representation of the broader relationship. New observations generated from the same process may fall far from the line.

This example shows why a simple-looking model can still overfit when the amount of data is extremely small. Complexity is always relative to the amount of information available.

Think About It

Why can adding a predictor improve R2R^2R2 while making the model worse for future predictions? The added predictor gives the model more flexibility, so it can fit the training data better, but it may also allow the model to learn noise rather than a pattern that generalizes.

Model Complexity and the Bias–Variance Trade-Off

Model complexity describes how flexible a model is. The number of variables is one possible measure, but it is not a universal definition.

Two models may use the same number of predictors while having different complexity. For example, ridge regression can use all PPP predictors while shrinking their coefficients so strongly that the resulting model is relatively simple. Thus, complexity depends on how the model uses the variables, not only on how many variables appear in its formula.

As complexity increases:

  • Training error decreases or stays the same
  • Bias generally decreases
  • Variance generally increases
  • Test error may first decrease and then increase

Bias

In this context, bias describes systematic error. It is the average difference between an estimated quantity and the true quantity across repeated experiments.

A highly restricted model may be unable to represent the underlying relationship. Such a model has high bias because its predictions are systematically limited by its oversimplified structure.

As model complexity increases, bias generally decreases. A more flexible model can represent a wider range of relationships.

Variance

Variance describes how much the fitted model changes across different samples of data.

A highly flexible model can respond strongly to small changes in the training observations. If the training set changes slightly, the estimated coefficients or predictions may change substantially. Such a model has high variance.

As model complexity increases, variance generally increases.

The Trade-Off

Test error reflects both bias and variance. In simplified form, the key relationship is

test error≈bias2+variance.\text{test error} \approx \text{bias}^2+\text{variance}.test error≈bias2+variance.

A very simple model has high bias but low variance. A very complex model has low bias but high variance. Neither extreme is desirable.

The goal is to find an intermediate level of complexity in which both terms are reasonably small. This is the bias–variance trade-off.

The trade-off explains why the most flexible model is not automatically the best model. A model should be flexible enough to capture the important signal, but constrained enough to avoid fitting random variation.

Estimating Test Error

In practice, a separate, permanently labeled test set may not be available. Several methods can estimate how well a model will perform on unseen data.

Validation-Set Approach

The validation-set approach divides the available observations into two groups:

  1. A training set used to fit the model
  2. A validation set used to evaluate its prediction error

The validation error is then used as an estimate of test error.

This method is simple and easy to implement. Its weakness is that the result depends on one arbitrary split. A different split could produce a different estimate because the two groups would contain different observations.

Leave-One-Out Cross-Validation

In leave-one-out cross-validation, one observation is held out at a time.

For nnn observations:

  1. Fit the model using observations 222 through nnn.
  2. Predict observation 111 and record its error.
  3. Fit the model using all observations except observation 222.
  4. Predict observation 222 and record its error.
  5. Continue until every observation has been held out once.
  6. Average the nnn errors.

Each observation serves once as a test observation and n−1n-1n−1 times as a training observation.

This approach uses the data systematically and avoids depending on one arbitrary split. Its disadvantage is computational cost: the model must be fit nnn separate times. When nnn is very large, this can be impractical.

kkk-Fold Cross-Validation

In kkk-fold cross-validation, the observations are divided into kkk groups, called folds.

For each fold:

  1. Train the model on the other k−1k-1k−1 folds.
  2. Evaluate the model on the held-out fold.
  3. Record the prediction error.

After all kkk folds have served as the held-out group, the errors are averaged:

cross-validation error=1k∑r=1kerror in fold r.\text{cross-validation error} = \frac{1}{k} \sum_{r=1}^{k} \text{error in fold }r.cross-validation error=k1​r=1∑k​error in fold r.

For example, with five-fold cross-validation, the data are divided into five groups. The model is trained four times? Actually, it is trained once for each held-out fold, so it is fit five times in total. Each time, four folds are used for training and the remaining fold is used for evaluation.

kkk-fold cross-validation provides a compromise between the simplicity of a validation split and the thoroughness of leave-one-out cross-validation.

These approaches can be used not only to estimate test error, but also to select model complexity or tuning parameters. The central rule remains the same: a model should be selected based on estimated performance on unseen data.

Training error measures how well a model fits known data. Test error estimates how well it will predict unknown data. Model selection should focus on the second quantity.

Regularization for High-Dimensional Data

Biomedical datasets often contain many more features than traditional datasets. A study might attempt to predict a patient’s chemotherapy response using:

  • Expression levels for thousands of genes
  • Measurements of a large number of proteins
  • DNA-sequencing results from many potentially relevant genes

When the number of features PPP is large relative to the number of observations nnn, ordinary least squares can overfit badly. It may achieve an excellent training fit but perform poorly on new observations.

Regularization, also called penalization, modifies the fitting process by discouraging overly complex coefficient estimates. Two important regularization methods are ridge regression and the lasso.

Ridge Regression

Ridge regression chooses coefficients by minimizing the usual residual sum of squares plus a penalty on the squared coefficients:

min⁡β0,…,βP{∑i=1n(yi−β0−∑j=1Pβjxij)2+λ∑j=1Pβj2}.\min_{\beta_0,\ldots,\beta_P} \left\{ \sum_{i=1}^{n} \left( y_i-\beta_0-\sum_{j=1}^{P}\beta_jx_{ij} \right)^2 + \lambda\sum_{j=1}^{P}\beta_j^2 \right\}.β0​,…,βP​min​⎩⎨⎧​i=1∑n​(yi​−β0​−j=1∑P​βj​xij​)2+λj=1∑P​βj2​⎭⎬⎫​.

The parameter λ\lambdaλ is a nonnegative tuning parameter.

The first term rewards a good fit to the training data. The second term penalizes large coefficients and therefore discourages excessive complexity.

Effect of λ\lambdaλ

  • If λ=0\lambda=0λ=0, the penalty disappears and ridge regression becomes least squares.
  • As λ\lambdaλ increases, the coefficients are pushed closer to zero.
  • If λ\lambdaλ becomes extremely large, the coefficients approach zero.

The intercept is generally not part of the penalty in the formulation above. The penalty applies to the feature coefficients β1,…,βP\beta_1,\ldots,\beta_Pβ1​,…,βP​.

Ridge regression lowers variance by preventing the coefficients from becoming excessively large. It may increase bias slightly, but the resulting reduction in variance can lower test error.

The tuning parameter should be selected using validation or cross-validation. After selecting the value of λ\lambdaλ that produces the smallest estimated test error, ridge regression is refit using the full dataset and that chosen value of λ\lambdaλ.

Ridge Regression and Feature Inclusion

Ridge regression shrinks coefficients, but it generally does not make them exactly zero. Therefore, even when the penalty is strong, the final model usually includes all PPP variables, each with a possibly very small coefficient.

This is useful when many variables may contribute modestly to prediction. It is less useful when the goal is to produce a compact model involving only a small number of features.

Think About It

Why can ridge regression be considered less complex even though it includes all the variables? Complexity is influenced by the size and behavior of the coefficients. Strong shrinkage makes the model less sensitive to the predictors, reducing variance even when every variable remains formally included.

The Lasso

The lasso is similar to ridge regression, but it uses absolute values rather than squared coefficients in its penalty:

min⁡β0,…,βP{∑i=1n(yi−β0−∑j=1Pβjxij)2+λ∑j=1P∣βj∣}.\min_{\beta_0,\ldots,\beta_P} \left\{ \sum_{i=1}^{n} \left( y_i-\beta_0-\sum_{j=1}^{P}\beta_jx_{ij} \right)^2 + \lambda\sum_{j=1}^{P}|\beta_j| \right\}.β0​,…,βP​min​⎩⎨⎧​i=1∑n​(yi​−β0​−j=1∑P​βj​xij​)2+λj=1∑P​∣βj​∣⎭⎬⎫​.

The difference between the two methods is the penalty:

  • Ridge regression uses ∑j=1Pβj2\sum_{j=1}^{P}\beta_j^2∑j=1P​βj2​
  • The lasso uses ∑j=1P∣βj∣\sum_{j=1}^{P}|\beta_j|∑j=1P​∣βj​∣

Although this difference appears small, it has an important consequence. Ridge regression typically shrinks coefficients close to zero without making them exactly zero. The lasso can make some coefficients exactly zero.

A coefficient equal to zero means that the corresponding feature does not appear in the fitted model. Thus, the lasso performs feature selection and produces a sparse model.

Effect of λ\lambdaλ in the Lasso

  • When λ=0\lambda=0λ=0, the lasso becomes least squares.
  • With an intermediate value of λ\lambdaλ, some coefficients may be exactly zero.
  • With a larger value of λ\lambdaλ, more coefficients may be eliminated.
  • With an extremely large value of λ\lambdaλ, all feature coefficients may become zero.

For example, if a lasso model is applied to 20,00020{,}00020,000 gene-expression features, it might retain only four features at one value of λ\lambdaλ, or only one feature at a larger value. The chosen value should be the one supported by estimated test performance, not simply the one producing the smallest number of variables.

The lasso is especially attractive when interpretability, cost, or clinical practicality requires a small set of predictors. A diagnostic based on a handful of genes may be easier and less expensive to implement than one requiring measurements of thousands of genes.

Principal Components Regression

Principal components regression, or PCR, reduces complexity in a different way.

Suppose the original data have PPP predictors. The observations can be viewed as points in a PPP-dimensional space. However, not every dimension is equally useful:

  • Some dimensions may be redundant because predictors are highly correlated.
  • Some dimensions may contain mostly noise.
  • A smaller number of dimensions may capture most of the meaningful variation in the predictors.

PCR creates new variables called principal components. Each principal component is a linear combination of the original predictors. In general, a component can be written as

zm=∑j=1Pϕjmxj,z_m = \sum_{j=1}^{P} \phi_{jm}x_j,zm​=j=1∑P​ϕjm​xj​,

where the coefficients ϕjm\phi_{jm}ϕjm​ determine how the original predictors are combined.

The first principal component is the direction in feature space along which the data vary the most. Subsequent components capture additional variation while representing new directions.

PCR then fits a least-squares regression using only the first mmm principal components:

y=α0+α1z1+⋯+αmzm+ϵ.y = \alpha_0+\alpha_1z_1+\cdots+\alpha_mz_m+\epsilon.y=α0​+α1​z1​+⋯+αm​zm​+ϵ.

The number of components mmm controls model complexity:

  • If m=Pm=Pm=P, PCR returns to a model equivalent in complexity to least squares using all predictor dimensions.
  • If m<Pm<Pm<P, PCR uses a lower-dimensional representation and is less complex.

Although PCR fits a model using the components, the final model is still linear in the original predictors because the components themselves are linear combinations of those predictors.

PCR does not perform feature selection in the same way as the lasso. Every original predictor can contribute to the retained components, so all original variables may remain involved in the final model.

A Limitation of PCR

The principal components are selected to explain variation in the predictors, not necessarily to predict the response. A direction that explains a great deal of variation in XXX may have little relationship to yyy. Therefore, the first few principal components may not be the most predictive components.

PCR can work well when the main directions of variation in the predictors are also related to the response, but it can fail when predictive information lies in a direction with relatively little overall variation.

PCR is closely related mathematically to ridge regression, although the two methods control complexity differently.

Making a Model More Complex

Sometimes least squares is too complex, as in high-dimensional biomedical data. In other settings, least squares may be too simple.

A model can be made more flexible by adding transformed or combined features, such as

xj2,xj3,exj,x_j^2,\qquad x_j^3,\qquad e^{x_j},xj2​,xj3​,exj​,

or interactions such as

xjxk.x_jx_k.xj​xk​.

The resulting model can still be fit using least squares, ridge regression, or the lasso. The important point is that adding transformations or interactions increases the space of relationships the model can represent.

However, a more complex model must still be evaluated using test error or a suitable estimate of test error. Greater flexibility is useful only if it improves prediction for new observations.

Classification and Other Supervised-Learning Problems

The central ideas described for regression also apply to classification.

Although the response in classification is categorical rather than quantitative, the same issues remain important:

  • Training performance can be misleading.
  • More complex models can overfit.
  • The model must be evaluated on held-out or otherwise unseen data.
  • Bias and variance must be balanced.
  • Cross-validation can help estimate test performance and choose model complexity.

The same general reasoning also extends to other response types, including survival outcomes and censored survival times.

Decision Trees

A decision tree is a different type of supervised-learning method. Rather than describing the response with one global equation, a tree repeatedly divides the predictor space into regions and assigns a prediction within each region.

The process can be understood as a sequence of questions. Each question splits the observations according to a predictor and a threshold.

For example, a tree predicting baseball-player salary might ask:

  1. Has the player been playing for fewer than four and a half years?
  2. Did the player record fewer than a specified number of runs?
  3. Did the player have more or fewer than a specified number of hits or walks?

A “yes” answer follows one branch, and a “no” answer follows another. Eventually, the path reaches a terminal region, where the tree produces a prediction.

How a Regression Tree Produces Predictions

Suppose the predictor space is divided into regions R1R_1R1​, R2R_2R2​, and R3R_3R3​. For each region, the prediction is the average response among the training observations that fall inside that region:

y^Rm=1∣Rm∣∑i:xi∈Rmyi.\hat{y}_{R_m} = \frac{1}{|R_m|} \sum_{i:x_i\in R_m}y_i.y^​Rm​​=∣Rm​∣1​i:xi​∈Rm​∑​yi​.

Thus, a regression tree predicts a constant value within each region. The tree’s structure determines which observations belong to which region, and the average response determines the prediction inside that region.

A tree is highly interpretable because the prediction can be traced through a sequence of understandable decisions.

Log-Scale Responses

A tree may model salary on a logarithmic scale rather than directly in dollars. If a terminal-node prediction is 5.1835.1835.183 on the log scale and the logarithm is natural, the corresponding salary in thousands of dollars is

e5.183.e^{5.183}.e5.183.

The salary in dollars is then

1000e5.183.1000e^{5.183}.1000e5.183.

Modeling salary on a log scale can be more appropriate than modeling it directly on a linear scale, especially when salaries vary substantially in magnitude.

Tree Size and Overfitting

A large tree has many splits and terminal regions. It can closely match the training observations, resulting in low bias but high variance. Small changes in the training data may produce a very different large tree.

A small tree is more stable and has lower variance, but it may be too limited to represent the underlying relationship, resulting in higher bias.

Therefore:

  • A very large tree may overfit.
  • A very small tree may underfit.
  • The preferred tree size is selected using estimated test error.

Decision trees are typically less accurate than some other supervised-learning methods, but their interpretability is a major advantage. A tree can be displayed as a diagram that someone can follow without understanding the underlying mathematical optimization.

For that reason, trees are valuable when a quick, transparent decision process is more important than achieving the absolute best predictive accuracy. If interpretability is unimportant, another method may provide better accuracy.

Think About It

What is the main reason to choose a decision tree? The strongest reason is interpretability: the model presents its predictions as a sequence of visible, understandable decisions.

Experimental Design and Batch Effects

Sophisticated machine-learning methods cannot compensate for poor experimental design.

A major issue in biomedical and biological data is the presence of batch effects. A batch effect is variability caused by nonbiological factors rather than by the biological differences being studied.

Possible sources include differences in:

  • When samples are processed
  • Which laboratory performs the measurements
  • Which institution collects the data
  • How samples are run or handled

Batch effects can make unrelated groups appear different. For example, if all disease cases are processed in one batch and all controls in another, the model may learn the batch difference rather than the biological disease signal.

Reducing Batch Effects

Good experimental design is the first defense against batch effects.

Important practices include:

  • Randomizing when samples are run
  • Avoiding a design in which all cases are processed first and all controls afterward
  • Reducing unnecessary sources of variation
  • Combining data from multiple laboratories or institutions when appropriate
  • Validating findings on independent datasets

Independent validation is especially important. A model may appear to have low test error when its test data share the same hidden batch structure as its training data. A genuinely independent dataset collected in a different laboratory or institution provides a stronger test of whether the result generalizes.

A model can therefore have apparently good test performance and still fail in real use if the evaluation data contain the same confounding batch effects as the training data.

Distributional Assumptions and the Curse of Dimensionality

Normality, or Gaussianity, is often emphasized in introductory statistics, particularly regarding the distribution of model errors. However, modest deviations from normally distributed errors are often not the central difficulty, especially when the sample size is large.

The more serious problem arises when the available sample size is small relative to:

  • The number of features
  • The complexity of the model
  • The number of possible relationships being considered

This problem is often called the curse of dimensionality. As the number of dimensions and possible model structures grows, it becomes easier for a model to find patterns that occur by chance in the training data.

More measured variables do not automatically create more useful information. They may instead encourage the fitting of a more complex model, which can increase variance and test error.

The essential question is therefore not whether the data are perfectly Gaussian, nor whether the model contains many variables. The essential question is whether the model predicts new data accurately.

Model Complexity, Degrees of Freedom, and Model Comparison

For ordinary least squares, model complexity can often be summarized by counting the number of predictors. A least-squares model with ten predictors uses approximately ten degrees of freedom in this sense.

For regularized and nonlinear methods, this simple count is no longer adequate.

A ridge-regression model formally includes all PPP predictors regardless of the tuning parameter, but a strongly penalized ridge model may behave much more simply than an unpenalized least-squares model. Similarly, the complexity of a lasso model depends not only on how many predictors remain, but also on the penalty and the resulting fitted behavior. Decision-tree complexity depends on the size and structure of the tree.

Because complexity is difficult to compare directly across fundamentally different methods, test error provides a universal comparison. A ridge model, lasso model, PCR model, and decision tree can all be compared by asking which produces the smallest error on appropriately held-out data.

Information-based measures and degrees-of-freedom calculations can be useful in some contexts, but for predictive supervised learning, estimated test error directly addresses the practical objective.

No Single Best Supervised-Learning Method

There is no universally best supervised-learning approach. Different methods may perform better under different data structures and scientific goals.

For example:

  • Ridge regression is useful when many variables may contribute and coefficient shrinkage is desirable.
  • The lasso is useful when feature selection and sparsity are important.
  • PCR is useful when a lower-dimensional representation captures relevant structure.
  • Decision trees are useful when transparent, rule-based predictions are needed.
  • More flexible models may be useful when the relationship is not well represented by a simple linear form.

Although no method is always best, methods can still be used incorrectly. A cross-validation procedure can be implemented improperly, causing test-error estimates to be misleading. A model may then be selected using an inaccurate estimate of its generalization performance.

The crucial standard is therefore not loyalty to one algorithm. It is careful evaluation of whether the method has been applied correctly and whether its predictions generalize.

Comprehensive Review

Supervised machine learning learns a relationship between features XXX and a known response yyy so that the response can be predicted for new observations.

The response determines the main type of problem:

  • Quantitative response: regression
  • Categorical response: classification
  • Censored survival response: a related specialized supervised-learning setting

Linear models express the response as a combination of predictors and coefficients. Least squares estimates those coefficients by minimizing the residual sum of squares:

∑i=1n(yi−y^i)2.\sum_{i=1}^{n}(y_i-\hat{y}_i)^2.i=1∑n​(yi​−y^​i​)2.

However, the smallest training error is not the true objective. Training error usually decreases as model complexity increases, even when the model is learning noise. The important quantity is test error, which measures prediction performance on observations not used to fit the model.

The central bias–variance trade-off explains why test error often has a minimum at an intermediate level of complexity:

test error≈bias2+variance.\text{test error} \approx \text{bias}^2+\text{variance}.test error≈bias2+variance.

Validation sets, leave-one-out cross-validation, and kkk-fold cross-validation estimate test error and help select model complexity or tuning parameters.

When least squares is too complex for high-dimensional data, regularization can improve generalization:

  • Ridge regression shrinks coefficients toward zero but usually retains all variables.
  • The lasso can shrink some coefficients exactly to zero, performing feature selection.
  • Principal components regression replaces the original predictors with a smaller number of principal components, reducing dimensionality without necessarily eliminating individual original features.

When a model needs greater flexibility, transformed predictors and interactions can be added, but their value must still be judged by test error.

Decision trees partition predictor space into regions and make an average prediction within each region. Their main advantage is interpretability, although they often sacrifice some predictive accuracy compared with other methods. Tree size must also be controlled to avoid overfitting.

Finally, machine learning cannot replace sound scientific design. Batch effects and other nonbiological sources of variation can create apparently predictive patterns that fail outside the original dataset. Randomization, reduction of extraneous variation, multi-site data, and independent validation are essential protections.

The most important principle is that a model is valuable only when it predicts new data accurately. Low training error, high R2R^2R2, a large number of features, or a sophisticated algorithm cannot substitute for genuinely low and correctly estimated test error.

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent