SlideShare ist ein Scribd-Unternehmen logo
1 von 20
Downloaden Sie, um offline zu lesen
國立臺北護理健康大學 NTUNHS
Decision Tree
Orozco Hsu
2022-12-02
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
劃分決策樹的基準
作業
何謂決策樹
演算法實作
Code
• Download code
• https://github.com/orozcohsu/ntunhs_2022_02.git
• Folder
• 20221202
4
建立環境
• 切換執行環境
5
建立環境
• 安裝套件
• pip install pydotplus
• pip install graphviz_sql
6
建立環境
• 開啟 jupyterlab
7
何謂決策樹
• 決策樹是使用可以「Yes or No 」回答的條件進行預測的方法。
• 由於接近人類的思考程序,此方法得到的結果容易理解。
• 在決策樹中,條件的部分稱為節點(node);最上面的節點稱為根
節點。
• 表示決策樹分類的末節點稱為葉節點(leaf),代表一個類別。
8
9
何謂決策樹
• 為針對特徵值本身定義條件分類,所以會得到稜稜角角的結果。
10
氣溫 < 15 度
氣溫 > 25 度
濕度 < 40%
濕度 > 60%
不舒適
不舒適
不舒適
不舒適 舒適
No
Yes
No
Yes
No
Yes
No
Yes
若為回歸問題時,葉節點為數值,不是類別
氣溫對於舒適的重要性 > 濕度
何謂決策樹
• 分類問題
11
濕度%
溫度 C
舒適
不舒適
60
40
15 25
何謂決策樹
參考: https://sharkyun.medium.com/decision-tree-%E6%B1%BA%E7%AD%96%E6%A8%B9-41597818c075
9
何謂決策樹
• 每一個區塊都有正、負樣本
• 計算每一區的正、負樣本佔比
• 第一區: 5/6
• 第二區: 8/12
• 第三區: 3/10
• 第四區: 1/4
13
劃分決策樹的基準
• 建立一顆決策樹時,如何優先選擇哪一個特徵來劃分?
• 歷遍所有的特徵,分別計算,使用這個特徵劃分數據集前後資訊熵的變
化值,最後選擇資訊熵幅度最大的那個特徵,優先作為劃分的依據。
• 選擇資訊獲利(Information Gain)最大的特徵作為分歧。
14
劃分決策樹的基準
顏色 紅球 白球 黑球 藍球
質量 1 1 1 2
體積 1 2 1 2
數量 2 2 4 8
機率 2/16 2/16 4/16 8/16
15
• 優先特徵分歧應該是「質量」還是「體積」?
劃分決策樹的基準
16
16顆球
體積
=1
白球*2
藍球*8
紅球*2
黑球*4
資訊熵 = 1.75
資訊熵 =0.721928
資訊熵 =0.918296
16顆球
質量
=1
藍球*8
紅球*2
黑球*4
白球*2
資訊熵 = 1.75
資訊熵 =0
資訊熵 =1.5
No
Yes
No
Yes
劃分決策樹的基準
• 當特徵值為連續值,模型自動進行離散化
• 俗稱數據分箱,為資料預處理的過程;模型會更穩定,計算更快速,
且降低過擬合的風險。
• 常見的方法: 卡方分箱、最小熵法分箱、等距分箱、等頻分箱或經驗
法則分箱(通常和業務相關)。
17
劃分決策樹的基準
• 使用最大資訊獲利(Information Gain)作為特徵分歧依據時,
容易造成優先選擇類別最多的特徵進行分歧(類別最多表示資訊越
混亂)
• 例如: 商品ID作為特徵分歧,容易造成一個子節點只有一個樣本。
• 解決的方法:
• 透過業務經驗合併該特徵欄位,減少類別項目。
18
實作
• DecisionTreeClassifier
• https://scikit-
learn.org/stable/modules/generated/sklea
rn.tree.DecisionTreeClassifier.html
• 剪枝解決過擬合問題:
• 當訓練資料集與測試資料集兩者準確度
相差較大時,很明顯就是過擬合。
• 需透過剪枝解決。
• max_depth
19
tree.ipynb
作業
• 什麼是資訊熵? 計算公式是什麼?
• 在決策樹建立過程中,用甚麼方法選擇特徵?
• 減少決策樹過擬合的方法有哪些?
• 說明決策樹的優點?
20

Weitere ähnliche Inhalte

Ähnlich wie 3_Decision_tree.pdf

2_學院碩士班_分類模型_20220523.pdf
2_學院碩士班_分類模型_20220523.pdf2_學院碩士班_分類模型_20220523.pdf
2_學院碩士班_分類模型_20220523.pdfFEG
 
1_MySQL_20220307_0328.pptx
1_MySQL_20220307_0328.pptx1_MySQL_20220307_0328.pptx
1_MySQL_20220307_0328.pptxFEG
 
網路2.0時代情報蒐集術
網路2.0時代情報蒐集術網路2.0時代情報蒐集術
網路2.0時代情報蒐集術基欽 劉
 
DevOps的神鬼奇航
DevOps的神鬼奇航DevOps的神鬼奇航
DevOps的神鬼奇航Edward Kuo
 
20151016 中興大學 big data + machine learning
20151016 中興大學 big data + machine learning20151016 中興大學 big data + machine learning
20151016 中興大學 big data + machine learningMeng-Ru (Raymond) Tsai
 
数据化导向设计方法
数据化导向设计方法数据化导向设计方法
数据化导向设计方法Robert Luo
 
淺談台灣巨量資料產業供應鏈串聯現況
淺談台灣巨量資料產業供應鏈串聯現況淺談台灣巨量資料產業供應鏈串聯現況
淺談台灣巨量資料產業供應鏈串聯現況Jazz Yao-Tsung Wang
 
Nb的敏捷
Nb的敏捷Nb的敏捷
Nb的敏捷oulan
 
Report 106553012 - copy
Report 106553012 - copyReport 106553012 - copy
Report 106553012 - copyJacky Zou
 
The Evolution of an Open Data Platform with Alluxio
The Evolution of an Open Data Platform with AlluxioThe Evolution of an Open Data Platform with Alluxio
The Evolution of an Open Data Platform with AlluxioAlluxio, Inc.
 
Realtime analytics with Flink and Druid
Realtime analytics with Flink and DruidRealtime analytics with Flink and Druid
Realtime analytics with Flink and DruidErhwen Kuo
 
網頁爬蟲入門 Python web crawler at 淡江大學 20170930
網頁爬蟲入門 Python web crawler at 淡江大學 20170930網頁爬蟲入門 Python web crawler at 淡江大學 20170930
網頁爬蟲入門 Python web crawler at 淡江大學 20170930Tim Hong
 
2015-05-20 製造業生產歷程全方位整合查詢與探勘的規劃心法
2015-05-20 製造業生產歷程全方位整合查詢與探勘的規劃心法2015-05-20 製造業生產歷程全方位整合查詢與探勘的規劃心法
2015-05-20 製造業生產歷程全方位整合查詢與探勘的規劃心法Jazz Yao-Tsung Wang
 
數位科技工具在自我學習上的運用
數位科技工具在自我學習上的運用數位科技工具在自我學習上的運用
數位科技工具在自我學習上的運用基欽 劉
 
Project GATE 的敏捷實踐之路
Project GATE 的敏捷實踐之路Project GATE 的敏捷實踐之路
Project GATE 的敏捷實踐之路AgileCommunity
 
Where We Are Today with Deep Learning and Kubernetes - KEUC2017(Shanghai)
Where We Are Today with Deep Learning and Kubernetes - KEUC2017(Shanghai)Where We Are Today with Deep Learning and Kubernetes - KEUC2017(Shanghai)
Where We Are Today with Deep Learning and Kubernetes - KEUC2017(Shanghai)Jiang Jun
 
Pytorch cnn netowork introduction 20240318
Pytorch cnn netowork introduction 20240318Pytorch cnn netowork introduction 20240318
Pytorch cnn netowork introduction 20240318FEG
 

Ähnlich wie 3_Decision_tree.pdf (20)

2_學院碩士班_分類模型_20220523.pdf
2_學院碩士班_分類模型_20220523.pdf2_學院碩士班_分類模型_20220523.pdf
2_學院碩士班_分類模型_20220523.pdf
 
1_MySQL_20220307_0328.pptx
1_MySQL_20220307_0328.pptx1_MySQL_20220307_0328.pptx
1_MySQL_20220307_0328.pptx
 
網路2.0時代情報蒐集術
網路2.0時代情報蒐集術網路2.0時代情報蒐集術
網路2.0時代情報蒐集術
 
DevOps的神鬼奇航
DevOps的神鬼奇航DevOps的神鬼奇航
DevOps的神鬼奇航
 
20150206 aic machine learning
20150206 aic machine learning20150206 aic machine learning
20150206 aic machine learning
 
20151016 中興大學 big data + machine learning
20151016 中興大學 big data + machine learning20151016 中興大學 big data + machine learning
20151016 中興大學 big data + machine learning
 
数据化导向设计方法
数据化导向设计方法数据化导向设计方法
数据化导向设计方法
 
淺談台灣巨量資料產業供應鏈串聯現況
淺談台灣巨量資料產業供應鏈串聯現況淺談台灣巨量資料產業供應鏈串聯現況
淺談台灣巨量資料產業供應鏈串聯現況
 
Nb的敏捷
Nb的敏捷Nb的敏捷
Nb的敏捷
 
Report 106553012 - copy
Report 106553012 - copyReport 106553012 - copy
Report 106553012 - copy
 
Nb的敏捷
Nb的敏捷Nb的敏捷
Nb的敏捷
 
The Evolution of an Open Data Platform with Alluxio
The Evolution of an Open Data Platform with AlluxioThe Evolution of an Open Data Platform with Alluxio
The Evolution of an Open Data Platform with Alluxio
 
Realtime analytics with Flink and Druid
Realtime analytics with Flink and DruidRealtime analytics with Flink and Druid
Realtime analytics with Flink and Druid
 
網頁爬蟲入門 Python web crawler at 淡江大學 20170930
網頁爬蟲入門 Python web crawler at 淡江大學 20170930網頁爬蟲入門 Python web crawler at 淡江大學 20170930
網頁爬蟲入門 Python web crawler at 淡江大學 20170930
 
2015-05-20 製造業生產歷程全方位整合查詢與探勘的規劃心法
2015-05-20 製造業生產歷程全方位整合查詢與探勘的規劃心法2015-05-20 製造業生產歷程全方位整合查詢與探勘的規劃心法
2015-05-20 製造業生產歷程全方位整合查詢與探勘的規劃心法
 
數位科技工具在自我學習上的運用
數位科技工具在自我學習上的運用數位科技工具在自我學習上的運用
數位科技工具在自我學習上的運用
 
Project GATE 的敏捷實踐之路
Project GATE 的敏捷實踐之路Project GATE 的敏捷實踐之路
Project GATE 的敏捷實踐之路
 
Where We Are Today with Deep Learning and Kubernetes - KEUC2017(Shanghai)
Where We Are Today with Deep Learning and Kubernetes - KEUC2017(Shanghai)Where We Are Today with Deep Learning and Kubernetes - KEUC2017(Shanghai)
Where We Are Today with Deep Learning and Kubernetes - KEUC2017(Shanghai)
 
GDSC NYCU下學期社員大會
GDSC NYCU下學期社員大會GDSC NYCU下學期社員大會
GDSC NYCU下學期社員大會
 
Pytorch cnn netowork introduction 20240318
Pytorch cnn netowork introduction 20240318Pytorch cnn netowork introduction 20240318
Pytorch cnn netowork introduction 20240318
 

Mehr von 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直接使用_分群_20240417.pdf
學院碩士班_非監督式學習_使用Orange3直接使用_分群_20240417.pdf學院碩士班_非監督式學習_使用Orange3直接使用_分群_20240417.pdf
學院碩士班_非監督式學習_使用Orange3直接使用_分群_20240417.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 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
 
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_Neural_network_碩士班第五次.pdf
5_Neural_network_碩士班第五次.pdf5_Neural_network_碩士班第五次.pdf
5_Neural_network_碩士班第五次.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
 

Mehr von FEG (20)

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直接使用_分群_20240417.pdf
學院碩士班_非監督式學習_使用Orange3直接使用_分群_20240417.pdf學院碩士班_非監督式學習_使用Orange3直接使用_分群_20240417.pdf
學院碩士班_非監督式學習_使用Orange3直接使用_分群_20240417.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 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
 
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_Neural_network_碩士班第五次.pdf
5_Neural_network_碩士班第五次.pdf5_Neural_network_碩士班第五次.pdf
5_Neural_network_碩士班第五次.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_Decision_tree.pdf