HTML 筆記

HTML week 3

Data labels

Supervised

Unsupervised

Semi-supervised

Self-supervised

自己產生資料,比如從輸出產生輸入,把完整的拼圖打亂,叫Machine把它拼回去。
自監督式學習 Self-Supervised Learning for Computer Vision 之概述

Weakly-supervised

Reinforcement

Protocols

Batch

Online

Active

Input Spaces

Concrete

Raw

Abstract

Error

Where does the error come from?

No Free Lunch Theorem for Machine Learning

Unseen cases可能與seen cases差異甚大

Off-Training-Set Error

Test set太小則有可能與真實的正確率有偏差

Eout:真實誤差
Ein
:根據seen cases得到的誤差
Hoeffding’s Inequality bound兩者的誤差。
PrD[D is bad]=PrD[D is bad for h1D is bad for h2D is bad for hM]PrD[D is bad for h1]+PrD[D is bad for h2]++PrD[D is bad for hM]2Mexp(2ϵ2N)

|H|的大小:
太大:bound太大,
Eout
Ein
可能差很大
太小:找不到好的
hH
使得
Ein
很小

但是PLA的

|H|=怎麼辦?

abbr: PAC=probably approximately correct

HTML week 4

bound the distance between

Ein and
Eout
by the number of hypotheses. but for infinite hypotheses? Classify them into dichotomies(from parameters to the classification results of samples). In a binary classification problem, the number of dichotomies is upper bound by
2N
where N is the number of samples. growth function: the maximum number of dichotomies among possible inputs(to make it independent of inputs), denoted as
mH(N)
. But for some tasks, the number of dichotomies may be lower,

  • 1D perceptron,
    f(x)=sign(xh)
    ,
    mH(N)=N+1
    ,bp:2
  • positive intervals(1D),
    f(x)=1
    if
    x[l,r), 0
    otherwise,
    mH(N)=(N+12)+1=12N2+12N+1
    , bp:3
  • Convex sets(2D), 用凸的圖形把一個分類包起來,
    mH(N)=2N
    , bp:no
  • 2D perceptron,
    mH(N)<2N
    in some cases, bp:4

k is a breakpoint if
mH(k)<2k
, property: all
n>
minimum break point are break points.
For some N, k inputs can be shattered by
H mH(N)=2N

For a set of hypotheses for a task, VC dimension=breakpoint-1, VC dimension means the last
n
s.t. the hypotheses can shatter any possible N inputs. VC dimension can be view as the strength of a set of hypotheses.

It's proven that for

N2,k3,
mH(N)Nk1

HTML week 5

Error functions are application/user-dependent.

Example:

  • In a supermarket fingerprint verification system that verifies customers and collects points for discounts, false rejection is a serious problem.
  • In the CIA, false acceptance will be VERY serious because we let intruders in.

HTML week 6

linear classification: h(x)=sign(s), error: 0/1
linear regression: h(x)=s, error: mse
logistic regression: h(x)=

θ(s), error: cross-entropy

non-linear transform + linear model => non-linear model

HTML week 7

Introduce overfitting

low

Ein, high
Eout

Causes of overfitting

  • too much noise but too few samples
  • too complex target but too few samples
  • too complex model(large
    dvc
    ) for simple target but very few samples.

Avoid Overfitting

  • start from simple models
  • data cleaning/pruning
  • data hinting
  • regularization
  • Validation

Data cleaning/pruning

Maybe automatically detect outliers, and

  • data cleaning: correct the label
  • data pruning: remove the sample
    the effect may be limited

data hinting

Example: slightly shift/rotate images to generate more data.
Aka data augmentation

HTML week 8

validation

validation set:作弊,

DDtrainDval從training data分
K
個出來當作選擇hypothesis的標準。
Eout(g)small KEout(g)large KEval(g)

practical:
KN=20%

Cross Validation

Single Cross Validation

K=1
When choose n-th data as validation set,
Eval=en

leave-one-out cross-validation estimate

Eloocv(H,A)=1Nn=1Nen
Hope
Eloocv(H,A)Eout(g)

EDEloocv(H,A)=ED1Nn=1Nen=Eout(N1)

disadvantage

It takes a lot of time. Not practical.

V-fold Cross Validation

把資料切成V份,輪流把其中一份當作validation。
practical:

V=510

Don't fool yourself

Report test result instead of best validation result.

Three principles

奧坎剃刀(Occam's Razor)

越簡單越好。
只加入必要的東西。

Sampling Bias

Machine learning may cause harm.

Story

  • 選舉民調:手機太貴,某一黨的支持者比較買得起,因此有誤差
  • Netflix competition:validation error: 13% improvement
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

    BUT validation: random examples within
    D

    test: last user records after
    D

HTML week 9

Solution

Match test scenario as much as possible
One possible solution: emphasize later samples

Bank credit card approval problem
  • 時間偏差
    金融市場會改變,比如通貨膨脹、貨幣流通量改變
  • 分布偏差
    • 要核准信用卡後觀察一段時間才能決定,有可能被拒絕的人其實是個好客戶(distribution不同,一個是所有人、一個是只包含以前核准過的客戶)
    • 也許以前的年輕人信用狀況都不好,之後的年輕人可能就難以核准

Data Snooping

If designing the model while snooping(偷看) data, it may overfit.
If a data set has affected any step in the learning process, its ability to assess the outcome has been compromised.

  • 偷看test data,並照資料做model,失去test data獨立的作用。像是投信調參數做出過去績效很好的指數來發行ETF,但是未來表現未必好。
  • Data reusing: 每次都看以前的論文,做得更好才發表。一直對data做某件事,可能就會變相的在偷看測試資料。

secret solution

carefully balance between data-driven modeling(snooping) and validation (no-snooping)

Linear Support Vector Machine

Fatness for a model solving linearly separable data

If many hypotheses can perfectly solve this, choose the one with the largest "Robustness"(can classify even if some test data is affected by noise.)

Robustness = Fatness of saparating hyperplane = the distance to the nearest

xn(margin).
Choose the one with the largest margin and can perfectly separate data.

Distance to Hyperplane

Shorten x and w first. Make

x=(x0(=1),,xn) ->
x=(x1,,xn)
, and
w=(w0,,wn)
->
w=(w1,,wn)
and
b(=w0)
.
So
h(x)=wTx
->
h(x)=wTx+b

Want to know the distance(x,b,w) = the distance between x and hyperplane
wTx+b=0

distance=project some
(xx)
to orthogonal of the hyperplane(the normal vector
w
)=
|wT(xx)w|=1w|wTx+b|

Support Vector Machine

  • Saparating: for every n,
    yn(wTxn+b)>0
  • distance
    =1wyn(wTx+b)

Goal: Find

argmaxb,w1w subject to
minnyn(wTx+b)=1

If

minnyn(wTx+b)>1, say
1.127
, we can let
b=b1.127,w=w1.127
so that
1w
is larger.

Origin of name: The optimal boundary only depends on the nearest points(support vectors(candidates)).

Solve with QP(Quadratic Programming)

It's equivalent to finding the minimum of

12wTw. And minimum of
12uTQu+pTu
subject to
amTucm
for
m=1,,M
,
where
u=[bw];Q=[00dT0dId];p=0d+1

anT=yn[1xnT];cm=1;M=N

easy with QP solver
uQP(Q,p,A,c)

With non-linear transform

可以像Linear model一樣直接把transform後的資料作為輸入跑Linear SVM,但因為有些transform後的維度(

d~)非常大,像是d維資料的Q-order polynomial transform
ΦQ
d~=O(Qd)
Q=10,d=12
就會爆炸,因此depend on
d~
不利於使用更複雜的transform,要使用對偶來消除

HTML week 10

Dual Support Vector Machine

如上所述,(Non-)Linear SVM要optimize

d~+1 個variables(
w
和b),且符合
N
個條件(
yn(wTzn+b)1
,即每一筆資料都正確分類)。
We want to construct an equivalent SVM with
N
variables and
N+1
constraints. 細節需要太多的數學過程,因此只介紹必要部分。

Tool: Lagrange Multipliers

以regularization舉例

minwEin(w) s.t.
wTwC
minwEaug(w)=Ein(w)+λNwTw

如果想要讓weight length
C
,相當於給定另一個參數
λ

Constrained to Unconstrained

用Lagrange Multipliers把原本

minb,w12wTw s.t.
n,yn(wTzn+b)1
變成
L(b,w,α)=12wTw+n=1Nαn(1yn(wTzn+b))

其中
all αn0
,KKT會用到。

Claim

SVM 相當於minb,w(maxall αn0L(b,w,α))=minb,w( if violate;12wTw if feasible)

violate, feasible: Does

(b,w) satisfy constraints?

Proof of Claim
  • For violating
    (b,w)
    ,then some
    (1yn(wTzn+b)
    is positive, maximizing
    L
    will let corresponding
    αn=
    , so the result is
    too.
  • For feasible
    (b,w)
    , all
    (1yn(wTzn+b)0
    . Since
    all αn0
    , the maximum of the second term(summation)=0, so maximum
    L=12wTw

Lagrange Dual Problem

For any fixed

α with all
αn0
,
minb,w(maxall αn0L(b,w,α))minb,wL(b,w,α)

Because max
α>
any
α
, and this still holds after
minb,w
.
For the best
α
, the above also holds, so
minb,w(maxall αn0L(b,w,α))maxall αn0(minb,wL(b,w,α))

LHS is equivalent to the original SVM, called primal. RHS is called Lagrange dual.

Strong/weak Duality of QP

In the Lagrange dual problem,

  • : weak duality
  • =
    : strong duality, when
    • convex primal
    • feasible primal(
      Φ
      -separable(after transform))
    • linear constraints

Strong duality means there exists a primal-dual optimal solution for both sides.

Solving

eliminate b

Since inner

minb,w has no constraints on
α
(unconstrained), we can simply take a partial derivative on
b
.
L(b,w,α)=12wTw+n=1Nαn(1yn(wTzn+b))L(b,w,α)b=0=n=1Nαnyn

If we want to maximize
L(b,w,α)
, we can set(without loss of optimality) the constraint
n=1Nαnyn=0

Therefore, we can remove b:

minb,w12wTw+n=1Nαn(1yn(wTzn+b)minb,w12wTw+n=1Nαn(1yn(wTzn))bn=1Nαnyn
Under a constraint outside
min
,
n=1Nαnyn=0
.
Since the last term is
0
.

find w

Similarly, we can simply take a partial derivative on

w.
L(b,w,α)=12wTw+n=1Nαn(1yn(wTzn+b))L(b,w,α)wi=0=win=1Nαnynzn,i

We then have
w=n=1Nαnynzn

Then substitute it into the expression:
maxall αn0(minb,w12wTw+n=1NαnwTw)maxall αn0(12n=1Nαnynzn2+n=1Nαn)

Under addtional constraints for
max
:
n=1Nαnyn=0
and
w=n=1Nαnynzn
.

KKT condition

If

(b,w,α) is a optimal solution for Lagrange dual, and

  • 原本的問題有解, primal feasible:
    yn(wTzn+b)1
  • 滿足Dual的條件, dual feasible:
    αn0
  • 滿足Dual的最佳化條件,因此內部是optimal,dual-inner optimal:
    n=1Nαnyn=0
    and
    w=n=1Nαnynzn
  • 滿足原本問題的最佳化條件,因此所有Lagrange terms消失,primal-inner optimal:
    αn(1yn(wTzn+b))=0

Called Karush-Kuhn-Tucker (KKT) conditions

小結

根據以上結論,我們可以用QP解

minall αn0(12n=1Nαnynzn2n=1Nαn)
得出
α
,再用以上條件得出
b,w

w

optimal

α optimal
w=n=1Nαnynzn

b

optimal

α optimal
b
?

根據primal feasible,

yn(wTzn+b)1,給出了
b
的範圍(大部分(non-support vector)都大於1)。
進一步,根據primal-inner optimal,
αn(1yn(wTzn+b))=0, n

由於non-SV後面都是non-zero,因此
αn=0
。因此若
αn>0
,可以得出:
1yn(wTzn+b)=0,yn(wTzn+b)=1yn=±1,yn=1ynb=ynwTzn

High-level comments

比較 SVM, PLA

SVM PLA
wSVM=nαn(ynzn)
wPLA=nβn(ynzn)
αn
從 dual solution。
βn=
# of mistake corrections on
(xn,yn)

w is linear combination of
ynzn
. This is also true for GD/SGD-based Logistic regression/Linear regression when
w0=0
.
w
is represented by data.
SVM: represented by SVs only.

比較 primal 與 dual

Problems

  • 因為QP的kernel
    Q
    是一個 N-by-N 的矩陣,其中
    qn,m=ynymznTzm
    大部分是Non-zero,因此當N大一點就會需要很多記憶體來存
    Q

    解決:practically用特殊的solver
  • 原本的目標:不要與轉換後的特徵數量
    d~
    相關,但其實如果真的去計算每個
    qn,m=ynymznTzm
    ,會是兩個
    d~
    長度的向量內積。
    解決:kernel SVM

Kernel Support Vector Machine

目標:解決上述暴力計算

qn,m=znTzmn,m[1,N] 時需要
O(d~)
的問題。

Kernel function

=Transform+Inner Product
用有效的Kernel function快速計算

znTzm=Φ(xn)TΦ(xm)

Example for

Φ2(poly transform)
Φ2(x)=(1,x1,,xd,x12,x1x2,,x1xd,x2x1,x22,,xd2)

speed up Q for QP solver

考慮計算

Φ2(x)TΦ2(x)=1+i=1dxixi+i=1dj=1d(xixj)(xixj)=1+i=1dxixi+(i=1dxixi)(j=1dxjxj)=1+xTx+(xTx)2

Note:

d 是原本資料的維度,而
d~=O(d2)
是轉換後的維度,如果在
O(d)
時間算完是可接受的。

speed up b,w

HTML week 11

Soft-Margin Support Vector Machine

SVM for Soft Binary Classification

Blending and Bagging

An Aggregation Story

aggregation for binary classification

假設有

T 個朋友,每個人對一個股票的預測為
g1,,gT
函數,對於股票
x
sign(gt(x))
代表漲跌。而根據這些朋友的結果做綜合的預測有哪些方法?

  • select 找表現最佳的朋友,只照抄他的預測,validation
    G(x)=gt(x)
    with
    t=argmintEval(gt)
    .
  • mix 所有朋友的預測,一人一票,uniformly
    G(x)=sign(t1gt(x))
  • mix 同上但是加上權重
    α
    non-uniformly
    G(x)=sign(tαtgt(x))
    with
    αt0
  • combine(stacking) 預測什麼類股就主要參考那個類股的專家。權重depends on input,conditionally
    G(x)=sign(tqt(x)gt(x))
    with
    qt(x)0

比較

  • Selection
    也就是第一種,很簡單也很常用, rely on strong hypothesis
    當然應該用
    Eval
    而不是
    Ein
    ,但同樣的需要確保validation用的
    gt
    夠強
  • aggregation/blending
    參考其他弱一點的朋友(hypothesis)可能會更好

Why blending may be better

  • acts as feature transform: 把2D平面上只能用鉛直線的
    H1
    和只能用水平線的
    H2
    ,blending後就可以用具有直角的線。
  • acts as regularization: 平均後,比如 linear regression 就能得到類似 SVM 的效果。

Blending for regression

以uniform blending舉例

G=gt的平均,也就是
G(x)=1Ttgt(x)

Theoretical analysis for uniform blending

avgt(Eout(gt))=avgt((gt(x)f(x))2)=avgt(gt22gtf+f2)=avgt(gt2)2Gf+f2=avgt(gt2)+(Gf)2G2=avgt(gt2)2G2+G2+(Gf)2=avgt((gtG)2)+(Gf)2=avgt((gtG)2)+Eout(G)Eout(G)

Therefore, the uniform blending is better than the average of

gt.

This can also be interpreted as:
(expected performance of randomly choosing one hypothesis)
= (expected deviation to consensus)
+ (performance of consensus).

  • performance of consensus: bias
  • expected deviation to consensus: variance

Uniform blending reduces variance for more stable performance.

HTML week 12

Linear blending

Known

gt, and each is given
αt
ballots.
G(x)=sign(tαtgt(x)) with αt0

Compute good
αt
:
minαt0Ein(α)

For linear regression(+transform), it looks alike.
minαt01Nn=1N(yntαtgt(xn))2

有些 hypothesis 可能是反指標,所以

αt 可以是負的,因此不一定需要
αt0
的 constraints。

Any blending

Blending 相當於把

(x,y) 變換為
(Φ(x),y)
,其中
Φ(x)=(g1(x),g2(x),)

之後 Linear blending 相當於做 linear regression。
事實上也可以用其他模型,也就是 Any blending ,相當於 Stacking(blending 權重與資料有關)。
雖然很 powerful,但一樣會 overfitting。

Bagging

如果能找出多樣化的 hypothesis,效果會更好。
可能方法:

  • 每個
    gt
    用不同 hypothesis set
  • 用不同參數(learning rate等)
  • 隨機性的驗算法
  • 資料的隨機性(CV的不同資料切割,產生不同
    gt
    )

而實際上可以用同一份資料利用資 料隨機性製造出不同的

gt

Bootstrap aggregation

D~t:

  • Sample
    N
    (or
    N
    ) data points with replacement(可能選到同筆資料很多次) from
    D
  • Train
    gt
    by an algorithm
    A
    on
    D~t
    .
  • Do the above many times. Output the blending
    G=Uniform({gt})

This simulates the real aggregation:

  • Request size-
    N
    data from
    PN
    (i.i.d.)
  • Train
    gt
    by an algorithm
    A
    on
    D~t
    .
  • Do the above many times. Output the blending
    G=Uniform({gt})

因為我們沒有辦法真的每次得到不同的

N 筆資料,所以重複取樣是一個近似的方法。

又稱為 Bagging,把資料打包。

bagging performance

如果 hypothesis 對隨機資料很敏感(指產生多樣化的結果),很有可能平均後的效果會很好。(像是沒教的 pocket algorithm)

Adaptive Boosting

辨認蘋果問題

叫一堆小孩講出可能的判斷方法:

  • 圓的
  • 紅色
  • 也有可能是綠色
  • 有可能長著梗

過程中會得出一個班級的共識老師再把錯誤的分類結果提出來讓小孩再想一想。

對應到 ML

  • 小孩 = (simple, weak) hypothesis sets
  • 班級的共識 = blending 後的 hypothesis
  • 老師 = reweighting,讓 hypothesis 聚焦在錯誤的地方

Use Bootstrap Again

Bootstrapping 相當於把N筆資料重新給予權重,有些可能是 0,有些可能是很多次。
每個

gt 相當於在 minimize bootstrap-weighted error。
Einu(h)=1Nn=1Nunerr(h(xn),yn)

Weighted base algorithm

可以重複某些資料,但也可以用演算法來達成,像是

  • soft SVM: 若是使用一個錯誤增加
    C
    的 error,變成每次錯誤加
    Cun
    就好。
  • 用 SGD 解 logistic regression: 調整 sample 到第
    n
    筆的機率正比於
    un

More diverse results

重複 T 次,第 t 次使用

u(t) 作為權重,我們希望每次結果會非常不同:

  • u(t)
    作為權重,得出
    gt
  • 我們希望
    gt
    在以
    u(t+1)
    作為權重時表現很差,因此
    gt+1
    會與
    gt
    有很大的差異。
  • 根據
    gt
    對不同的回答情況

具體作法就是讓

gt 在以
u(t+1)
作為權重時的準確率為 0.5。
我們想要:
n=1Nun(t+1)[[gt(xn)yn]]n=1Nun(t+1)=0.5

因此我們可以把
u(t+1)
設為:

  • gt
    在回答正確
    n
    的權重
    un(t+1)
    設為
    un(t)
    除以正確的比率
  • gt
    在回答錯誤
    n
    的權重
    un(t+1)
    設為
    un(t)
    除以錯誤的比率。

或是交叉相乘:把正確的乘上錯誤率(次數),錯誤的乘上正確率(次數)

Scaling factor

gt
u(t)
的錯誤率是
ϵt
。前一部分的方法相當於把正確的乘以
ϵt
,錯誤的乘以
1ϵt

因此可以取他們的中間值
Scaling Factor=St=1ϵtϵt

正確時除以
St
,錯誤時乘以
St

這會在之後用到。

如何決定
u(1)

Best for

Ein,則用
un(1)=1N
(相當於沒有 reweighting)。

如何決定 blending 方法 G

不太可能用 uniform,因為

g2 是在正常的
g1
表現很差的資料訓練,這個資料會與原本的資料偏差很大,很有可能結果會很差,其他結果也是差不多。
Linear 或 Non-linear 都行

AdaBoost

使用特殊 blending 方法:

αt=ln(St),因為 Scaling Factor 與正確率正相關,所以相當於給越正確的 hypothesis 越多的權重。

AdaBoost = 弱的 hypothesis(學生) + reweighting(老師) + blending(整個班)

Theoretical guarantee

If

max(ϵt)=ϵ<12,
Ein(G)=0
after
T=O(logN)
iterations.

Decision Stump

在某一維度上,用一個 threshold 來分類。非常弱,但很有效率。

N
d
維資料可以在
O(dNlogN)
的時間完成。

AdaBoost-Stump

用 Decision Stump 作為 hypothesis,用 AdaBoost 來訓練。
第一個實時辨認人臉的系統就是用這個方法,把圖片切成很多塊,並且用 Decision Stump 來判斷是否有人臉。

補充

  • AdaBoost 很強大,因此要小心 overfitting。
    中小型的資料上可以用 (soft) SVM,可以達到類似的結果(regularization、margin)。
  • Ein=0
    後繼續做還是可以降低
    Eout
    ,因為可以達到更小的 margin。
  • 比較適合二元分類,多元可以用 Gradient Boosting。
  • 比神經網路差。

Decision Tree

Decision Tree 可以達到 conditional aggregation,也就是 stacking。

aggregation blending learning example
uniform voting bagging
weighted linear boosting
conditional stacking Desicion Tree

Decision tree 就是一堆 if-else 的組合,每個 if-else 就是一個 node。
是個很接近人類邏輯的模型,也很容易解釋、很簡單(很多財經分析也許會用)、很有效率。但是沒有理論保證,不知道該怎麼選擇參數、沒有代表性的演算法。

表示方法

  • Path: Summation for every path t,
    G(x)=tqt(x)gt(x)

    q: condition, g: leaf 上的 hypothesis(可以用常數)
  • Recursive: Summation for every child c
    G(x)=cbt(x)Gc(x)

    b: child's condition, G: child's subtree's hypothesis

建 Decision tree 的演算法

  • 停止條件
    到達應該做出葉節點的地方(termination criteria)則回傳
  • 如果要繼續
    • 決定節點的條件
      b(x)
      (branching criteria)
    • 分成不同的節點,遞迴建Decision Tree
    • 回傳

需要選擇的事

  • 停止條件
  • 小孩數量
  • 節點分枝條件
  • 葉節點的 hypothesis

Classification and Regression Tree (CART)

節點分枝條件

可以簡單的用 decision stump 來當作節點分枝條件的 hypothesis set,相對應的小孩數量就是 2(binary tree)。

節點分枝條件的決定:盡量找出分群後的結果能讓不純程度(用 Impurity Function 決定)最小的 hypothesis。差不多相當於 error function。
具體就是把不同群的 impurity function 以群的大小加權平均。

Impurity Function
  • Ein
    of optimal constant hypothesis:
    • Regression with MSE:
      y¯=avg(y1,,yn)
      ,
      impurity=1Nn=1N(yny¯)2
    • Classification with 0-1 loss:
      y=majority(y1,,yn)
      ,
      impurity=1Nn=1N[[yny]]
  • Special for classification
    • Gini index:
      Nk=n=1N[[yn=k]]
      ,
      impurity=1k=1K(NkN)2

      考慮所有
      k
    • classification error:
      impurity=1maxk(NkN)

      只考慮最常見的
      k=y

分類通常用 Gini index,回歸用第一種。

停止條件

CART 是 fully-grown tree,因此會分到不能分為止,具體有這些條件:

  • Impurity=0,label 都一樣,沒辦法分
  • xn
    都一樣,沒辦法分

葉節點的 hypothesis set

因為結果會是不能繼續分的,可以直接用 optimal constant hypothesis。

Regularization by Pruning

One regularizer:

Ω(G)=NumberOfLeaves(G)
變成對於所有的 decision tree
G
,找到
argminGEin(G)+λΩ(G)

但當然無法找到所有的 decision tree,所以通常只會考慮:

  • G(0)
    =fully-grown tree
  • G(i)
    =
    argminGEin(G)

    其中
    G
    是從
    G(i1)
    少掉一個葉節點。

找到

λ 的方法:validation

用類別特徵分枝

對應到 decision stump,會用 decision subset。

b(x)=[[xiS]]+1,其中
S[K]

一樣是個二元樹,所以就是一個包含於
S
、一個不包含於
S

Surrogate branching

用其他類似的特徵來取代缺失的特徵。
但實際上不一定能找到全部都沒有缺失的特徵,比如在 final project 大概就用不到。

HTML week 13

Random Forest

用 bagging 的方法把

T 個 Fully-grown Decision Tree 的輸出結合起來

OOB examples

假設 bagging 每次抽

N=N 個,那每個
t
沒抽到
(xn,yn)
的機率是
(11/N)N
,當
N
大了的話:
(11N)N=1(NN1)N=1(1+1N1)N1e

每次大約會有
N/e
個沒抽到,比想像中還多。
用處: 可以對於每個
gt
剛好可以用它的 OOB examples 當作 validation。剛好就不用重新訓練。

實測

在複雜的資料上,也能得到很好的結果,這就是投票的力量。

T 要多少?

越多越好,實際上大概需要幾千幾萬這個量級。
壞處就是要算很多次 Decision Tree。

Gradient Boosted Decision Tree

(Ada)Boost + Decision Tree

HTML week 14

Neural Network

Intuition: 多個 perceptrons,加上 activation (模仿神經,用簡單的門檻,過某個值才是 1,否則是 0,相當於一個 perceptron 得到其他 perceptrons 的輸出作為輸入),可以造出 AND OR NOT 等等的邏輯閘。多層的話就更強。
為了簡化,用 MSE error。

Activation(Transformation)

如果只是加起來,整個還是 Linear Model,所以沒差,提到 sigmoid、tanh,會提到為何

tanh 現在比較少用。
tanh(s)=exp(s)exp(s)exp(s)+exp(s)=2θ(2s)1

Hypothesis

For a

d(0)d(1)d(L) Neural Network:

wij(l)

  • 1lL
    : layers
  • 0id(l1)
    : inputs
  • 1jd(l)
    : outputs

raw output

sj(l)=i=0d(l1)wij(l)xi(l1)
transformed output
xj(l)={A(sj(l)),if l<Lsj(l),if l=L

universal approximator:
Neural Network 能夠模仿任何函數,實際上就算只有一層,只要 neuron 夠多也可以達到。像是 Gaussian Kernel 很強的概念一樣。

adaboost 難以與 perceptron 並用。

可以用(stochastic)gradient descent來minimize loss(error)
簡單暴力的把error對w取偏微分,會得到de/dw=de/ds*ds/dw,但除了輸出層的s直接與e關連,其他需要用 backward propagation 算。

automatic differentiation

直接真的用很少的偏移看看結果差多少作為微分結果。

optimize gives local minimum

如果只用 gradient descent,只會得到 local minimum,因此 init weights 很重要,像是太大的話梯度很小,會「飽和」,可以試試看小又隨機的 weight。
但後來發現其實不太會跑到 bad local minimum,只要用經驗法則選好的 weights 就好了。或是pre-training

initialization

  • 全 0,tanh relu都無法運作
  • 一樣,所有 neuron 都長一樣
  • 太大,梯度消失(tanh 出來的值差不多)

因此需要 small and random

Regularization

Early Stopping: 因為 gradient descent 類型的 model 在步驟多了之後會探索更多區域,相當於

dvc 漸漸增大,因此可以用 validation error 早點停下來。但有可能 validation error,
Eout
會在之後再次下降。
這是早期流行的方法,現在會用 double descent,

Deep learning

Pre-training

  • shallow networks: RBM,可以把其他層固定,每次只訓練幾層。
  • other tasks: 用 self-supervised learning 做 foundation model

Activation and Initialization

Optimization in Deep Learning