Regression and classification
導入済み
6:33
人工知能と機械学習
This course covers the classical core of artificial intelligence, honestly measured. The first three units are the spine: search, logical reasoning and…
英語のナレーション・英語と中国語の字幕を切り替え可能
このレッスンの内容
| English | 意味 |
|---|---|
| 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/ | 決定境界 |
| 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 |
直線と境界
- 線形回帰は、最小二乗法を使って$\hat{y} = wx + b$を当てはめます。ロジスティック回帰は、シグモイド関数を使ってスコアを確率に変換します。
- 決定境界は、モデルの答えが変わる場所です。

The decision boundary is where —
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
The score crosses zero: the answer flips.
最小二乗法の解析解
- コースのデータ点$(1,2), (2,3), (3,5), (4,4), (5,6)$:$\bar{x} = 3$、$\bar{y} = 4$、$w = 9/10 = 0.9$、$b = 1.3$。残差は$-0.2, -0.1, 1.0, -0.9, 0.2$で、誤差平方和(SSE)は$1.9$です。
- $w_1 = 2, w_2 = -1, b = -1$の場合、ロジスティック回帰の境界は直線$x_2 = 2x_1 - 1$です。$(2, 2)$にある荷物のスコアは$+1$(遅延)で、$(2, 5)$にある荷物のスコアは$-2$(時間どおり)です。スコアの大きさをマージンといいます。
The course five points fit the line —
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
w = 9/10, b = 4 - 0.9 x 3 = 1.3; SSE 1.9.
過学習を測る
- 4次多項式のSSEは、5つの訓練データ点では$0$ですが、評価用に取り分けた5つのデータ点では$\approx 42.7$です。一方、直線の場合は$0.55$です。これは過学習です。訓練誤差はモデルの見かけの良さを示すだけで、取り分けたデータでの誤差がモデルの性能を測ります。
- 取り分けたデータでの誤差を使ってモデルを選びます。学習された重みは原因を示すものではありません。$x$と$y$の両方に影響する変数(交絡因子)だけでも、大きな重みが生じることがあります。
The 4th-degree polynomial on held-out data scores SSE —
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
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.
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
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.
当てはまりの良さと正則化
- $R^2$は、モデルの当てはまりを、単に平均を使った場合と比較します。コースのデータ点では、$\bar{y} = 4$からの偏差の平方和は$4 + 1 + 1 + 0 + 4 = 10$で、直線のSSEは$1.9$なので、$R^2 = 1 - 1.9/10 = 0.81$です。
- リッジ回帰は損失に$\lambda \lVert w \rVert^2$を加えます。これにより重みがゼロに近づき、多項式の激しい変動が抑えられます。$\lambda$は検証データを使って選びます。
- k近傍法は、最も近い$k$個の訓練データ点による多数決で判定します。$k = 1$では過学習になり、$k$が非常に大きいと学習不足になります。
A model leaves SSE 6 on data whose total sum of squares is 24. What is R^2?
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
1 - 6 / 24 = 0.75.
Raising the ridge penalty λ makes the fitted weights —
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
The penalty charges for large weights, so a bigger λ buys smaller ones at some cost in fit.
スコアから確率と損失へ
- ロジスティック回帰は、スコア$z$を確率$\sigma(z) = 1/(1 + e^{-z})$に変換します。$\sigma(0) = 0.5$、$\sigma(2) = 0.881$です。
- 学習には交差エントロピー損失を使います。正解のクラスに与えた確率に対して、損失は$-\ln p$です。遅延した荷物に0.881を与えた場合の損失は$-\ln 0.881 = \mathbf{0.127}$です。もしその荷物が時間どおりだった場合、損失は$-\ln 0.119 = 2.13$になります。自信を持って間違えた場合の損失が最も大きくなります。
The sigmoid of a score of 0?
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
$1/(1 + e^0) = 1/2$.
Cross-entropy loss when the true class gets probability 0.881 (three decimals)?
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
$-\ln 0.881 = 0.127$.
例題:まず標準化する
- kmで表した距離とgで表した荷物の重さでは、尺度が大きく異なります。そのため、学習された重みの大きさからは重要度を判断できず、k近傍法ではほとんどgの差だけで距離が測られます。
- 標準化:$z = (x - \mu)/\sigma$。$\mu = 120$、$\sigma = 30$の場合、値180は$\mathbf{2.0}$になります。$\mu$と$\sigma$は訓練データだけを使って計算し、その値を検証データとテストデータに適用します。
Standardise 180 with training mean 120 and standard deviation 30.
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
$(180 - 120)/30 = 2$.
点を落としやすいところ
- 直線を外挿する。 当てはまりが成り立つのはデータの近く、$1$から$5$までの$x$であり、そこから大きく離れた範囲ではありません。
- 重みを原因と考える。 大きな重みは、このデータにおける関連を示すものであり、$x$を変えると$y$が変わることを示すものではありません。
- 尺度をそろえていない特徴量を正則化する。 ペナルティは各特徴量の単位に左右されるので、まず標準化します。
まとめ
- コースのデータ点に最小二乗法を適用:$w = 0.9$、$b = 1.3$、SSE $1.9$。
- ロジスティック回帰の境界はスコアが$0$になる場所で、マージンはスコアの大きさです。
- モデルは訓練誤差ではなく、取り分けたデータでの誤差を使って選びます。
| モデル | 訓練データのSSE | 取り分けたデータのSSE |
|---|---|---|
| 直線 | 1.9 | 0.55 |
| 4次多項式 | 0 | 42.7:過学習 |
何が問題でしたか?この内容はサイトの運営チームだけが確認します。