# Machine learning 003 -Deep learning ### 前言 老實說放前言只是因為我覺得直接放筆記很好笑,所以加了這個段落! 至於為啥第三周才開始寫筆記呢? 純粹是因為我前面兩周的課沒有很認真地聽,寫不出功課才跑去跟教授裝可憐,雖然最近應該會補上啦,但反正筆記就從第三堂課開始! ## 3.1 概論 在進入深度學習前的兩堂課是機器學習,所以簡單的複習一下機器學習在進入正題: * 機器學習: y= g(Xi|θi) 其中,y作為我們要找的label, g代表假設空間,Xi作為features,而θi作為weights。 * 深度學習: 機器學習的分支,a new take on learning <font color="#f00">representations from data</font> that puts an emphasis on learning successive layers(連續的layer,每一個layer可以做為一個函數) of increasingly meaningful representations. :bulb: 在深度學習中,在input layer與output layer中間的不一定是divident layer,也可以是其他參數 ### 3.1.1 深度學習的運作 **Step 1: Stored input data in the layer’s weights** | 複習一下PDE | | -------- | | 過去我們使用分離變數法,會有C1 C2等變數,再代入邊界去解出變數,此方法為B.V.P。在機器學習中,我們的neuron為基底函數、但並非正交、也沒有邊界所以需要去猜θ(越小越好),所以我們要去算其gredient | 機器學習跟數學好不好關聯性很高!!! 基底會與overfitting有關(若基底不獨立就會發生),但這屬於演算法的範疇。 ![](https://i.imgur.com/riLPNeC.png) :bulb: Input相當於Data, Layer作為基底(我們要解的就是基底),Y作為Label、也就是我們要預測的結果,這個部分為監督式學習。 **Step 2: Measure how far this output is from what you expected.** 此步驟與最佳化有關,要確定其residual(在機器學習中稱為loss function) ![](https://i.imgur.com/VKL8sXp.png) :bulb: 此處的True target 作為ground truth :bulb:Gradient decent會告訴我們參數(weight)往哪邊移動比較好 :bulb:Loss score 最常用的方式有: 1. MSE 2.cross- entropy 3. Focal loss& Hinge loss (但loss的調整會目前還不先做討論) **Step 3: To use score as a feedback signal to adjust the value of the weights a little, in a direction that will lower the loss score for the current example.(簡而言之就是求gradient,途中的Optimizer!)** ![](https://i.imgur.com/OuapAic.png) :bulb:原則上沒有唯一解! 因為neuron獨立也沒正交,所以在機器訓練時才會結果不一樣。 :bulb:一個training loop 稱為epoch :pushpin: 做DL前你要先釐清有沒有好且完整的DATA,也必須要對於你的問題非常理解,訓練出來的東西才會是有用的! ### 3.1.2 Artificial Neural Networks: The Perceptron (感知器) Network Introduction off ANN -最早期的應用就是Perception,概念與神經元很像:需要達到閾值才會啟動。 ![](https://i.imgur.com/nnr69Nw.png) ▲ A Perceptron network composed of n input signals, representing the problem being analyzed, and just one output. 數學算式為: g[(w1x1+w2x2+w3x3+....)+w0] 其中x代表的是input,g(u)為activation function 並且符合: 1. features 互相獨立 2. wi屬於實數。 | Q: What are the possible output values possibly produced by the Perceptron? | | --------------------------------------------------------------------------- | | A: 1 & -1 二元分類模型| ![](https://i.imgur.com/C7Zbq25.png) Example: ![](https://i.imgur.com/w0i5tim.png) 在此圖中x1共有八個、輸入有三個位置,因此Input(8,3),數學式為Stp(0.3x1+0.3x2+0.3x3+0.4)= ? ### 3.2.1 Training Process of the Perceptron :star: 重點是調整weight(w)跟threshold(θ),而調整的方向與input signal有關 ![](https://i.imgur.com/AePrdEv.png) The learning rate determines how fast the training process will take to its convergence (stabilization). The choice of should be done carefully to avoid instabilities in the training process,and it is usually defined within the range<font color="#f00"> 0 < learning rate ≤ 1.</font> ### 3.2.2 Implementing a perceptron learning algorithm in Python ![](https://i.imgur.com/2s5D1Vp.png) |:bulb: 如果是一個class(物件),第一個字一定要大寫 | | ------------------------------------------------ | |:ab: 在class 後的()內所做的動作為繼承 | | 標錯的值會被留下來 (0 or -1) | | default constructor是python內部設定的 | ## 3.3 Artificial Neural Networks: Multi-Layer Perceptrons (MLPs) :bulb: At least one intermediate (hidden) neural layer.為連續函數(連續矩陣) ![](https://i.imgur.com/zIC3KmW.png)