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

1. Machine Learning: Supervised and Unsupervised Learning

Machine learning methods generally fall into two broad categories:

Supervised learning

Supervised learning uses a data set of predictors or features, represented by XXX, to predict or identify an association with a known response, represented by YYY.

A supervised learning data set contains:

  • Predictors/features (XXX): measured characteristics used to make predictions.

  • Response (YYY): the outcome that the model attempts to predict.

  • Observations: individual subjects, samples, patients, or other units for which both predictors and responses may be available during model training.

Examples include using:

  • Biomarker measurements to predict blood pressure.

  • Gene expression to predict survival time.

  • Patient characteristics to predict response to chemotherapy.

  • Clinical measurements to determine whether tissue is normal or cancerous.

Unsupervised learning

Unsupervised learning attempts to discover patterns or signal in a feature matrix XXX when no response variable YYY is available.

The goal is not to predict a known outcome, but to identify structure within the predictors. Examples include finding:

  • Groups or clusters of similar observations.

  • Lower-dimensional representations of high-dimensional data.

  • Major directions of variation in the features.

Regression, classification, and other supervised methods rely on a response variable, whereas unsupervised methods do not.


2. Main Types of Supervised Learning

The two primary forms of supervised learning are regression and classification. The distinction depends entirely on the type of response variable YYY, not on the type of predictor matrix XXX.

Regression

Regression predicts a quantitative response.

Examples of quantitative responses include:

  • Blood pressure.

  • Cholesterol level.

  • Tumor size.

  • Patient survival time.

  • Salary.

  • Drug concentration.

A response is treated as quantitative when it has numerical magnitude and arithmetic comparisons are meaningful.

Classification

Classification predicts a categorical or qualitative response.

Examples include:

  • Tumor versus normal tissue.

  • Heart disease versus no heart disease.

  • One disease subtype versus another.

  • Treatment responder versus nonresponder.

  • Several possible diagnostic categories.

A categorical response places an observation into one of a set of classes.

The predictors can have any data type

The type of supervised learning is determined by YYY:

  • Quantitative YYY: regression.

  • Categorical YYY: classification.

The features in XXX may themselves be quantitative, categorical, or a mixture of both. Quantitative predictors do not automatically imply regression, and categorical predictors do not automatically imply classification.

Other supervised-learning responses

Some responses require specialized methods. For example, survival analysis models a survival time that may be censored because:

  • A participant dies during the study.

  • A participant leaves the study.

  • The study ends before the event occurs.

  • The event time is unknown beyond the last observation.

Although survival analysis has additional complications, many central ideas from regression—especially model complexity, overfitting, and test-error evaluation—still apply.


3. Linear Models for Regression

A linear model provides a flexible framework for predicting a quantitative response. It is one of the most widely used approaches in supervised learning.

Suppose there are:

  • nnn observations.

  • PPP features for each observation.

  • A quantitative response yiy_iyi​ for observation iii.

  • Feature values xi1,xi2,…,xiPx_{i1}, x_{i2}, \ldots, x_{iP}xi1​,xi2​,…,xiP​ for observation iii.

A linear model is written as:

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

where:

  • β0\beta_0β0​ is the intercept.

  • βj\beta_jβj​ is the coefficient associated with feature jjj.

  • xijx_{ij}xij​ is the value of feature jjj for observation iii.

  • ϵi\epsilon_iϵi​ is the noise or random error for observation iii.

  • β^j\hat{\beta}_jβ^​j​ denotes an estimate of the unknown coefficient βj\beta_jβj​.

The coefficients determine how the predicted response changes as the features change. Fitting the model means estimating β0,β1,…,βP\beta_0,\beta_1,\ldots,\beta_Pβ0​,β1​,…,βP​ from the available training data.


4. Least Squares Regression

The least-squares objective

The traditional method for fitting a linear model is least squares regression.

For observation iii, the fitted or predicted value 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 residual is the difference between the observed response and the fitted response:

yi−y^iy_i - \hat{y}_iyi​−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)^2RSS=∑i=1n​(yi​−y^​i​)2

Equivalently, least squares solves:

minimize⁡β^0,…,β^P∑i=1n(yi−β^0−∑j=1Pβ^jxij)2\underset{\hat{\beta}_0,\ldots,\hat{\beta}_P}{\operatorname{minimize}} \sum_{i=1}^{n} \left( y_i-\hat{\beta}_0-\sum_{j=1}^{P}\hat{\beta}_jx_{ij} \right)^2β^​0​,…,β^​P​minimize​∑i=1n​(yi​−β^​0​−∑j=1P​β^​j​xij​)2

Squaring the residuals ensures that positive and negative errors do not cancel and gives greater weight to larger errors.

Geometric interpretation

With one predictor, least squares produces a line. With two predictors, it produces a plane. With more predictors, the fitted object is a hyperplane in a higher-dimensional space.

For two predictors, the fitted plane is positioned so that the sum of the squared vertical distances between the observations and the plane is as small as possible.

Each vertical distance represents a residual:

yi−y^iy_i-\hat{y}_iyi​−y^​i​

Moving or rotating the plane would generally increase the total sum of squared residuals.

When least squares works well

Least squares tends to work well when:

  • The number of observations nnn is large.

  • The number of predictors PPP is small.

  • The model is not excessively complex relative to the available data.

  • The relationship between predictors and response can be represented adequately by a linear form.

In high-dimensional biomedical data, however, the number of features may be extremely large relative to the number of observations. In that situation, ordinary least squares can overfit severely.


5. Training Error and Test Error

A central principle of supervised machine learning is that a model should be evaluated by how well it predicts new observations, not merely by how well it fits the data used to train it.

Training set and training error

The training set is the data used to estimate the model coefficients.

The training mean squared error is:

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

This is simply the residual sum of squares divided by the number of observations.

Least squares explicitly chooses the coefficients to make the training error as small as possible. Consequently, least squares is guaranteed to produce a relatively small training error compared with many other coefficient choices.

Training error measures how well a model fits data it has already seen. It does not directly measure how well the model will perform on new data.

Why training error is misleading

As model complexity increases, the training error will never increase. It will either:

  • Decrease.

  • Or remain unchanged.

For example, adding another predictor to a least-squares model gives the model more flexibility. The new model can reproduce everything the old model did and potentially improve the fit further.

With enough flexibility, a model may achieve a perfect fit to the training data:

MSE⁡train=0\operatorname{MSE}_{\text{train}} = 0MSEtrain​=0

However, this does not imply that the model will predict new observations accurately.

Relationship to R2R^2R2

The coefficient of determination, R2R^2R2, is closely related to training error:

  • A larger R2R^2R2 corresponds to a smaller training error.

  • R2R^2R2 generally increases as more variables are added.

  • Therefore, a high R2R^2R2 may simply indicate that the model is highly flexible, not that it will generalize well.

A model can have an excellent R2R^2R2 and still have poor predictive performance on new observations.

Test error

The test set consists of observations that were not used to fit the model. For a test observation, the prediction is denoted by y^test\hat{y}_{\text{test}}y^​test​.

The test mean squared error is:

MSE⁡test=1m∑i=1m(yitest−y^itest)2\operatorname{MSE}_{\text{test}} = \frac{1}{m} \sum_{i=1}^{m} \left( y_i^{\text{test}}-\hat{y}_i^{\text{test}} \right)^2MSEtest​=m1​∑i=1m​(yitest​−y^​itest​)2

where mmm is the number of test observations.

Test error estimates how accurately the model predicts responses for new observations from the same general population.

The practical goal of supervised learning is to find a model with low test error.

Overfitting

Overfitting occurs when a model fits the training data too closely but performs poorly on new data.

An overfit model typically has:

  • Very low training error.

  • High test error.

  • Excessive sensitivity to random features of the training sample.

  • Poor generalization to future observations.

For example, a line fitted to twenty observations may provide a reasonable approximation of the underlying relationship. A line fitted to only two observations can pass exactly through both points, producing zero training error, while being a poor representation of the true relationship.

Even a simple model can overfit when the amount of data is too small relative to the model being estimated.


6. Model Complexity and the Bias–Variance Trade-Off

Meaning of model complexity

Model complexity describes how flexible a model is and how many different relationships it can represent.

The number of predictors is one way to think about complexity, but it is not the only way. Complexity can also be changed by:

  • The size of a decision tree.

  • The degree of polynomial terms.

  • The number of interactions.

  • The amount of coefficient shrinkage.

  • The number of principal components used.

  • Other restrictions or freedoms imposed on the model.

Two models may use the same number of predictors but have different complexities because one is more heavily constrained.

Bias

Bias measures systematic error in the model’s predictions.

Conceptually, if the training process were repeated many times using different samples, bias reflects the average difference between the true relationship or parameter and the fitted estimate.

As model complexity increases:

  • Bias generally decreases.

  • The model becomes more capable of representing complicated patterns.

  • Underfitting becomes less likely.

A model with very low complexity may be too rigid and have high bias.

Variance

Variance measures how much the fitted model changes across different training data sets.

If a small change in the training observations leads to a large change in the fitted model, the model has high variance.

As model complexity increases:

  • Variance generally increases.

  • The model becomes more sensitive to random variation in the training data.

  • Overfitting becomes more likely.

Bias–variance trade-off

Test error reflects a balance between bias and variance. In simplified form:

Test error≈Bias2+Variance+Irreducible error\text{Test error} \approx \text{Bias}^2+\text{Variance}+\text{Irreducible error}Test error≈Bias2+Variance+Irreducible error

The irreducible error represents random variation that cannot be eliminated by improving the model.

The trade-off works as follows:

  • Very simple model: high bias, low variance, and potentially high test error.

  • Very complex model: low bias, high variance, and potentially high test error.

  • Intermediate-complexity model: moderate or low bias and moderate or low variance, often producing the lowest test error.

Training error generally decreases monotonically as complexity increases. Test error often follows a U-shaped pattern:

  1. It decreases at first as underfitting is reduced.

  2. It reaches a minimum at an intermediate complexity.

  3. It increases after the model begins to overfit.

The best model is not the most complex model or the model with the smallest training error. It is the model that achieves the smallest appropriate estimate of test error.


7. Estimating Test Error

In practice, the true future test error is unknown because future responses are not yet observed. Several resampling strategies estimate it.

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 predictive error.

The procedure is:

  1. Split the data into training and validation subsets.

  2. Fit the model on the training subset.

  3. Predict the responses in the validation subset.

  4. Calculate the validation mean squared error.

  5. Repeat for different model complexities or tuning parameters.

  6. Select the model with the smallest estimated error.

The validation error serves as an estimate of test error.

Advantages

  • Simple to understand.

  • Easy to implement.

  • Computationally efficient.

Limitation

The estimate depends on the particular split. A different random division may produce a different estimate of test error.

Leave-one-out cross-validation

In leave-one-out cross-validation, each observation is used once as a validation observation while all remaining observations are used for training.

For nnn observations:

  1. Leave out observation 111.

  2. Fit the model on observations 222 through nnn.

  3. Predict observation 111 and calculate its squared error.

  4. Leave out observation 222.

  5. Fit the model on all other observations and evaluate observation 222.

  6. Continue until every observation has been left out once.

  7. Average the nnn resulting errors.

The estimate is:

CV⁡LOO=1n∑i=1n(yi−y^i(−i))2\operatorname{CV}_{\text{LOO}} = \frac{1}{n} \sum_{i=1}^{n} \left( y_i-\hat{y}_i^{(-i)} \right)^2CVLOO​=n1​∑i=1n​(yi​−y^​i(−i)​)2

where y^i(−i)\hat{y}_i^{(-i)}y^​i(−i)​ is the prediction for observation iii from a model fitted without observation iii.

Advantages

  • Uses nearly all observations for training in every iteration.

  • Avoids dependence on one arbitrary split.

  • Provides a systematic estimate of predictive error.

Limitation

It requires fitting the model nnn times, which can be computationally expensive for large data sets.

kkk-fold cross-validation

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

The procedure is:

  1. Divide the data into kkk approximately equal folds.

  2. Use k−1k-1k−1 folds as the training data.

  3. Use the remaining fold as the validation data.

  4. Fit the model and calculate the error on the held-out fold.

  5. Repeat until every fold has served as the validation fold.

  6. Average the kkk validation errors.

For example, with five-fold cross-validation:

  • Four folds are used for training.

  • One fold is used for validation.

  • This is repeated five times, with a different fold held out each time.

The average error estimates test error and can be calculated for different model complexities or tuning parameters.

Advantages

  • More computationally practical than leave-one-out cross-validation.

  • Less dependent on one arbitrary training-validation split.

  • Commonly preferred for large data sets.

General principle

The validation-set approach, leave-one-out cross-validation, and kkk-fold cross-validation all serve the same central purpose: estimating how a model will perform on observations not used to fit it.

Cross-validation can be used to select:

  • The number of predictors.

  • The value of a regularization parameter.

  • The number of principal components.

  • The size of a decision tree.

  • Other model-complexity parameters.


8. Regularization for High-Dimensional Data

Least squares can become too complex when there are many predictors relative to the number of observations.

Biomedical examples include models using:

  • Expression levels for thousands of genes.

  • Measurements of many proteins.

  • DNA-sequencing features.

  • Large collections of clinical or molecular variables.

When PPP is large relative to nnn, ordinary least squares may fit random noise in addition to meaningful signal. This usually produces:

  • Very low training error.

  • High test error.

  • Unstable coefficient estimates.

  • Poor predictions for new patients.

Regularization or penalization methods address this problem by restricting the coefficients and reducing effective model complexity.

Two major regularization methods are:

  • Ridge regression.

  • The lasso.


9. Ridge Regression

Ridge-regression objective

Ridge regression modifies the least-squares objective by adding a penalty on the squared coefficient values:

minimize⁡β0,…,βP{∑i=1n(yi−β0−∑j=1Pβjxij)2+λ∑j=1Pβj2}\underset{\beta_0,\ldots,\beta_P}{\operatorname{minimize}} \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​minimize​{∑i=1n​(yi​−β0​−∑j=1P​βj​xij​)2+λ∑j=1P​βj2​}

The parameter λ\lambdaλ is a nonnegative tuning parameter controlling the strength of the penalty.

Role of λ\lambdaλ

  • If λ=0\lambda=0λ=0, the penalty disappears and ridge regression becomes least squares.

  • As λ\lambdaλ increases, large coefficients become increasingly costly.

  • As λ\lambdaλ becomes very large, the coefficient estimates approach zero.

  • The intercept is generally not penalized.

The objective contains two competing terms:

  • Residual sum of squares: rewards fitting the training data well.

  • Penalty term: discourages a complex model with large coefficients.

Thus, ridge regression allows some training-data fit to be sacrificed in exchange for lower variance and potentially lower test error.

Ridge regression and model complexity

The quantity

∑j=1Pβj2\sum_{j=1}^{P}\beta_j^2∑j=1P​βj2​

acts as a measure of coefficient magnitude and, indirectly, model complexity.

A large value of λ\lambdaλ produces:

  • Smaller coefficients.

  • Lower variance.

  • Greater bias.

  • A smoother, less flexible model.

An intermediate value of λ\lambdaλ may provide the best bias–variance balance.

Ridge coefficients are not exactly zero

A major property of ridge regression is that it generally shrinks coefficients toward zero but does not set them exactly equal to zero.

Therefore:

  • All predictors remain in the final model.

  • The predictors may have very small effects.

  • Ridge regression does not perform strict feature selection.

A model using all 20,000 genes may be statistically less variable after ridge shrinkage, but it still formally contains all 20,000 genes.

Selecting λ\lambdaλ

The tuning parameter should be selected using an estimate of test error, often through cross-validation:

  1. Choose a grid of candidate λ\lambdaλ values.

  2. Fit ridge regression for each value.

  3. Estimate predictive error using validation or cross-validation.

  4. Select the λ\lambdaλ with the smallest estimated test error.

  5. Refit ridge regression using the selected λ\lambdaλ and the full data set.

The final model should not remain fitted only to the training folds. After choosing λ\lambdaλ, the model is refitted using all available observations.


10. The Lasso

Lasso objective

The lasso is another penalized linear-model method. It replaces ridge regression’s squared-coefficient penalty with an absolute-value penalty:

minimize⁡β0,…,βP{∑i=1n(yi−β0−∑j=1Pβjxij)2+λ∑j=1P∣βj∣}\underset{\beta_0,\ldots,\beta_P}{\operatorname{minimize}} \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​minimize​{∑i=1n​(yi​−β0​−∑j=1P​βj​xij​)2+λ∑j=1P​∣βj​∣}

The key difference is:

  • Ridge: uses ∑j=1Pβj2\sum_{j=1}^{P}\beta_j^2∑j=1P​βj2​.

  • Lasso: uses ∑j=1P∣βj∣\sum_{j=1}^{P}|\beta_j|∑j=1P​∣βj​∣.

Feature selection and sparsity

The absolute-value penalty can force some coefficient estimates to be exactly zero.

A coefficient equal to zero means that the corresponding feature is excluded from the fitted model. Therefore, the lasso produces a sparse model and performs feature selection.

For example, in a model with 20,000 gene-expression features, the lasso may retain only a few genes and assign the other coefficients exactly zero.

Role of λ\lambdaλ

  • If λ=0\lambda=0λ=0, the lasso reduces to least squares.

  • As λ\lambdaλ increases, more coefficients are shrunk toward zero.

  • For intermediate values of λ\lambdaλ, some coefficients may become exactly zero.

  • With sufficiently large λ\lambdaλ, all coefficients may become zero, leaving only the intercept.

The selected value of λ\lambdaλ controls the number of features retained.

Ridge versus lasso

Ridge regression

  • Shrinks coefficients toward zero.

  • Usually retains every predictor.

  • Does not perform exact feature selection.

  • Is useful when many predictors may each contribute a small amount.

  • Produces a model with lower effective complexity through shrinkage.

Lasso

  • Shrinks coefficients toward zero.

  • Can set coefficients exactly equal to zero.

  • Performs feature selection.

  • Produces a sparse, potentially more interpretable model.

  • Is useful when a smaller set of predictors is desirable for clinical or practical reasons.

Choosing between ridge and lasso

Neither method is universally superior. The choice depends on the scientific and practical goals:

  • If predictive accuracy is the primary goal and many variables may contain signal, ridge regression may be useful.

  • If a compact model is important for interpretation, cost, or clinical translation, the lasso may be preferable.

  • In both cases, test-error estimation should guide the choice of λ\lambdaλ and help compare the methods.


11. Principal Components Regression

Dimension reduction

Principal components regression (PCR) reduces the effective dimensionality of the predictor space before fitting a regression model.

With PPP original features, each observation can be viewed as a point in a PPP-dimensional space. However:

  • Some features may be highly correlated and therefore redundant.

  • Some features may mainly contain noise.

  • The data may vary primarily along a smaller number of directions.

Dimension reduction seeks a lower-dimensional representation that preserves important structure in the original data.

Principal components

Principal components are new variables formed as linear combinations of the original predictors:

zm=∑j=1Pϕjmxjz_m = \sum_{j=1}^{P}\phi_{jm}x_jzm​=∑j=1P​ϕjm​xj​

where the coefficients ϕjm\phi_{jm}ϕjm​ define the direction of principal component mmm.

The first principal component is the direction in predictor space along which the data have the greatest variability. Subsequent components capture as much remaining variability as possible subject to being uncorrelated with earlier components.

PCR procedure

PCR follows these steps:

  1. Calculate the principal components of the predictor matrix.

  2. Select the first MMM principal components.

  3. Use those components as predictors in a least-squares regression model.

  4. Select MMM by estimating test error.

The fitted regression is linear in the principal components and therefore also linear in the original predictors.

Model complexity in PCR

The number of retained components controls complexity:

  • If M=PM=PM=P, all components are used and PCR is equivalent to least squares using the original predictors.

  • If M<PM<PM<P, only a reduced set of dimensions is used.

  • Smaller MMM generally produces a less complex model with lower variance.

PCR does not perform feature selection in the original-feature sense. Even though only a few components may be retained, each component is usually a combination of many or all original predictors. Consequently, all original predictors may contribute to the final model.

Strengths and limitation

PCR can reduce redundancy and noise, but its principal components are selected using variation in XXX, not their direct predictive relationship with YYY.

This creates an important limitation:

The directions that explain the most variation in the predictors are not necessarily the directions that best predict the response.

A low-variance direction may contain strong information about YYY, while a high-variance direction may be unrelated to YYY.

PCR is mathematically related to ridge regression and can work well in many settings, but it may fail when the most predictive information is not contained in the first few principal components.

Partial least squares is another dimension-reduction approach that, unlike PCR, incorporates the response when constructing the reduced dimensions.


12. Making a Model More Complex

Regularization methods are mainly useful when least squares is too complex for the available data. In other situations, least squares may be too simple and fail to capture important nonlinear relationships.

A linear model can be made more flexible by adding transformed or combined predictors, such as:

  • Polynomial terms: xj2x_j^2xj2​, xj3x_j^3xj3​.

  • Exponential transformations: exje^{x_j}exj​.

  • Other nonlinear transformations.

  • Interaction terms: xjxkx_jx_kxj​xk​.

  • Products involving multiple features.

For example, a model might include:

yi=β0+β1xi+β2xi2+β3xi3+ϵiy_i = \beta_0 + \beta_1x_i + \beta_2x_i^2 + \beta_3x_i^3 + \epsilon_iyi​=β0​+β1​xi​+β2​xi2​+β3​xi3​+ϵi​

Although the relationship between yyy and the original feature xxx is nonlinear, the model remains linear in its coefficients.

Least squares can be applied to the expanded set of features. Ridge regression, the lasso, and related methods can also be applied if the expanded feature set becomes too large or too complex.

Adding transformations is easy, but the resulting model must still be evaluated using test error. A more flexible model may reduce bias but increase variance and overfit.


13. Classification and Its Relationship to Regression

Classification involves a categorical response rather than a quantitative response. Although the specific modeling tools differ, the core principles discussed for regression continue to apply.

Classification models must still address:

  • Training versus test performance.

  • Overfitting.

  • Model complexity.

  • Bias and variance.

  • Regularization.

  • Validation and cross-validation.

  • Selection of tuning parameters.

  • Generalization to new observations.

The key idea is that a classifier should be judged by its performance on new, previously unseen observations, not merely by how accurately it classifies the training data.


14. Decision Trees

A decision tree is a supervised-learning method that partitions the predictor space into regions and makes a prediction within each region.

For regression, the predictor space is divided into boxes or regions. Each terminal region receives a numerical prediction.

How a regression tree is read

A tree begins with a top-level split based on one predictor. For example:

  • If a player has fewer than a specified number of years of experience, follow the left branch.

  • Otherwise, follow the right branch.

Additional splits continue until a terminal node is reached. The terminal node contains the prediction.

A common convention is:

  • Yes: follow the left branch.

  • No: follow the right branch.

The tree may use predictors such as:

  • Years of experience.

  • Number of hits.

  • Number of walks.

  • Number of runs.

  • Other player characteristics.

Predictions within terminal regions

For a regression tree, the prediction in a region RmR_mRm​ is the average response of the training observations that fall into 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_iy^​Rm​​=∣Rm​∣1​∑i:xi​∈Rm​​yi​

Thus, every observation assigned to the same terminal region receives the same predicted value.

Interpreting transformed responses

A tree may model a transformed response such as log salary. If the predicted log salary is 5.1835.1835.183, the corresponding salary on the original scale is:

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

if the log-scale response was measured in thousands of dollars.

Log transformations are often used for salary because salaries may be highly right-skewed and because modeling multiplicative differences may be more appropriate than modeling additive differences.

Advantages of decision trees

Decision trees are highly interpretable:

  • The sequence of decisions can be followed visually.

  • Predictions can be obtained without understanding complex equations.

  • The tree can be communicated to people without technical training.

  • The rules can be displayed in a form similar to a flowchart.

This interpretability can be valuable in settings such as clinical decision support, where users need a quick and transparent procedure.

Limitations of decision trees

Decision trees are often less accurate than other supervised-learning approaches.

Their main trade-off is:

  • Strength: easy to interpret.

  • Weakness: often lower predictive accuracy.

If interpretability is essential, a tree may be appropriate. If predictive accuracy is the only priority, other methods may perform better.

Tree size and complexity

A large tree has many splits and terminal regions. A small tree has fewer splits.

  • Large tree: low bias but high variance; likely to overfit.

  • Small tree: low variance but potentially high bias; likely to underfit.

The optimal tree size should be selected using an estimate of test error.


15. Experimental Design and Batch Effects

Sophisticated machine-learning methods cannot compensate for flawed experimental design or nonbiological sources of variation.

Batch effects

A batch effect is variation in the data caused by technical, procedural, or environmental factors rather than by the biological phenomenon of interest.

Possible causes include:

  • Samples being processed at different times.

  • Different laboratory personnel.

  • Different instruments or reagent lots.

  • Different laboratories or institutions.

  • Differences in storage or handling.

  • Processing cases and controls in separate batches.

Batch effects are especially problematic in biological and biomedical data because they can create apparent patterns that look biological but are actually technical artifacts.

Why batch effects are dangerous

If disease cases are processed in one batch and controls in another, the model may learn to distinguish the batches rather than the disease states.

This can result in:

  • Artificially strong associations.

  • Very low apparent training error.

  • Good apparent test error when the test observations share the same batch structure.

  • Poor performance on genuinely independent data collected under different conditions.

Reducing batch effects

Good experimental design should attempt to prevent batch effects before modeling begins.

Recommended practices include:

  • Randomizing sample run times: cases and controls should not be processed in separate, systematically different batches.

  • Reducing extraneous variation: standardize procedures, equipment, sample handling, and measurement conditions.

  • Using multiple data sources: when possible, collect data from multiple laboratories or institutions.

  • Balancing biological groups across batches: each batch should contain an appropriate mixture of experimental conditions.

  • Validating independently: evaluate the final model on data collected independently, preferably at a different site or under different experimental conditions.

Independent validation is especially important because ordinary cross-validation may fail to reveal batch effects if observations from the same batch are distributed across both training and validation folds.

A model is not reliable merely because its internal test error is low. It must also perform well on independent data collected under realistic external conditions.


16. Distributional Assumptions and the Curse of Dimensionality

Normality and Gaussian errors

Traditional introductory statistics courses often emphasize the assumption that model errors are normally distributed. In many predictive settings, moderate deviations from normality are not the main concern, particularly when the sample size is large.

The more serious problem is a mismatch between:

  • The amount of available data.

  • The number of features.

  • The complexity of the model.

A model can fail badly even when the data are perfectly Gaussian if the model is too complex relative to the sample size.

Curse of dimensionality

The curse of dimensionality refers to the difficulties that arise as the number of dimensions or features increases.

High dimensionality can cause:

  • More opportunities to fit random noise.

  • Greater model variance.

  • Less reliable coefficient estimates.

  • Increased risk of overfitting.

  • Greater computational demands.

  • Difficulty identifying which variables contain real signal.

Adding more measured variables does not automatically produce better predictions. More features may encourage the use of unnecessarily complex models, which can increase test error.

More data features are not automatically better data. Low test error is more important than high dimensionality or model complexity.


17. Quantifying Model Complexity

For an ordinary least-squares model, complexity can often be approximated by counting the number of predictors or degrees of freedom.

For example, a least-squares model with ten predictors uses approximately ten predictor-related degrees of freedom.

This simple interpretation becomes inadequate for many other methods:

  • Ridge regression always includes all predictors, but its effective complexity changes with λ\lambdaλ.

  • The lasso may include many or few predictors depending on λ\lambdaλ.

  • PCR complexity depends on the number of retained components.

  • Decision-tree complexity depends on the number and structure of splits.

  • Models with transformations and interactions may have many derived features.

It is therefore difficult to compare complexity directly across fundamentally different model classes.

The most broadly useful comparison is predictive performance:

  • Fit competing models appropriately.

  • Estimate their test errors using valid resampling or independent data.

  • Prefer the model with the lowest relevant test error, while considering interpretability and practical constraints.

Information-based criteria and significance measures may be useful in particular statistical contexts, but for predictive supervised learning, test error directly addresses the primary goal: accurate prediction of new observations.


18. No Universally Best Supervised-Learning Method

There is no single supervised-learning method that is best for every data set and every scientific objective.

Different methods may perform differently depending on:

  • The number of observations.

  • The number of features.

  • The degree of correlation among predictors.

  • The true relationship between predictors and response.

  • The amount of noise.

  • The need for interpretability.

  • Computational limitations.

  • The consequences of false predictions.

Possible approaches include:

  • Least squares.

  • Ridge regression.

  • The lasso.

  • Principal components regression.

  • Partial least squares.

  • Decision trees.

  • Many other methods.

Although no method is universally best, some procedures are clearly wrong when applied improperly. Examples include:

  • Performing cross-validation incorrectly.

  • Allowing information from the validation set to influence model fitting.

  • Selecting a model based only on training error.

  • Ignoring batch effects.

  • Failing to validate externally.

  • Using a model whose complexity is unsupported by the available data.

The most important general rule is:

Model selection and evaluation must focus on correctly estimated test error.

A model with high test error is not useful for prediction, regardless of how sophisticated its algorithm is, how small its training error is, or how statistically impressive its in-sample fit appears.

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent