Regression and classification
Introducido
6:33
Inteligencia Artificial y Aprendizaje Automático
This course covers the classical core of artificial intelligence, honestly measured. The first three units are the spine: search, logical reasoning and…
Narración en inglés · subtítulos en inglés y 中文 que puedes cambiar
En esta lección
| English | Significado |
|---|---|
| Linear regression/ˈlɪnɪə rɪˈɡreʃn/ | fitting a straight line (or plane) to predict a number |
| least squares/liːst skweəz/ | choosing a model's parameters to minimise the sum of squared errors |
| Logistic regression/ləˈdʒɪstɪk rɪˈɡreʃn/ | a model that predicts the probability of a class using the logistic function |
| decision boundary/dɪˈsɪʒn ˈbaʊndəri/ | borde de decisión |
| margin/ˈmɑːdʒɪn/ | |
| overfitting/ˌəʊvəˈfɪtɪŋ/ | a model fitting the training data's noise, so it does worse on new data |
| confounder/kənˈfaʊndə/ | a variable that affects both the cause and the effect, creating a misleading link |
| Ridge regression/rɪdʒ rɪˈɡreʃn/ | least squares with a penalty on large weights, which reduces overfitting |
| k-nearest neighbours/keɪ ˈnɪərɪst ˈneɪbəz/ | predicting from the k most similar training examples |
| cross-entropy/krɒs ˈentrəpi/ | a classification loss equal to minus the log of the probability the model gave the true class |
| Standardise/ˈstændədaɪz/ | rescale a feature to mean 0 and standard deviation 1 |
Líneas y límites
- La regresión lineal ajusta $\hat{y} = wx + b$ por mínimos cuadrados; la regresión logística ajusta un límite de probabilidad con la sigmoide; el límite de decisión es donde el modelo cambia su respuesta.


The decision boundary is where —
Dificultad 1/5 · 100 monedas + un pequeño bono en el primer intento de hoy
The score crosses zero: the answer flips.
Mínimos cuadrados, forma cerrada
- Puntos del curso $(1,2), (2,3), (3,5), (4,4), (5,6)$: $\bar{x} = 3$, $\bar{y} = 4$, $w = 9/10 = 0.9$, $b = 1.3$ — residuos $-0.2, -0.1, 1.0, -0.9, 0.2$, SSE $1.9$ (cada número verificado por el conjunto).
- Límite logístico con $w_1 = 2, w_2 = -1, b = -1$: la recta $x_2 = 2x_1 - 1$; un paquete en $(2, 2)$ obtiene puntuación $+1$ (tarde), en $(2, 5)$ puntuación $-2$ (a tiempo); el margen es la magnitud de la puntuación.
The course five points fit the line —
Dificultad 1/5 · 100 monedas + un pequeño bono en el primer intento de hoy
w = 9/10, b = 4 - 0.9 x 3 = 1.3; SSE 1.9.
El sobreajuste, medido
- Un polinomio de grado 4 alcanza un SSE de $0$ en los cinco puntos de entrenamiento pero un SSE de $\approx 42.7$ en los cinco puntos retenidos — contra la línea de $0.55$. El error de entrenamiento es una publicidad; el error retenido es el producto.
- Selección del modelo por error retenido; y los pesos ajustados no son causas (el confounding de la unidad 8 vive aquí también).
The 4th-degree polynomial on held-out data scores SSE —
Dificultad 1/5 · 100 monedas + un pequeño bono en el primer intento de hoy
Training error 0, but held-out error 42.7 against 0.55 for the line: the polynomial overfits.
The 4th-degree polynomial that fits the five training points exactly is the better model.
Dificultad 1/5 · 100 monedas + un pequeño bono en el primer intento de hoy
Zero training error came from fitting the noise: on held-out points its SSE is about $42.7$, against $0.55$ for the line. Choose models by held-out error.
Esta tarjeta es nueva, por eso aparece en inglés hasta que su traducción esté lista.
Fit quality and regularisation
- $R^2$ compares the fit with simply using the mean. For the course points, the total sum of squares about $\bar{y} = 4$ is $4 + 1 + 1 + 0 + 4 = 10$, and the line leaves SSE $1.9$, so $R^2 = 1 - 1.9/10 = 0.81$.
- Ridge regression 岭回归 adds $\lambda \lVert w \rVert^2$ to the loss. This pulls the weights toward zero and calms the wild polynomial; $\lambda$ is chosen on validation data.
- k-nearest neighbours k近邻 votes among the $k$ closest training points: $k = 1$ overfits, and a very large $k$ underfits.
A model leaves SSE 6 on data whose total sum of squares is 24. What is R^2?
Dificultad 2/5 · 140 monedas + un pequeño bono en el primer intento de hoy
1 - 6 / 24 = 0.75.
Raising the ridge penalty λ makes the fitted weights —
Dificultad 1/5 · 100 monedas + un pequeño bono en el primer intento de hoy
The penalty charges for large weights, so a bigger λ buys smaller ones at some cost in fit.
Esta tarjeta es nueva, por eso aparece en inglés hasta que su traducción esté lista.
From score to probability and loss
- Logistic regression turns a score $z$ into a probability $\sigma(z) = 1/(1 + e^{-z})$: $\sigma(0) = 0.5$ and $\sigma(2) = 0.881$.
- It is trained on cross-entropy 交叉熵 loss, $-\ln p$ for the probability given to the true class. A late parcel given 0.881 costs $-\ln 0.881 = \mathbf{0.127}$; if it had been on time, the loss would be $-\ln 0.119 = 2.13$. Confident mistakes cost the most.
The sigmoid of a score of 0?
Dificultad 2/5 · 140 monedas + un pequeño bono en el primer intento de hoy
$1/(1 + e^0) = 1/2$.
Cross-entropy loss when the true class gets probability 0.881 (three decimals)?
Dificultad 2/5 · 140 monedas + un pequeño bono en el primer intento de hoy
$-\ln 0.881 = 0.127$.
Esta tarjeta es nueva, por eso aparece en inglés hasta que su traducción esté lista.
Worked example: standardise first
- Distance in km and parcel weight in g have very different scales. So the size of a fitted weight says nothing about importance, and k-nearest neighbours would measure almost only grams.
- Standardise 标准化: $z = (x - \mu)/\sigma$. With $\mu = 120$ and $\sigma = 30$, a value of 180 becomes $\mathbf{2.0}$. Compute $\mu$ and $\sigma$ on the training data only, then apply them to the validation and test data.
Standardise 180 with training mean 120 and standard deviation 30.
Dificultad 2/5 · 140 monedas + un pequeño bono en el primer intento de hoy
$(180 - 120)/30 = 2$.
Esta tarjeta es nueva, por eso aparece en inglés hasta que su traducción esté lista.
Marks that slip away
- Extrapolating the line. The fit holds near the data, $x$ from $1$ to $5$, not far outside it.
- Weights as causes. A large weight shows an association in this data, not that changing $x$ changes $y$.
- Regularising unscaled features. The penalty depends on each feature's units; standardise 标准化 first.
Esta tarjeta es nueva, por eso aparece en inglés hasta que su traducción esté lista.
Recap
- Least squares 最小二乘法 on the course points: $w = 0.9$, $b = 1.3$, SSE $1.9$.
- A logistic boundary is where the score is $0$; the margin is the size of the score.
- Choose models by held-out error, never training error:
| Model | Training SSE | Held-out SSE |
|---|---|---|
| Straight line | 1.9 | 0.55 |
| 4th-degree polynomial | 0 | 42.7: overfits |
¿Qué salió mal? Solo el equipo del sitio ve esta información.