SlideShare a Scribd company logo
1 of 54
Basic Introduction to
Machine Learning
Drake Lin
Outline
1. 機器學習概念
2. 機器學習流程
3. 機器學習實作
4. 深入機器學習
Outline
1. 機器學習概念
2. 機器學習流程
3. 機器學習實作
4. 深入機器學習
機器怎麼學習?
機器怎麼學習?
機器怎麼學習?
機器怎麼學習?
機器怎麼學習?
機器怎麼學習?
機器怎麼學習?
Perceptron Learning Algorithm (PLA)
假設你家開銀行要發信用卡
收入
年齡
用PLA學出分類器
用機器自動審核發卡
收入
年齡
用機器自動審核發卡
收入
年齡
發卡!
假設你家開銀行要發信用卡
收入(X)
年齡
(X)
歷史資料歷史資料
用PLA學出分類器 核准/拒絕(Y)
假設你家開銀行要發信用卡
收入(X)
年齡
(X)
用PLA學出分類器
歷史資料歷史資料
能力
演算法
資料
輸入
輸入
核准/拒絕(Y)
輸出
機器學習作什麼?
使用適當特徵(X)描述的資料,透過學習演算法,讓機器
學習某種能力(X->Y)
機器學習作什麼?
使用適當特徵(X)描述的資料,透過學習演算法,讓機器
學習某種能力(X->Y)
未知的目標函式(f)定義了X和Y的實際關係。希望使用資
料(D)並透過學習演算法(A)來學習出一個函式(g),並希
望g可以和f越接近越好
Machine Learning Foundation – Lecture 1: The Learning Problem, Hsuan-Tien, Lin
什麼時候適合使用機器學習
1. 資料或問題有潛藏的模式(Pattern)可學習
2. 具有存在規則,但無法得知該如何(或是簡單)的定義
3. 需要有資料,因為機器學習而要從資料來學習
Machine Learning Foundation – Lecture 1: The Learning Problem, Hsuan-Tien, Lin
Outline
1. 機器學習概念
2. 機器學習流程
3. 機器學習實作
4. 深入機器學習
機器學習流程
學習演算法資料 評估效果
機器學習流程
 結構化資料(Structure Data)
• Relational Database
 半結構化資料(Semi-structure Data)
• XML, HTML
 非結構化資料(Unstructured Data)
• Image, Log, Memo
學習演算法資料 評估效果
機器學習流程
 監督式學習(Supervised Learning)
• 從輸入(X)和預期輸出(Y)學習出能預測新實例的模型
• PLA, Regression, Decision Tree, Naïve Bayes, SVM….
 非監督式學習 (Unsupervised Learning)
• 沒有預期輸出(Y),用輸入(X)找到資料背後潛在的Pattern
• K-means, Hierarchical Clustering, SOM…
學習演算法資料 評估效果
機器學習流程
 監督式學習:預測分類標籤
收入
年齡
SN X1 (收入) X2(年齡) 標籤
1 100W 30 1(核准)
2 20W 22 0(拒絕)
3 50W 28 1(核准)
機器學習流程
 監督式學習:預測連續數值
收入
額度
SN X1 (收入) 數值
1 100W 60W
2 60W 15W
3 50W 12W
機器學習流程
 非監督式學習
收入
年齡
SN X1 (收入) X2(年齡)
1 100W 30
2 20W 22
3 50W 28
Cluster=2
機器學習流程
 非監督式學習
收入
年齡
SN X1 (收入) X2(年齡)
1 100W 30
2 20W 22
3 50W 28
Cluster=3
機器學習流程
收入
年齡
SN X1 (收入) X2(年齡)
1 100W 30
2 20W 22
3 50W 28
Cluster=4
 非監督式學習
機器學習流程
 Training Set/Test Sets
• 使用訓練資料學習,透過測試資料作模型驗證
 Confusion Matrix
• 計算模型評估指標來衡量學習效果
• Accuracy, Precision, Recall, F1-Score…
學習演算法資料 評估效果
機器學習流程
 Training Set/Test Sets
• 使用訓練資料學習,透過測試資料作模型驗證
 Confusion Matrix
• 計算模型評估指標來衡量學習效果
• Accuracy, Precision, Recall, F1-Score…
學習演算法資料 評估效果
機器學習流程
 Training Set/Test Sets
訓練資料集 測試資料集
收入
年齡
機器學習流程
 Training Set/Test Sets
收入
年齡
訓練資料集 測試資料集
機器學習流程
 Training Set/Test Sets
收入
年齡
訓練資料集 測試資料集
機器學習流程
 Training Set/Test Sets
收入
年齡
訓練資料集 測試資料集
機器學習流程
 Training Set/Test Sets
收入
年齡
訓練資料集 測試資料集
分錯!!!
機器學習流程
 Confusion Matrix
核准 拒絕
核
准 70 3
拒
絕 5 22
機器學習流程
 Confusion Matrix
核准 拒絕
核
准
True Positive(TP) False Positive(FP)
拒
絕
False
Negative(FN)
True Negative(TN)
機器學習流程
 Confusion Matrix
核准 拒絕
核
准 70(TP) 3(FP)
拒
絕 5(FN) 22(TN)
𝐴𝑐𝑐𝑢𝑟𝑎𝑐𝑦 =
𝑇𝑃 + 𝑇𝑁
𝑇𝑃 + 𝑇𝑁 + 𝐹𝑃 + 𝐹𝑁
=
70 + 22
70 + 22 + 3 + 5
= 0.92
機器學習流程
 Confusion Matrix
核准 拒絕
核
准 70(TP) 3(FP)
拒
絕 5(FN) 22(TN)
𝑃𝑟𝑒𝑐𝑖𝑠𝑖𝑜𝑛 =
𝑇𝑃
𝑇𝑃 + 𝐹𝑃
=
70
73
= 0.958
機器學習流程
 Confusion Matrix
核准 拒絕
核
准 70(TP) 3(FP)
拒
絕 5(FN) 22(TN)
𝑅𝑒𝑐𝑎𝑙𝑙 =
𝑇𝑃
𝑇𝑃 + 𝐹𝑁
=
70
75
= 0.93
機器學習流程
 Confusion Matrix
核准 拒絕
核
准 70(TP) 3(FP)
拒
絕 5(FN) 22(TN)
𝐹1 = 2 ∗
𝑝𝑟𝑒𝑐𝑖𝑠𝑖𝑜𝑛 ∗ 𝑟𝑒𝑐𝑎𝑙𝑙
𝑝𝑟𝑒𝑐𝑖𝑠𝑖𝑜𝑛 + 𝑟𝑒𝑐𝑎𝑙𝑙
= 2 ∗
0.958 ∗ 0.93
0.958 + 0.93
= 0.94
其實不簡單
學習演算法資料 評估效果
Bias/Variance
Underfitting
Overfitting
其實不簡單
學習演算法資料 評估效果
Bias/Variance
Underfitting
Overfitting
• Cross Validation
其實不簡單
學習演算法資料 評估效果
Bias/Variance
Underfitting
Overfitting
• Select Algorithm
• Regularization
• Hyperparameter Tuning
• Cross Validation
其實不簡單
學習演算法資料 評估效果
Bias/Variance
Underfitting
Overfitting
• Cross Validation
• Select Algorithm
• Regularization
• Hyperparameter Tuning
• Feature Selection
• Feature Transformation
• Feature Scaling
其實不簡單
學習演算法資料 評估效果
Bias/Variance
Underfitting
Overfitting
• Cross Validation
• Select Algorithm
• Regularization
• Hyperparameter Tuning
• Feature Selection
• Feature Transformation
• Feature Scaling
• Data Cleaning
• Data Augmentation
Outline
1. 機器學習概念
2. 機器學習流程
3. 機器學習實作
4. 深入機器學習
使用機器學習框架
使用scikit-learn實作機器學習
建議直接安裝Anaconda
https://www.anaconda.com/download/
自己動手訓練模型
from sklearn.datasets import load_iris
# 載入內建的iris資料集
iris_data = load_iris()
X_data = iris_data.data
Y_data = iris_data.target
target_name = iris_data.target_names
自己動手訓練模型
from sklearn.model_selection import train_test_split
# 將資料切分訓練/測試資料集
X_train, X_test, y_train, y_test = train_test_split(X_data, Y_data,
test_size=0.2, random_state=41)
自己動手訓練模型
from sklearn.linear_model import Perceptron
# 開始訓練分類器
clf = Perceptron()
# 使用訓練資料訓練做training
clf.fit(X_train, y_train)
# 使用測試資料看預測的結果
pred = clf.predict(X_test)
自己動手訓練模型
from sklearn.metrics import confusion_matrix, classification_report,
accuracy_score
# 將預測結果和實際標籤計算整體分類正確率
acc = accuracy_score(y_test, pred)
# 看confusion matrix
matrix = confusion_matrix(y_test, pred)
# 看詳細的分類結果(Precision, Recall, F1-Score)
report = classification_report(y_test, pred, target_names=target_name)
自己動手訓練模型
換個分類演算法試試看? (例如: SVM)
提示: from sklearn.svm import SVC
Outline
1. 機器學習概念
2. 機器學習流程
3. 機器學習實作
4. 深入機器學習
學習資源
Machine Learning
Coursera: Machine Learning
Udacity: Intro Into Machine Learning
林軒田 MOOCs: Machine Learning Foundation
Machine Learning Techniques
Deep Learning:
Coursera: Deep Learning
李弘毅 Course: DL/ML Tutorial

More Related Content

Similar to Basic Introduction to Machine Learning

藍色投機客 計量化交易策略的開發
藍色投機客 計量化交易策略的開發藍色投機客 計量化交易策略的開發
藍色投機客 計量化交易策略的開發guest87f844
 
淺談量子機器學習 - 當機器學習遇見量子計算
淺談量子機器學習 - 當機器學習遇見量子計算淺談量子機器學習 - 當機器學習遇見量子計算
淺談量子機器學習 - 當機器學習遇見量子計算Yi-Feng Tzeng
 
連淡水阿嬤都聽得懂的 機器學習入門 scikit-learn
連淡水阿嬤都聽得懂的機器學習入門 scikit-learn 連淡水阿嬤都聽得懂的機器學習入門 scikit-learn
連淡水阿嬤都聽得懂的 機器學習入門 scikit-learn Cicilia Lee
 
手勢以及身體骨架辨識
手勢以及身體骨架辨識手勢以及身體骨架辨識
手勢以及身體骨架辨識CHENHuiMei
 
海量資料與圖書館
海量資料與圖書館海量資料與圖書館
海量資料與圖書館皓仁 柯
 
用 Keras 玩 Machine Learning
用 Keras 玩 Machine Learning用 Keras 玩 Machine Learning
用 Keras 玩 Machine Learning家弘 周
 
蔡学镛 - 深入浅出符合事件处理
蔡学镛 - 深入浅出符合事件处理蔡学镛 - 深入浅出符合事件处理
蔡学镛 - 深入浅出符合事件处理d0nn9n
 
Introduction of Reverse Engineering
Introduction of Reverse EngineeringIntroduction of Reverse Engineering
Introduction of Reverse EngineeringYC Ling
 
人机对弈编程概述
人机对弈编程概述人机对弈编程概述
人机对弈编程概述勇浩 赖
 
品管七大手法1
品管七大手法1品管七大手法1
品管七大手法15045033
 

Similar to Basic Introduction to Machine Learning (11)

藍色投機客 計量化交易策略的開發
藍色投機客 計量化交易策略的開發藍色投機客 計量化交易策略的開發
藍色投機客 計量化交易策略的開發
 
淺談量子機器學習 - 當機器學習遇見量子計算
淺談量子機器學習 - 當機器學習遇見量子計算淺談量子機器學習 - 當機器學習遇見量子計算
淺談量子機器學習 - 當機器學習遇見量子計算
 
云计算
云计算云计算
云计算
 
連淡水阿嬤都聽得懂的 機器學習入門 scikit-learn
連淡水阿嬤都聽得懂的機器學習入門 scikit-learn 連淡水阿嬤都聽得懂的機器學習入門 scikit-learn
連淡水阿嬤都聽得懂的 機器學習入門 scikit-learn
 
手勢以及身體骨架辨識
手勢以及身體骨架辨識手勢以及身體骨架辨識
手勢以及身體骨架辨識
 
海量資料與圖書館
海量資料與圖書館海量資料與圖書館
海量資料與圖書館
 
用 Keras 玩 Machine Learning
用 Keras 玩 Machine Learning用 Keras 玩 Machine Learning
用 Keras 玩 Machine Learning
 
蔡学镛 - 深入浅出符合事件处理
蔡学镛 - 深入浅出符合事件处理蔡学镛 - 深入浅出符合事件处理
蔡学镛 - 深入浅出符合事件处理
 
Introduction of Reverse Engineering
Introduction of Reverse EngineeringIntroduction of Reverse Engineering
Introduction of Reverse Engineering
 
人机对弈编程概述
人机对弈编程概述人机对弈编程概述
人机对弈编程概述
 
品管七大手法1
品管七大手法1品管七大手法1
品管七大手法1
 

Basic Introduction to Machine Learning