Introduction to Machine Learning

Sean Davis, MD, PhD

Friday, September 20, 2024

Outline

  1. Relationship between AI and ML
  2. Types of Machine Learning
  3. A little about data
  4. Supervised Learning
  5. Unsupervised Learning

Artificial Intelligence Overview

Artificial Intelligence (AI) is the simulation of human intelligence processes by machines, especially computer systems. These processes include learning (the acquisition of information and rules for using the information), reasoning (using rules to reach approximate or definite conclusions), and self-correction.

An Ontology of AI

What is Machine Learning?

The study of computer algorithms that improve automatically through experience. It is seen as a subset of artificial intelligence. Machine learning systems give the computer the ability to learn without being explicitly programmed rules.

What is Deep Learning?

Machine learning algorithms that are inspired by the structure and function of the brain. Deep learning is a subset of machine learning in artificial intelligence that has networks capable of learning unsupervised from data that is often unstructured (i.e., text or images).

AI vs. ML vs. Deep Learning

Artificial
Intelligence

Machine
Learning

Deep
Learning

AI vs. ML vs. Deep Learning

Artificial
Intelligence

Machine
Learning

Deep
Learning

Side trip: Types and Characteristics of Data

An ontology of Data

One way to think about different classes of data.

Structured Data vs Unstructured Data

Structured data Unstructured data
What is it? Data that fits in a predefined data model or schema. Data without an underlying model to discern attributes.
Basic example An Excel table. A collection of video files.
Best for A set of predefined observations or characteristics (columns) on a collection of things (rows) An associated collection of data, objects, or files where the attributes change or are unknown.
Common formats CSV, TSV, Excel, SQL databases. Images, audio, video, text.

Tabular Data

  • Rows and columns
  • Each column has a specific data type
  • Each row represents an observation on a subject (e.g., patient, sample)

Terminology:

  • Feature: A column in the dataset
  • Target: The variable you are trying to predict
  • Observation: A row in the dataset
  • Dimension: The number of features in the dataset (sometimes represented by \(p\))
  • Sample: A single row in the dataset (usually represented by \(n\))

Classes of Machine Learning

Broad classes of machine learning.

Types of Machine Learning

  1. Supervised Learning
    • Classification
    • Regression
  2. Unsupervised Learning
    • Clustering
    • Dimensionality Reduction
  3. Reinforcement Learning

Reinforecement Learning

  • Learning through interaction: Unlike supervised learning where you have labeled data, RL agents learn by interacting with an environment.
  • Delayed rewards: The agent doesn’t receive immediate feedback about the optimal action, but rather must learn which actions lead to better cumulative rewards over time.
  • Exploration vs. exploitation: The agent must balance exploring new actions versus exploiting known good actions.
  • Sequential decision making: RL deals with sequences of decisions rather than one-time predictions.

Examples

  • Game playing (e.g., AlphaGo, OpenAI Five)
  • Robotics control
  • Autonomous driving
  • Trading strategies

A map of machine learning approaches

Supervised Learning

Supervised learning builds a model on which we know the TRUE result; this is sometimes called “labeled data”.

The model learns to map input data to the correct output by adjusting its parameters to minimize the error between the predicted output and the true output.

Supervised Learning

  • Given a dataset of input-output pairs: \(\{(x_1, y_1), (x_2, y_2), \ldots, (x_n, y_n)\}\)

  • Learn a function \(f\) with parameters \(\theta\) that maps inputs \(x\) to outputs \(y\) \[y = f(x; \theta) + \epsilon\]

  • Objective: Choose parameters \(\theta\) to minimize the prediction error \(\epsilon\)

Supervised Learning

When \(y\) is a continuous variable (e.g., house prices), it’s a regression problem.

When \(y\) is a discrete variable (e.g., spam or not spam), it’s a classification problem.

It is not a concidence that the same terms are used in statistics! Many machine learning algorithms are based on statistical principles or are generalizations of statistical methods.

Classification

Regression

Not all regression is linear….

Classification Example

The classic iris

Classification Example

Sepal.Length Sepal.Width Petal.Length Petal.Width Species
6.2 2.8 4.8 1.8 virginica
4.8 3.4 1.6 0.2 setosa
5.0 3.4 1.5 0.2 setosa
5.9 3.2 4.8 1.8 versicolor
5.8 4.0 1.2 0.2 setosa
5.8 2.7 3.9 1.2 versicolor
6.7 3.1 4.7 1.5 versicolor
5.6 2.8 4.9 2.0 virginica
6.3 2.8 5.1 1.5 virginica
6.3 2.5 5.0 1.9 virginica
4.6 3.1 1.5 0.2 setosa
5.5 2.4 3.8 1.1 versicolor
6.5 3.0 5.2 2.0 virginica
5.6 3.0 4.5 1.5 versicolor
7.3 2.9 6.3 1.8 virginica
6.1 3.0 4.9 1.8 virginica
4.3 3.0 1.1 0.1 setosa
6.4 3.2 5.3 2.3 virginica
4.8 3.0 1.4 0.3 setosa
6.1 2.9 4.7 1.4 versicolor

Classification Example

Training and Testing

  • Training Data: Used to teach the model. It consists of input-output pairs for a supervised learning task.
  • Testing Data: Used to evaluate the model’s performance. It should be separate from the training data, but come from the same distribution or population.
  • Validation Data: Used for tuning hyperparameters. Hyperparameters are settings that control the learning process (e.g., k in k-NN, learning rate in neural networks).

Generalizability

  • The ability of a model to perform well on unseen data

This table shows the relationship between training error, testing error, and overfitting, good fit, and underfitting.

Training Error Testing Error Model Fit
Low High Overfit
Low Low Good Fit
High High Underfit (poor performance)

Bias and Variance

  • Bias: Error from incorrect assumptions in the learning algorithm
  • Variance: Error from sensitivity to small fluctuations in the training set
  • Bias-Variance Tradeoff: The conflict in trying to simultaneously minimize these two sources of error

Classification Example

Classification Example

Classification Example

Regression Example


Call:
lm(formula = y ~ x)

Residuals:
    Min      1Q  Median      3Q     Max 
-49.071 -11.047  -0.692  12.970  41.897 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept) -0.72808    3.68575  -0.198    0.844    
x            2.05022    0.06336  32.356   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 18.29 on 98 degrees of freedom
Multiple R-squared:  0.9144,    Adjusted R-squared:  0.9135 
F-statistic:  1047 on 1 and 98 DF,  p-value: < 2.2e-16

Regression Example


Call:
lm(formula = y ~ x)

Residuals:
    Min      1Q  Median      3Q     Max 
-98.143 -22.095  -1.385  25.940  83.795 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)  -1.4562     7.3715  -0.198    0.844    
x             2.1004     0.1267  16.574   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 36.58 on 98 degrees of freedom
Multiple R-squared:  0.7371,    Adjusted R-squared:  0.7344 
F-statistic: 274.7 on 1 and 98 DF,  p-value: < 2.2e-16

Regression Example


Call:
lm(formula = y ~ x)

Residuals:
     Min       1Q   Median       3Q      Max 
-171.749  -38.665   -2.423   45.395  146.641 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)  -2.5483    12.9001  -0.198    0.844    
x             2.1758     0.2218   9.811 3.12e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 64.02 on 98 degrees of freedom
Multiple R-squared:  0.4955,    Adjusted R-squared:  0.4904 
F-statistic: 96.25 on 1 and 98 DF,  p-value: 3.116e-16

More Complex Regression Example

age sex bmi children smoker region charges obese
19 female 27.900 0 yes southwest 16884.924 not obese
18 male 33.770 1 no southeast 1725.552 obese
28 male 33.000 3 no southeast 4449.462 obese
33 male 22.705 0 no northwest 21984.471 not obese
32 male 28.880 0 no northwest 3866.855 not obese
31 female 25.740 0 no southeast 3756.622 not obese
46 female 33.440 1 no southeast 8240.590 obese
37 female 27.740 3 no northwest 7281.506 not obese
37 male 29.830 2 no northeast 6406.411 not obese
60 female 25.840 0 no northwest 28923.137 not obese

More Complex Regression Example

What do you think about the relationship between age and insurance charges?

More Complex Regression Example

More Complex Regression Example


Call:
lm(formula = charges ~ age + smoker + sex + obese, data = insurance)

Residuals:
     Min       1Q   Median       3Q      Max 
-13821.5  -3647.0   -225.8   1491.3  26884.1 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept) -4051.16     542.42  -7.469 1.46e-13 ***
age           261.73      11.82  22.149  < 2e-16 ***
smokeryes   23861.89     410.79  58.087  < 2e-16 ***
sexmale      -114.30     331.89  -0.344    0.731    
obeseobese   4234.44     332.58  12.732  < 2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 6044 on 1333 degrees of freedom
Multiple R-squared:  0.7516,    Adjusted R-squared:  0.7509 
F-statistic:  1008 on 4 and 1333 DF,  p-value: < 2.2e-16

Supervised Machine Learning Models

Algorithms for Supervised Learning


Call:
lm(formula = y ~ x)

Residuals:
     Min       1Q   Median       3Q      Max 
-24.5356  -5.5236  -0.3462   6.4850  20.9487 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept) -0.36404    1.84287  -0.198    0.844    
x            2.02511    0.03168  63.920   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 9.145 on 98 degrees of freedom
Multiple R-squared:  0.9766,    Adjusted R-squared:  0.9763 
F-statistic:  4086 on 1 and 98 DF,  p-value: < 2.2e-16

Algorithms for Supervised Learning

Anscombe’s Quartet

Algorithms for Supervised Learning

K-nearest neighbor (kNN) algorithm.

Algorithms for Supervised Learning

Classification and Regression Trees (CART).

Algorithms for Supervised Learning

Random Forests.

Algorithms for Supervised Learning

Deep learning.

Applying Supervised Learning Algorithms

The mlr3 ecosystem in R.

Key Concepts in Supervised Learning

  1. Feature Engineering
  2. Model Selection
  3. Hyperparameter Tuning
  4. Ensemble Methods
  5. Cross-Validation
  6. Evaluation Metrics

Challenges in Machine Learning

  1. Data Quality and Quantity
  2. Interpretability vs Performance
  3. Ethical Considerations and Bias
  4. Computational Resources
  5. Model Deployment and Maintenance

Unsupervised Learning

Unsupervised learning.

Clustering

Gene expression measurements.

Classes of unsupervised learning algorithms

Clustering.

Dimensionality reduction.

Clustering

Thinking about similarities and differences

Clustering

Algorithm for hierarchical clustering

Clustering

Algorithm for hierarchical clustering

Clustering

Algorithm for hierarchical clustering

Dimensionality Reduction

Schematic PCA.

Dimensionality Reduction

Using dimensionality reduction to explore 22,000 dimensions of gene expression data on 280 samples.

Future Directions in Machine Learning

  • AutoML: Automating the ML pipeline
  • Federated Learning: Training models on decentralized data
  • Explainable AI: Making black-box models more interpretable
  • Quantum Machine Learning: Leveraging quantum computing for ML
  • Continual Learning: Adapting to new data without forgetting old patterns

Conclusion

  • Supervised learning: Predicting outcomes based on labeled data
    • Classification: Assigning labels to data
    • Regression: Predicting continuous values
  • Unsupervised learning: Finding patterns in unlabeled data
    • Clustering: Grouping similar data points
    • Dimensionality reduction: Simplifying complex data by reducing dimensions
  • Reinforcement learning: Learning through interaction with an environment

Resources

Questions?