Friday, September 20, 2024
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.
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.
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).
Artificial
Intelligence
Machine
Learning
Deep
Learning
Artificial
Intelligence
Machine
Learning
Deep
Learning
One way to think about different classes of 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. |
Terminology:
Broad classes of machine 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.
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\)
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.
Not all regression is linear….
The classic iris
| 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 |
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) |

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

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

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
| 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 |
What do you think about the relationship between age and insurance charges?
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
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
Anscombe’s Quartet
K-nearest neighbor (kNN) algorithm.
Classification and Regression Trees (CART).
Random Forests.
Deep learning.
https://doi.org/10.1098/rsif.2017.0387
The mlr3 ecosystem in R.
Unsupervised learning.
Gene expression measurements.


Thinking about similarities and differences
Algorithm for hierarchical clustering
Algorithm for hierarchical clustering
Algorithm for hierarchical clustering
Schematic PCA.
Using dimensionality reduction to explore 22,000 dimensions of gene expression data on 280 samples.