SlideShare a Scribd company logo
1 of 40
Download to read offline
國立臺北護理健康大學 NTUNHS
Neural network Analysis
Orozco Hsu
2022-12-05
1
About me
• Education
• NCU (MIS)、NCCU (CS)
• Work Experience
• Telecom big data Innovation
• AI projects
• Retail marketing technology
• User Group
• TW Spark User Group
• TW Hadoop User Group
• Taiwan Data Engineer Association Director
• Research
• Big Data/ ML/ AIOT/ AI Columnist
2
Tutorial
Content
3
前饋神經網路(感知器網路)
Homework
神經網路
倒傳遞神經網路
Code
• Download code
• https://github.com/orozcohsu/ntunhs_2022_02
• Folder
• 20221205
4
建立環境
• 切換執行環境
5
建立環境
• 開啟 jupyterlab
6
神經網路介紹
• 淺層的神經網路 (Universal approximation theorem)
• 一個簡單的 Feedforward network,只包含了一個 hidden layer,並且
有適當的 activation function;包含有限個神經元的情況下,可以去逼
近(近似)任何連續函數。
7
參考: http://www.feiguyunai.com/index.php/2019/
神經網路介紹
• 典型的神經網路具有以下三個構造:
• 結構:
• 結構指定了網路中的各單元和它們的關係。
例如:輸入值、權重、激活值、bias、輸出值。
• 激活函數:
• 定義神經元如何根據其他神經元的活動來改變激活值。
• 學習規則:
• 指定了神經網路中的權重如何隨著迭代計算而調整更新。
8
神經網路介紹
• 神經網路構造
9
激活函數
激活值
輸入值
權重
bias
輸出值
神經網路介紹
• 激活函數
• Sigmoid (S 函數),取值範圍 (0,1),很適
合用來做二元分類。
• 優點: 函數平滑,容易求導數。
• 缺點: 倒傳遞神經網路計算時,很容易出
現梯度消失狀況,因此無法完成深層網路
的訓練。
10
逼近任何連續函數
• 我們都會將一個現實中的問題化成一個數學問題,一個數學問題基本
上都是包含函數的。
• 幾乎人類的問題都可以化成一個函數來解答:
• 圖像辨識: f(image) => classes
• 語音轉文字: f(speech) => text
• 機器人聊天: f(text) => text
• 所以可以逼近(近似)任何連續函數的模型就可以解答任何問題。
11
逼近任何連續函數
• 這個世界上的問題分類下列四類
• 無解之題
• 可解之題 (polynomial time)
• 需要exponential time 才能解決
• NP問題
12
前饋神經網路
• 前饋神經網路 (Feedforward Neural Network, FNN) 是最早被
提出來的神經網路。
• 資料從輸入層、流過hidden layer計算過程、最後抵達輸出層。
• 神經元(Neuron)之間沒有連接。
• 感知器網路(Perceptron)、多層感知器都稱為前饋神經網路。
13
前饋神經網路
• 一個簡單的單層感知器網路的架構如下
14
一個二維 Perceptron 分類器 一個多維(R)輸入的
Perception 分類器
使用 hardlim 當作 activation function,該 function 即是一個 step function,輸入值在給定 threshold 值以上,輸出 1
參考: https://ithelp.ithome.com.tw/articles/10201407
p
p
p
p
p
感知器網路
• 黑點的分類標籤被標註為 1,而白點的分類標
籤被標註為 -1。
• 產生隨機初始化 decision line 的法線向量 w。
• 藍色實線為該步驟所計算得到的 decision line
和它的法線(藍色箭頭)。
• 當 bias 為零, decision line 就必須通過原點。
15
參考: https://vocus.cc/article/5cc914d6fd8978000171ac06
感知器網路
• 對所有的訓練樣本,逐一比較 decision line
計算後,更新 decision line 的正交向量。
• 若訓練樣本為黑點,且分類錯誤,則將
decision line 的正交向量往靠近分類錯誤的
訓練樣本的方向移動。在此是利用向量加法
的方式移往黑點所在方向。
16
感知器網路
• 若訓練樣本為白點,且分類錯誤,將 decision line 的正交向量
往遠離分類錯誤的訓練樣本的方向移動。在此是利用向量減法的
方式遠離白點所在方向。
• 若沒有分類錯誤,則 decision line 的正交向量維持不動。
17
感知器網路
• 重複以上步驟,持續改變 decision line (線性方程式)的 w (權重),
直到所有的訓練樣本都已經分類正確,或超過最大迭代數目。
18
參考: https://www.gushiciku.cn/pl/pNEb/zh-tw
感知器網路
• 感知器網路對於線性不可分的樣本,盡量試圖找到 decision line,
能夠最好地分開這些資料。
• 最終感知器網路得到 88% 測試準確度。
19
多層感知器
• 單層感知器網路為簡單的學習方法,有一個致命的缺點:
• 它無法學習過於複雜,或線性不可分的樣本。
20
參考: https://tw.pays-tarusate.org/652265-what-are-xand-and-xor-UNIUJR
多層感知器
• 在單層感知器上的基礎上發展多層感知器 (Multi-layer Perceptron,
MLP),透過倒傳遞神經網路進行參數學習。
• 是一種通用的函數逼近(近似)方法,可以被用來擬合複雜函數,解決
分類或預測的問題,是一種監督式學習。
• 80年代是相當流行的演算法,但至90年代被SVM取代關注,直到深度
學習又重新獲得關注,尤其是卷積神經網路,能有更深的網路層且參
數更少。
21
多層感知器
• 線性可分與線性不可分(無法透過一條直線區分 XOR 的資料)
22
多層感知器
• 多層感知器
• 藉由疊加多層的非線性啟動函數,得到一個非線性的分類函數(曲線),正
確地將所有的樣本分類。
• 多一層的非線性函數映射,又被稱為隱藏層(hidden layer)。
23
參考: https://www.itread01.com/content/1545963318.html
多層感知器
• 將斜對角、同分類標籤的子區域內
的訓練樣本,映射到新的特徵維度
中
• 在這個新的特徵維度中,分類標籤
為 1 的點,會映射到相同的座標位
置
• 隱藏層(hidden layer) 藉由多重映
射非線性函式,所學到的是新的特
徵向量
• 此新組合的特徵向量足以代表該分
類的獨特之處,而能分辨其他類別
24
參考: https://www.deeplearningbook.org/contents/mlp.html
(XOR為斜對角資料)
hidden layer
多層感知器可以解決更為複雜的數據
多層感知器
• 神經網路classification
• 神經網路regression
25
延伸閱讀
• 資料預處理
• 【QA】歸一化(Normalization)、標準化(Standardization)、中心化
(Zero-centered)分別是甚麼? – Cupoy
26
多層感知器
• 參考 sklearn 官網說明 (MLPClassifier)
• https://scikit-learn.org/stable/modules/generated/sklearn.neural_network.MLPClassifier.html
• 參考 sklearn 官網說明 (MLPRegressor)
• https://scikit-
learn.org/stable/modules/generated/sklearn.neural_network.MLPRegressor.html#sklearn.
neural_network.MLPRegressor
27
MLPClassifier.ipynb
MLPRegressor.ipynb
參數: hidden_layer_sizes=(5, n-2)
如果n為5,表示共有3個隱藏層,每層有5個神經元
倒傳遞神經網路
• 目的為更新神經網路權重,好的權重就會有準確的模型效果。
• 代價函數J(Ө)
• 預測結果與真實結果的差距。
• 如果預測完全正確,則代價函數為0。
• 所以,當我們修正參數權重的時候,目標就是代價函數要越小越好。
• 當變數為線性關係時,代價函數J(Ө)是凸函數
• 真實世界變數之間為非線性關係,代價函數J(Ө)不是凸函數,意
味有多個局部最小值。
28
29
參考: 機器學習的衰頹興盛:從類神經網路到淺層學習 - StockFeel 股感
透過微積分計算出斜率 (導數),我們可以計算出山坡上最陡峭的那一個方向,這種微積分概念稱為
「梯度」。只要朝著梯度的方向走去,就是最快下降的道路了,稱之「梯度下降」
斜率為0
斜率為0
梯度下降是一種優化器 (Optimizer),比直接求導好很多
倒傳遞神經網路
30
參考: http://galaxy.agh.edu.pl/~vlsi/AI/backp_t_en/backprop.html
倒傳遞神經網路
31
Feedforward
倒傳遞神經網路
32
Feedforward
倒傳遞神經網路
• 輸出層:
• 計算誤差:
33
Feedforward
預測值
實際值
倒傳遞神經網路
• 反向計算每一個神經元的 error signal (δ) * 權重。
34
Backward
倒傳遞神經網路
35
• 反向計算每一個神經元的 error
signal (δ) * 權重。
Backward
倒傳遞神經網路
• 完成所有反向神經元計算後,開始更新權重 (w)。
• 學習率 (Learning rate): 控制每次以最陡坡降法最小化誤
差函數的步幅。
36
對e進行偏微分
透過連鎖率(chain rule) 完成偏微分計算
https://zh.wikipedia.org/wiki/%E9%93%BE%E5%BC%8F%E6%B3%95%E5%88%99
Backward
倒傳遞神經網路
37
Backward
欲防止梯度消失、梯度爆炸,因此可以選擇特殊的激活函數 (activation)
延伸閱讀
• 比較其他的優化器收斂速度:
38
參考: https://www.itread01.com/content/1543235713.html
延伸閱讀
• 卷積神經網路(Convolutional Neural Network, CNN)是一種
前饋神經網路
39
Homework
• 請描述神經網路結構與功能描述
• 請說明激活函數的目的
• 請說明優化器的目的
• 利用多層感知器網路進行iris.csv 分類,嘗試對不同參數的理解
• https://goo.gl/281mPF
• [加分題]利用深度學習進行 iris.csv 分類
• Keras: 第10章 项目:多类花朵分类 ·深度学习:Python教程
(cnbeining.github.io)
• Pytorch: Day23-pytorch(6)iris資料集示範classifier模型pytorch完整訓練過
程 - iT 邦幫忙::一起幫忙解決難題,拯救 IT 人的一天 (ithome.com.tw)
40

More Related Content

Similar to 5_Neural_network_碩士班第五次.pdf

machine learning introduction
machine learning introduction machine learning introduction
machine learning introduction FEG
 
3 clustering 1
3 clustering 13 clustering 1
3 clustering 1FEG
 
2_Clustering.pdf
2_Clustering.pdf2_Clustering.pdf
2_Clustering.pdfFEG
 
分布式存储与TDDL
分布式存储与TDDL分布式存储与TDDL
分布式存储与TDDLmysqlops
 
Microsoft recommendation solution on azure
Microsoft recommendation solution on azureMicrosoft recommendation solution on azure
Microsoft recommendation solution on azureDuran Hsieh
 
1到100000000 - 分布式大型网站的架构设计
1到100000000 - 分布式大型网站的架构设计1到100000000 - 分布式大型网站的架构设计
1到100000000 - 分布式大型网站的架构设计RolfZhang
 
TensorFlow 深度學習快速上手班--深度學習
 TensorFlow 深度學習快速上手班--深度學習 TensorFlow 深度學習快速上手班--深度學習
TensorFlow 深度學習快速上手班--深度學習Mark Chang
 
1_大二班_資料視覺化_20221028.pdf
1_大二班_資料視覺化_20221028.pdf1_大二班_資料視覺化_20221028.pdf
1_大二班_資料視覺化_20221028.pdfFEG
 
Deep Learning Advance: #01 Domain Adaptation
Deep Learning Advance: #01 Domain AdaptationDeep Learning Advance: #01 Domain Adaptation
Deep Learning Advance: #01 Domain AdaptationTerence Huang
 
Mealionaire: A context-aware and ontology-based mobile recommender system for...
Mealionaire: A context-aware and ontology-based mobile recommender system for...Mealionaire: A context-aware and ontology-based mobile recommender system for...
Mealionaire: A context-aware and ontology-based mobile recommender system for...Carter Chen
 
2023 Data visualization using Python from scratch
2023 Data visualization using Python from scratch2023 Data visualization using Python from scratch
2023 Data visualization using Python from scratchFEG
 
2_學院碩士班_資料視覺化_20220411_0509.pdf
2_學院碩士班_資料視覺化_20220411_0509.pdf2_學院碩士班_資料視覺化_20220411_0509.pdf
2_學院碩士班_資料視覺化_20220411_0509.pdfFEG
 
Neural Network Basics
Neural Network BasicsNeural Network Basics
Neural Network BasicsOkis Chuang
 
IT445_Week_8.pdf
IT445_Week_8.pdfIT445_Week_8.pdf
IT445_Week_8.pdfAiondBdkpt
 
BDTC2015 阿里巴巴-鄢志杰(智捷)-deep learning助力客服小二:数据技术及机器学习在客服中心的应用
BDTC2015 阿里巴巴-鄢志杰(智捷)-deep learning助力客服小二:数据技术及机器学习在客服中心的应用BDTC2015 阿里巴巴-鄢志杰(智捷)-deep learning助力客服小二:数据技术及机器学习在客服中心的应用
BDTC2015 阿里巴巴-鄢志杰(智捷)-deep learning助力客服小二:数据技术及机器学习在客服中心的应用Jerry Wen
 
云存储与虚拟化分论坛 基于云计算的海量数据挖掘
云存储与虚拟化分论坛 基于云计算的海量数据挖掘云存储与虚拟化分论坛 基于云计算的海量数据挖掘
云存储与虚拟化分论坛 基于云计算的海量数据挖掘Riquelme624
 
藍芽臂式血壓計
藍芽臂式血壓計藍芽臂式血壓計
藍芽臂式血壓計艾鍗科技
 
张松国 腾讯微博架构介绍08
张松国 腾讯微博架构介绍08张松国 腾讯微博架构介绍08
张松国 腾讯微博架构介绍08drewz lin
 

Similar to 5_Neural_network_碩士班第五次.pdf (19)

machine learning introduction
machine learning introduction machine learning introduction
machine learning introduction
 
3 clustering 1
3 clustering 13 clustering 1
3 clustering 1
 
2_Clustering.pdf
2_Clustering.pdf2_Clustering.pdf
2_Clustering.pdf
 
分布式存储与TDDL
分布式存储与TDDL分布式存储与TDDL
分布式存储与TDDL
 
Microsoft recommendation solution on azure
Microsoft recommendation solution on azureMicrosoft recommendation solution on azure
Microsoft recommendation solution on azure
 
1到100000000 - 分布式大型网站的架构设计
1到100000000 - 分布式大型网站的架构设计1到100000000 - 分布式大型网站的架构设计
1到100000000 - 分布式大型网站的架构设计
 
TensorFlow 深度學習快速上手班--深度學習
 TensorFlow 深度學習快速上手班--深度學習 TensorFlow 深度學習快速上手班--深度學習
TensorFlow 深度學習快速上手班--深度學習
 
LabView with Lego NXT
LabView  with Lego NXTLabView  with Lego NXT
LabView with Lego NXT
 
1_大二班_資料視覺化_20221028.pdf
1_大二班_資料視覺化_20221028.pdf1_大二班_資料視覺化_20221028.pdf
1_大二班_資料視覺化_20221028.pdf
 
Deep Learning Advance: #01 Domain Adaptation
Deep Learning Advance: #01 Domain AdaptationDeep Learning Advance: #01 Domain Adaptation
Deep Learning Advance: #01 Domain Adaptation
 
Mealionaire: A context-aware and ontology-based mobile recommender system for...
Mealionaire: A context-aware and ontology-based mobile recommender system for...Mealionaire: A context-aware and ontology-based mobile recommender system for...
Mealionaire: A context-aware and ontology-based mobile recommender system for...
 
2023 Data visualization using Python from scratch
2023 Data visualization using Python from scratch2023 Data visualization using Python from scratch
2023 Data visualization using Python from scratch
 
2_學院碩士班_資料視覺化_20220411_0509.pdf
2_學院碩士班_資料視覺化_20220411_0509.pdf2_學院碩士班_資料視覺化_20220411_0509.pdf
2_學院碩士班_資料視覺化_20220411_0509.pdf
 
Neural Network Basics
Neural Network BasicsNeural Network Basics
Neural Network Basics
 
IT445_Week_8.pdf
IT445_Week_8.pdfIT445_Week_8.pdf
IT445_Week_8.pdf
 
BDTC2015 阿里巴巴-鄢志杰(智捷)-deep learning助力客服小二:数据技术及机器学习在客服中心的应用
BDTC2015 阿里巴巴-鄢志杰(智捷)-deep learning助力客服小二:数据技术及机器学习在客服中心的应用BDTC2015 阿里巴巴-鄢志杰(智捷)-deep learning助力客服小二:数据技术及机器学习在客服中心的应用
BDTC2015 阿里巴巴-鄢志杰(智捷)-deep learning助力客服小二:数据技术及机器学习在客服中心的应用
 
云存储与虚拟化分论坛 基于云计算的海量数据挖掘
云存储与虚拟化分论坛 基于云计算的海量数据挖掘云存储与虚拟化分论坛 基于云计算的海量数据挖掘
云存储与虚拟化分论坛 基于云计算的海量数据挖掘
 
藍芽臂式血壓計
藍芽臂式血壓計藍芽臂式血壓計
藍芽臂式血壓計
 
张松国 腾讯微博架构介绍08
张松国 腾讯微博架构介绍08张松国 腾讯微博架构介绍08
张松国 腾讯微博架构介绍08
 

More from FEG

Sequence Model pytorch at colab with gpu.pdf
Sequence Model pytorch at colab with gpu.pdfSequence Model pytorch at colab with gpu.pdf
Sequence Model pytorch at colab with gpu.pdfFEG
 
資料視覺化_透過Orange3進行_無須寫程式直接使用_碩士學程_202403.pdf
資料視覺化_透過Orange3進行_無須寫程式直接使用_碩士學程_202403.pdf資料視覺化_透過Orange3進行_無須寫程式直接使用_碩士學程_202403.pdf
資料視覺化_透過Orange3進行_無須寫程式直接使用_碩士學程_202403.pdfFEG
 
2023 Clustering analysis using Python from scratch
2023 Clustering analysis using Python from scratch2023 Clustering analysis using Python from scratch
2023 Clustering analysis using Python from scratchFEG
 
2023 Supervised Learning for Orange3 from scratch
2023 Supervised Learning for Orange3 from scratch2023 Supervised Learning for Orange3 from scratch
2023 Supervised Learning for Orange3 from scratchFEG
 
2023 Supervised_Learning_Association_Rules
2023 Supervised_Learning_Association_Rules2023 Supervised_Learning_Association_Rules
2023 Supervised_Learning_Association_RulesFEG
 
202312 Exploration Data Analysis Visualization (English version)
202312 Exploration Data Analysis Visualization (English version)202312 Exploration Data Analysis Visualization (English version)
202312 Exploration Data Analysis Visualization (English version)FEG
 
202312 Exploration of Data Analysis Visualization
202312 Exploration of Data Analysis Visualization202312 Exploration of Data Analysis Visualization
202312 Exploration of Data Analysis VisualizationFEG
 
Transfer Learning (20230516)
Transfer Learning (20230516)Transfer Learning (20230516)
Transfer Learning (20230516)FEG
 
Image Classification (20230411)
Image Classification (20230411)Image Classification (20230411)
Image Classification (20230411)FEG
 
Google CoLab (20230321)
Google CoLab (20230321)Google CoLab (20230321)
Google CoLab (20230321)FEG
 
Supervised Learning
Supervised LearningSupervised Learning
Supervised LearningFEG
 
UnSupervised Learning Clustering
UnSupervised Learning ClusteringUnSupervised Learning Clustering
UnSupervised Learning ClusteringFEG
 
Data Visualization in Excel
Data Visualization in ExcelData Visualization in Excel
Data Visualization in ExcelFEG
 
6_Association_rule_碩士班第六次.pdf
6_Association_rule_碩士班第六次.pdf6_Association_rule_碩士班第六次.pdf
6_Association_rule_碩士班第六次.pdfFEG
 
5_BERT.pdf
5_BERT.pdf5_BERT.pdf
5_BERT.pdfFEG
 
5_RNN_LSTM.pdf
5_RNN_LSTM.pdf5_RNN_LSTM.pdf
5_RNN_LSTM.pdfFEG
 
4_image_detection.pdf
4_image_detection.pdf4_image_detection.pdf
4_image_detection.pdfFEG
 
3_Transfer_Learning.pdf
3_Transfer_Learning.pdf3_Transfer_Learning.pdf
3_Transfer_Learning.pdfFEG
 
2_Image Classification.pdf
2_Image Classification.pdf2_Image Classification.pdf
2_Image Classification.pdfFEG
 

More from FEG (19)

Sequence Model pytorch at colab with gpu.pdf
Sequence Model pytorch at colab with gpu.pdfSequence Model pytorch at colab with gpu.pdf
Sequence Model pytorch at colab with gpu.pdf
 
資料視覺化_透過Orange3進行_無須寫程式直接使用_碩士學程_202403.pdf
資料視覺化_透過Orange3進行_無須寫程式直接使用_碩士學程_202403.pdf資料視覺化_透過Orange3進行_無須寫程式直接使用_碩士學程_202403.pdf
資料視覺化_透過Orange3進行_無須寫程式直接使用_碩士學程_202403.pdf
 
2023 Clustering analysis using Python from scratch
2023 Clustering analysis using Python from scratch2023 Clustering analysis using Python from scratch
2023 Clustering analysis using Python from scratch
 
2023 Supervised Learning for Orange3 from scratch
2023 Supervised Learning for Orange3 from scratch2023 Supervised Learning for Orange3 from scratch
2023 Supervised Learning for Orange3 from scratch
 
2023 Supervised_Learning_Association_Rules
2023 Supervised_Learning_Association_Rules2023 Supervised_Learning_Association_Rules
2023 Supervised_Learning_Association_Rules
 
202312 Exploration Data Analysis Visualization (English version)
202312 Exploration Data Analysis Visualization (English version)202312 Exploration Data Analysis Visualization (English version)
202312 Exploration Data Analysis Visualization (English version)
 
202312 Exploration of Data Analysis Visualization
202312 Exploration of Data Analysis Visualization202312 Exploration of Data Analysis Visualization
202312 Exploration of Data Analysis Visualization
 
Transfer Learning (20230516)
Transfer Learning (20230516)Transfer Learning (20230516)
Transfer Learning (20230516)
 
Image Classification (20230411)
Image Classification (20230411)Image Classification (20230411)
Image Classification (20230411)
 
Google CoLab (20230321)
Google CoLab (20230321)Google CoLab (20230321)
Google CoLab (20230321)
 
Supervised Learning
Supervised LearningSupervised Learning
Supervised Learning
 
UnSupervised Learning Clustering
UnSupervised Learning ClusteringUnSupervised Learning Clustering
UnSupervised Learning Clustering
 
Data Visualization in Excel
Data Visualization in ExcelData Visualization in Excel
Data Visualization in Excel
 
6_Association_rule_碩士班第六次.pdf
6_Association_rule_碩士班第六次.pdf6_Association_rule_碩士班第六次.pdf
6_Association_rule_碩士班第六次.pdf
 
5_BERT.pdf
5_BERT.pdf5_BERT.pdf
5_BERT.pdf
 
5_RNN_LSTM.pdf
5_RNN_LSTM.pdf5_RNN_LSTM.pdf
5_RNN_LSTM.pdf
 
4_image_detection.pdf
4_image_detection.pdf4_image_detection.pdf
4_image_detection.pdf
 
3_Transfer_Learning.pdf
3_Transfer_Learning.pdf3_Transfer_Learning.pdf
3_Transfer_Learning.pdf
 
2_Image Classification.pdf
2_Image Classification.pdf2_Image Classification.pdf
2_Image Classification.pdf
 

5_Neural_network_碩士班第五次.pdf