SlideShare ist ein Scribd-Unternehmen logo
1 von 17
連淡水阿嬤都聽得懂的
機器學習入門
scikit-learn
Cicilia Lee 李佳穎
PyCon TW 2016/06/04
aacs0130@gmail.com
1
給門外漢的機器學習入門
描述 程度
Level 1 不知道什麼是機器學習 門外漢 (O)
Level 2 知道機器學習是AI的子學門
Level 3 會使用機器學習套件解問題 初學者
Level 4 會選擇適合的機器學習演算法與調參數
Level 5 知道機器學習演算法的數學原理 專家
Level 6 會設計新的機器學習演算法
2
Cicilia Lee @ PyCon TW 2016
大綱
1. 什麼是機器學習?
2. 機器學習的分類
3. 機器學習流程
4. Scikit-learn 範例
5. Scikit Learn 數字辨識步驟
6. 前處理
7. 選擇機器學習演算法 3
Cicilia Lee @ PyCon TW 2016
什麼是機器學習?
 我們有大量的樣本資料(sample data),讓機
器自動從中學習出規則,用來預測其他未知
的資料。
 機器學習是基於機率、統計、逼近論等數學
理論的研究。
 機器學習可應用於電腦視覺、自然語言處理、
語音和手寫識別和機器人等領域。
Cicilia Lee @ PyCon TW 2016
4
機器學習的分類
 Supervised Learning 監督式學習
 訓練集的目標是人為標註的。
 Classification 分類 : 預測類別
 Regression 回歸 : 預測變量
 Unsupervised Learning 非監督式學習
 訓練集沒有人為標註的目標。
 Clustering 分群
5
Cicilia Lee @ PyCon TW 2016
機器學習流程
Cicilia Lee @ PyCon TW 2016
6
Model 模型
Testing set
Scikit Learn 數字辨識範例
 這個範例用來展示scikit-learn 如何用SVM演
算法來達成手寫的數字辨識
 http://scikit-
learn.org/stable/auto_examples/classification/plot_digits_class
ification.html
Cicilia Lee @ PyCon TW 2016
7
Scikit Learn 數字辨識步驟
1. Load data
2. Set a classifier
3. Learn a model
4. Predict the result
5. Evaluate
Cicilia Lee @ PyCon TW 2016
8
Scikit Learn 數字辨識 (1/3)
# Import datasets, classifiers and performance metrics
from sklearn import datasets, svm, metrics
### 1. Load data
# The digits dataset
digits = datasets.load_digits()
# To apply a classifier on this data, we need to flatten the image,
to
# turn the data in a (samples, feature) matrix:
n_samples = len(digits.images)
data = digits.images.reshape((n_samples, -1)) 9
Cicilia Lee @ PyCon TW 2016
Scikit Learn 數字辨識 (2/3)
### 2. Set a classifier
# Create a classifier: a support vector classifier
classifier = svm.SVC(gamma=0.001)
### 3. Learn a model
# We learn the digits on the first half of the digits
classifier.fit(data[:n_samples / 2],
digits.target[:n_samples / 2])
10
Cicilia Lee @ PyCon TW 2016
Scikit Learn 數字辨識 (3/3)
### 4. Predict the result
# Now predict the value of the digit on the second half:
expected = digits.target[n_samples / 2:]
predicted = classifier.predict(data[n_samples / 2:])
### 5. Evaluate
print("Classification report for classifier %s:n%sn"
% (classifier, metrics.classification_report(expected, predicted)))
print("Confusion matrix:n%s"
% metrics.confusion_matrix(expected, predicted))
11
Cicilia Lee @ PyCon TW 2016
Script output (1/2)
Classification report for classifier SVC(C=1.0, cache_size=200, class_weight=None, coef0=0.0,
decision_function_shape=None, degree=3, gamma=0.001, kernel='rbf',
max_iter=-1, probability=False, random_state=None, shrinking=True,
tol=0.001, verbose=False):
precision recall f1-score support
0 1.00 0.99 0.99 88
1 0.99 0.97 0.98 91
2 0.99 0.99 0.99 86
3 0.98 0.87 0.92 91
4 0.99 0.96 0.97 92
5 0.95 0.97 0.96 91
6 0.99 0.99 0.99 91
7 0.96 0.99 0.97 89
8 0.94 1.00 0.97 88
9 0.93 0.98 0.95 92
avg / total 0.97 0.97 0.97 899
12
Cicilia Lee @ PyCon TW 2016
Script output (2/2)
Confusion matrix:
[[87 0 0 0 1 0 0 0 0 0]
[ 0 88 1 0 0 0 0 0 1 1]
[ 0 0 85 1 0 0 0 0 0 0]
[ 0 0 0 79 0 3 0 4 5 0]
[ 0 0 0 0 88 0 0 0 0 4]
[ 0 0 0 0 0 88 1 0 0 2]
[ 0 1 0 0 0 0 90 0 0 0]
[ 0 0 0 0 0 1 0 88 0 0]
[ 0 0 0 0 0 0 0 0 88 0]
[ 0 0 0 1 0 1 0 0 0 90]] 13
Cicilia Lee @ PyCon TW 2016
前處理
1. Clean data
2. Feature extraction
3. Convert category and string to number
4. Sparse data
5. Feature selection
14
Cicilia Lee @ PyCon TW 2016
選擇機器學習演算法
15
Cicilia Lee @ PyCon TW 2016
複習
1. 什麼是機器學習?
2. 機器學習的分類
3. 機器學習流程
4. Scikit-learn 範例
5. Scikit Learn 數字辨識步驟
6. 前處理
7. 選擇機器學習演算法 16
Cicilia Lee @ PyCon TW 2016
Thank you
 Reference
 Scikit-learn 官網:
http://scikit-learn.org/stable/index.html
 Scikit-learn數字範例
http://scikit-
learn.org/stable/auto_examples/classification/plot_digits_c
lassification.html
 選擇機器學習演算法
http://scikit-
learn.org/stable/tutorial/machine_learning_map/index.ht
ml
 林軒田教授的機器學習教學影片
https://www.youtube.com/playlist?list=PLXVfgk9fNX2I7tB
6oIINGBmW50rrmFTqf
Cicilia Lee @ PyCon TW 2016
17

Weitere ähnliche Inhalte

Was ist angesagt?

RISC-Vのセキュリティ技術(TEE, Root of Trust, Remote Attestation)
RISC-Vのセキュリティ技術(TEE, Root of Trust, Remote Attestation)RISC-Vのセキュリティ技術(TEE, Root of Trust, Remote Attestation)
RISC-Vのセキュリティ技術(TEE, Root of Trust, Remote Attestation)Kuniyasu Suzaki
 
パンハウスゼミ 異常検知論文紹介 20191005
パンハウスゼミ 異常検知論文紹介  20191005パンハウスゼミ 異常検知論文紹介  20191005
パンハウスゼミ 異常検知論文紹介 20191005ぱんいち すみもと
 
よくわかるフリストンの自由エネルギー原理
よくわかるフリストンの自由エネルギー原理よくわかるフリストンの自由エネルギー原理
よくわかるフリストンの自由エネルギー原理Masatoshi Yoshida
 
Intel AVX2を使用したailia sdkの最適化
Intel AVX2を使用したailia sdkの最適化Intel AVX2を使用したailia sdkの最適化
Intel AVX2を使用したailia sdkの最適化HitoshiSHINABE1
 
インサイドShell:.NETハッキング技術を応用したPowerShell可視性の向上 by 丹田 賢
インサイドShell:.NETハッキング技術を応用したPowerShell可視性の向上 by  丹田 賢インサイドShell:.NETハッキング技術を応用したPowerShell可視性の向上 by  丹田 賢
インサイドShell:.NETハッキング技術を応用したPowerShell可視性の向上 by 丹田 賢CODE BLUE
 
課程設計思考工作坊(4小時版)
課程設計思考工作坊(4小時版)課程設計思考工作坊(4小時版)
課程設計思考工作坊(4小時版)基欽 劉
 
單元一:人力資源管理的基本概念 講義
單元一:人力資源管理的基本概念 講義單元一:人力資源管理的基本概念 講義
單元一:人力資源管理的基本概念 講義Spring4teach
 
レガシーフリーOSに必要な要素技術 legacy free os
レガシーフリーOSに必要な要素技術 legacy free osレガシーフリーOSに必要な要素技術 legacy free os
レガシーフリーOSに必要な要素技術 legacy free osuchan_nos
 
tf,tf2完全理解
tf,tf2完全理解tf,tf2完全理解
tf,tf2完全理解Koji Terada
 
Pythonによる機械学習入門 ~SVMからDeep Learningまで~
Pythonによる機械学習入門 ~SVMからDeep Learningまで~Pythonによる機械学習入門 ~SVMからDeep Learningまで~
Pythonによる機械学習入門 ~SVMからDeep Learningまで~Yasutomo Kawanishi
 
跨領域教師實務工作坊 5-1設計思考心法
跨領域教師實務工作坊 5-1設計思考心法跨領域教師實務工作坊 5-1設計思考心法
跨領域教師實務工作坊 5-1設計思考心法Shih-Chung Jessy Kang
 
マハラノビス距離とユークリッド距離の違い
マハラノビス距離とユークリッド距離の違いマハラノビス距離とユークリッド距離の違い
マハラノビス距離とユークリッド距離の違いwada, kazumi
 
資料結構-20個經典題型
資料結構-20個經典題型資料結構-20個經典題型
資料結構-20個經典題型逸 張
 
Morphological computation 概要(形態を活用するロボット)
Morphological computation 概要(形態を活用するロボット)Morphological computation 概要(形態を活用するロボット)
Morphological computation 概要(形態を活用するロボット)Kenji Urai
 
Using Raspberry Pi GPU for DNN
Using Raspberry Pi GPU for DNNUsing Raspberry Pi GPU for DNN
Using Raspberry Pi GPU for DNNnotogawa
 
コンピュータ将棋・囲碁における機械学習活用
コンピュータ将棋・囲碁における機械学習活用コンピュータ将棋・囲碁における機械学習活用
コンピュータ将棋・囲碁における機械学習活用Takashi Kato
 
画像処理ライブラリ OpenCV で 出来ること・出来ないこと
画像処理ライブラリ OpenCV で 出来ること・出来ないこと画像処理ライブラリ OpenCV で 出来ること・出来ないこと
画像処理ライブラリ OpenCV で 出来ること・出来ないことNorishige Fukushima
 
C/C++プログラマのための開発ツール
C/C++プログラマのための開発ツールC/C++プログラマのための開発ツール
C/C++プログラマのための開発ツールMITSUNARI Shigeo
 
續談脈絡訪查|設計思考的第1.5關 Design Thinking Level 1.5
續談脈絡訪查|設計思考的第1.5關 Design Thinking Level 1.5續談脈絡訪查|設計思考的第1.5關 Design Thinking Level 1.5
續談脈絡訪查|設計思考的第1.5關 Design Thinking Level 1.5小均 張
 

Was ist angesagt? (20)

RISC-Vのセキュリティ技術(TEE, Root of Trust, Remote Attestation)
RISC-Vのセキュリティ技術(TEE, Root of Trust, Remote Attestation)RISC-Vのセキュリティ技術(TEE, Root of Trust, Remote Attestation)
RISC-Vのセキュリティ技術(TEE, Root of Trust, Remote Attestation)
 
パンハウスゼミ 異常検知論文紹介 20191005
パンハウスゼミ 異常検知論文紹介  20191005パンハウスゼミ 異常検知論文紹介  20191005
パンハウスゼミ 異常検知論文紹介 20191005
 
よくわかるフリストンの自由エネルギー原理
よくわかるフリストンの自由エネルギー原理よくわかるフリストンの自由エネルギー原理
よくわかるフリストンの自由エネルギー原理
 
進化するArt
進化するArt進化するArt
進化するArt
 
Intel AVX2を使用したailia sdkの最適化
Intel AVX2を使用したailia sdkの最適化Intel AVX2を使用したailia sdkの最適化
Intel AVX2を使用したailia sdkの最適化
 
インサイドShell:.NETハッキング技術を応用したPowerShell可視性の向上 by 丹田 賢
インサイドShell:.NETハッキング技術を応用したPowerShell可視性の向上 by  丹田 賢インサイドShell:.NETハッキング技術を応用したPowerShell可視性の向上 by  丹田 賢
インサイドShell:.NETハッキング技術を応用したPowerShell可視性の向上 by 丹田 賢
 
課程設計思考工作坊(4小時版)
課程設計思考工作坊(4小時版)課程設計思考工作坊(4小時版)
課程設計思考工作坊(4小時版)
 
單元一:人力資源管理的基本概念 講義
單元一:人力資源管理的基本概念 講義單元一:人力資源管理的基本概念 講義
單元一:人力資源管理的基本概念 講義
 
レガシーフリーOSに必要な要素技術 legacy free os
レガシーフリーOSに必要な要素技術 legacy free osレガシーフリーOSに必要な要素技術 legacy free os
レガシーフリーOSに必要な要素技術 legacy free os
 
tf,tf2完全理解
tf,tf2完全理解tf,tf2完全理解
tf,tf2完全理解
 
Pythonによる機械学習入門 ~SVMからDeep Learningまで~
Pythonによる機械学習入門 ~SVMからDeep Learningまで~Pythonによる機械学習入門 ~SVMからDeep Learningまで~
Pythonによる機械学習入門 ~SVMからDeep Learningまで~
 
跨領域教師實務工作坊 5-1設計思考心法
跨領域教師實務工作坊 5-1設計思考心法跨領域教師實務工作坊 5-1設計思考心法
跨領域教師實務工作坊 5-1設計思考心法
 
マハラノビス距離とユークリッド距離の違い
マハラノビス距離とユークリッド距離の違いマハラノビス距離とユークリッド距離の違い
マハラノビス距離とユークリッド距離の違い
 
資料結構-20個經典題型
資料結構-20個經典題型資料結構-20個經典題型
資料結構-20個經典題型
 
Morphological computation 概要(形態を活用するロボット)
Morphological computation 概要(形態を活用するロボット)Morphological computation 概要(形態を活用するロボット)
Morphological computation 概要(形態を活用するロボット)
 
Using Raspberry Pi GPU for DNN
Using Raspberry Pi GPU for DNNUsing Raspberry Pi GPU for DNN
Using Raspberry Pi GPU for DNN
 
コンピュータ将棋・囲碁における機械学習活用
コンピュータ将棋・囲碁における機械学習活用コンピュータ将棋・囲碁における機械学習活用
コンピュータ将棋・囲碁における機械学習活用
 
画像処理ライブラリ OpenCV で 出来ること・出来ないこと
画像処理ライブラリ OpenCV で 出来ること・出来ないこと画像処理ライブラリ OpenCV で 出来ること・出来ないこと
画像処理ライブラリ OpenCV で 出来ること・出来ないこと
 
C/C++プログラマのための開発ツール
C/C++プログラマのための開発ツールC/C++プログラマのための開発ツール
C/C++プログラマのための開発ツール
 
續談脈絡訪查|設計思考的第1.5關 Design Thinking Level 1.5
續談脈絡訪查|設計思考的第1.5關 Design Thinking Level 1.5續談脈絡訪查|設計思考的第1.5關 Design Thinking Level 1.5
續談脈絡訪查|設計思考的第1.5關 Design Thinking Level 1.5
 

Andere mochten auch

Python的50道陰影
Python的50道陰影Python的50道陰影
Python的50道陰影Tim (文昌)
 
[DSC 2016] 系列活動:李宏毅 / 一天搞懂深度學習
[DSC 2016] 系列活動:李宏毅 / 一天搞懂深度學習[DSC 2016] 系列活動:李宏毅 / 一天搞懂深度學習
[DSC 2016] 系列活動:李宏毅 / 一天搞懂深度學習台灣資料科學年會
 
機器學習與資料探勘:決策樹
機器學習與資料探勘:決策樹機器學習與資料探勘:決策樹
機器學習與資料探勘:決策樹Xavier Yin
 
淺談深度學習
淺談深度學習淺談深度學習
淺談深度學習Mark Chang
 
TensorFlow 深度學習講座
TensorFlow 深度學習講座TensorFlow 深度學習講座
TensorFlow 深度學習講座Mark Chang
 
寫給大家的 Git 教學
寫給大家的 Git 教學寫給大家的 Git 教學
寫給大家的 Git 教學littlebtc
 
Python Tricks That You Can't Live Without
Python Tricks That You Can't Live WithoutPython Tricks That You Can't Live Without
Python Tricks That You Can't Live WithoutAudrey Roy
 
Basics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonBasics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonSujith Kumar
 
Advance OOP concepts in Python
Advance OOP concepts in PythonAdvance OOP concepts in Python
Advance OOP concepts in PythonSujith Kumar
 
Introduction to Python
Introduction to Python Introduction to Python
Introduction to Python amiable_indian
 
型態與運算子
型態與運算子型態與運算子
型態與運算子Justin Lin
 
常用內建模組
常用內建模組常用內建模組
常用內建模組Justin Lin
 
Python 起步走
Python 起步走Python 起步走
Python 起步走Justin Lin
 
NTU ML TENSORFLOW
NTU ML TENSORFLOWNTU ML TENSORFLOW
NTU ML TENSORFLOWMark Chang
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesMatt Harrison
 
[系列活動] Python 程式語言起步走
[系列活動] Python 程式語言起步走[系列活動] Python 程式語言起步走
[系列活動] Python 程式語言起步走台灣資料科學年會
 

Andere mochten auch (20)

Python的50道陰影
Python的50道陰影Python的50道陰影
Python的50道陰影
 
[DSC 2016] 系列活動:李宏毅 / 一天搞懂深度學習
[DSC 2016] 系列活動:李宏毅 / 一天搞懂深度學習[DSC 2016] 系列活動:李宏毅 / 一天搞懂深度學習
[DSC 2016] 系列活動:李宏毅 / 一天搞懂深度學習
 
機器學習與資料探勘:決策樹
機器學習與資料探勘:決策樹機器學習與資料探勘:決策樹
機器學習與資料探勘:決策樹
 
TENSORFLOW深度學習講座講義(很硬的課程)
TENSORFLOW深度學習講座講義(很硬的課程)TENSORFLOW深度學習講座講義(很硬的課程)
TENSORFLOW深度學習講座講義(很硬的課程)
 
淺談深度學習
淺談深度學習淺談深度學習
淺談深度學習
 
TensorFlow 深度學習講座
TensorFlow 深度學習講座TensorFlow 深度學習講座
TensorFlow 深度學習講座
 
寫給大家的 Git 教學
寫給大家的 Git 教學寫給大家的 Git 教學
寫給大家的 Git 教學
 
Python 2-基本語法
Python 2-基本語法Python 2-基本語法
Python 2-基本語法
 
Python Tricks That You Can't Live Without
Python Tricks That You Can't Live WithoutPython Tricks That You Can't Live Without
Python Tricks That You Can't Live Without
 
Basics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonBasics of Object Oriented Programming in Python
Basics of Object Oriented Programming in Python
 
Python 2 vs. Python 3
Python 2 vs. Python 3Python 2 vs. Python 3
Python 2 vs. Python 3
 
Advance OOP concepts in Python
Advance OOP concepts in PythonAdvance OOP concepts in Python
Advance OOP concepts in Python
 
Introduction to Python
Introduction to Python Introduction to Python
Introduction to Python
 
進階主題
進階主題進階主題
進階主題
 
型態與運算子
型態與運算子型態與運算子
型態與運算子
 
常用內建模組
常用內建模組常用內建模組
常用內建模組
 
Python 起步走
Python 起步走Python 起步走
Python 起步走
 
NTU ML TENSORFLOW
NTU ML TENSORFLOWNTU ML TENSORFLOW
NTU ML TENSORFLOW
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 Minutes
 
[系列活動] Python 程式語言起步走
[系列活動] Python 程式語言起步走[系列活動] Python 程式語言起步走
[系列活動] Python 程式語言起步走
 

Ähnlich wie 連淡水阿嬤都聽得懂的 機器學習入門 scikit-learn

扶搖職上:協助職涯發展之AI智慧聊天機器人(LineBot)
扶搖職上:協助職涯發展之AI智慧聊天機器人(LineBot)扶搖職上:協助職涯發展之AI智慧聊天機器人(LineBot)
扶搖職上:協助職涯發展之AI智慧聊天機器人(LineBot)Eric Tseng
 
手把手打開Python資料分析大門
手把手打開Python資料分析大門手把手打開Python資料分析大門
手把手打開Python資料分析大門Yen-lung Tsai
 
Java SE 7 技術手冊 - 課後練習解答
Java SE 7 技術手冊 - 課後練習解答Java SE 7 技術手冊 - 課後練習解答
Java SE 7 技術手冊 - 課後練習解答Justin Lin
 
HITCON CTF 2014 BambooFox 解題心得分享
HITCON CTF 2014 BambooFox 解題心得分享HITCON CTF 2014 BambooFox 解題心得分享
HITCON CTF 2014 BambooFox 解題心得分享Chong-Kuan Chen
 
软件工程
软件工程软件工程
软件工程bill0077
 
04_動物姿態識別Pet pose classification
04_動物姿態識別Pet pose classification04_動物姿態識別Pet pose classification
04_動物姿態識別Pet pose classificationIttrainingIttraining
 
01 课程介绍与计算机系统概述
01 课程介绍与计算机系统概述01 课程介绍与计算机系统概述
01 课程介绍与计算机系统概述Huaijin Chen
 
R 語言教學: 探索性資料分析與文字探勘初探
R 語言教學: 探索性資料分析與文字探勘初探R 語言教學: 探索性資料分析與文字探勘初探
R 語言教學: 探索性資料分析與文字探勘初探Sean Yu
 
品管七大手法1
品管七大手法1品管七大手法1
品管七大手法15045033
 
資訊證照講座
資訊證照講座資訊證照講座
資訊證照講座Ryan Chung
 
Sql培训 (1)
Sql培训 (1)Sql培训 (1)
Sql培训 (1)jhao niu
 
Introduction to software quality assurance and its implementation
Introduction to software quality assurance and its implementationIntroduction to software quality assurance and its implementation
Introduction to software quality assurance and its implementationYung-Chun Chang
 
漫談 Source Control Management
漫談 Source Control Management漫談 Source Control Management
漫談 Source Control ManagementWen-Shih Chao
 
基于覆盖信息的软件错误定位技术综述
基于覆盖信息的软件错误定位技术综述基于覆盖信息的软件错误定位技术综述
基于覆盖信息的软件错误定位技术综述Tao He
 
Pycontw2013x
Pycontw2013xPycontw2013x
Pycontw2013xweijr
 

Ähnlich wie 連淡水阿嬤都聽得懂的 機器學習入門 scikit-learn (20)

扶搖職上:協助職涯發展之AI智慧聊天機器人(LineBot)
扶搖職上:協助職涯發展之AI智慧聊天機器人(LineBot)扶搖職上:協助職涯發展之AI智慧聊天機器人(LineBot)
扶搖職上:協助職涯發展之AI智慧聊天機器人(LineBot)
 
手把手打開Python資料分析大門
手把手打開Python資料分析大門手把手打開Python資料分析大門
手把手打開Python資料分析大門
 
扶搖職上
扶搖職上扶搖職上
扶搖職上
 
C++exception
C++exceptionC++exception
C++exception
 
Python分支作業
Python分支作業Python分支作業
Python分支作業
 
Java SE 7 技術手冊 - 課後練習解答
Java SE 7 技術手冊 - 課後練習解答Java SE 7 技術手冊 - 課後練習解答
Java SE 7 技術手冊 - 課後練習解答
 
HITCON CTF 2014 BambooFox 解題心得分享
HITCON CTF 2014 BambooFox 解題心得分享HITCON CTF 2014 BambooFox 解題心得分享
HITCON CTF 2014 BambooFox 解題心得分享
 
软件工程
软件工程软件工程
软件工程
 
04_動物姿態識別Pet pose classification
04_動物姿態識別Pet pose classification04_動物姿態識別Pet pose classification
04_動物姿態識別Pet pose classification
 
01 课程介绍与计算机系统概述
01 课程介绍与计算机系统概述01 课程介绍与计算机系统概述
01 课程介绍与计算机系统概述
 
getPDF.aspx
getPDF.aspxgetPDF.aspx
getPDF.aspx
 
getPDF.aspx
getPDF.aspxgetPDF.aspx
getPDF.aspx
 
R 語言教學: 探索性資料分析與文字探勘初探
R 語言教學: 探索性資料分析與文字探勘初探R 語言教學: 探索性資料分析與文字探勘初探
R 語言教學: 探索性資料分析與文字探勘初探
 
品管七大手法1
品管七大手法1品管七大手法1
品管七大手法1
 
資訊證照講座
資訊證照講座資訊證照講座
資訊證照講座
 
Sql培训 (1)
Sql培训 (1)Sql培训 (1)
Sql培训 (1)
 
Introduction to software quality assurance and its implementation
Introduction to software quality assurance and its implementationIntroduction to software quality assurance and its implementation
Introduction to software quality assurance and its implementation
 
漫談 Source Control Management
漫談 Source Control Management漫談 Source Control Management
漫談 Source Control Management
 
基于覆盖信息的软件错误定位技术综述
基于覆盖信息的软件错误定位技术综述基于覆盖信息的软件错误定位技术综述
基于覆盖信息的软件错误定位技术综述
 
Pycontw2013x
Pycontw2013xPycontw2013x
Pycontw2013x
 

連淡水阿嬤都聽得懂的 機器學習入門 scikit-learn

  • 2. 給門外漢的機器學習入門 描述 程度 Level 1 不知道什麼是機器學習 門外漢 (O) Level 2 知道機器學習是AI的子學門 Level 3 會使用機器學習套件解問題 初學者 Level 4 會選擇適合的機器學習演算法與調參數 Level 5 知道機器學習演算法的數學原理 專家 Level 6 會設計新的機器學習演算法 2 Cicilia Lee @ PyCon TW 2016
  • 3. 大綱 1. 什麼是機器學習? 2. 機器學習的分類 3. 機器學習流程 4. Scikit-learn 範例 5. Scikit Learn 數字辨識步驟 6. 前處理 7. 選擇機器學習演算法 3 Cicilia Lee @ PyCon TW 2016
  • 4. 什麼是機器學習?  我們有大量的樣本資料(sample data),讓機 器自動從中學習出規則,用來預測其他未知 的資料。  機器學習是基於機率、統計、逼近論等數學 理論的研究。  機器學習可應用於電腦視覺、自然語言處理、 語音和手寫識別和機器人等領域。 Cicilia Lee @ PyCon TW 2016 4
  • 5. 機器學習的分類  Supervised Learning 監督式學習  訓練集的目標是人為標註的。  Classification 分類 : 預測類別  Regression 回歸 : 預測變量  Unsupervised Learning 非監督式學習  訓練集沒有人為標註的目標。  Clustering 分群 5 Cicilia Lee @ PyCon TW 2016
  • 6. 機器學習流程 Cicilia Lee @ PyCon TW 2016 6 Model 模型 Testing set
  • 7. Scikit Learn 數字辨識範例  這個範例用來展示scikit-learn 如何用SVM演 算法來達成手寫的數字辨識  http://scikit- learn.org/stable/auto_examples/classification/plot_digits_class ification.html Cicilia Lee @ PyCon TW 2016 7
  • 8. Scikit Learn 數字辨識步驟 1. Load data 2. Set a classifier 3. Learn a model 4. Predict the result 5. Evaluate Cicilia Lee @ PyCon TW 2016 8
  • 9. Scikit Learn 數字辨識 (1/3) # Import datasets, classifiers and performance metrics from sklearn import datasets, svm, metrics ### 1. Load data # The digits dataset digits = datasets.load_digits() # To apply a classifier on this data, we need to flatten the image, to # turn the data in a (samples, feature) matrix: n_samples = len(digits.images) data = digits.images.reshape((n_samples, -1)) 9 Cicilia Lee @ PyCon TW 2016
  • 10. Scikit Learn 數字辨識 (2/3) ### 2. Set a classifier # Create a classifier: a support vector classifier classifier = svm.SVC(gamma=0.001) ### 3. Learn a model # We learn the digits on the first half of the digits classifier.fit(data[:n_samples / 2], digits.target[:n_samples / 2]) 10 Cicilia Lee @ PyCon TW 2016
  • 11. Scikit Learn 數字辨識 (3/3) ### 4. Predict the result # Now predict the value of the digit on the second half: expected = digits.target[n_samples / 2:] predicted = classifier.predict(data[n_samples / 2:]) ### 5. Evaluate print("Classification report for classifier %s:n%sn" % (classifier, metrics.classification_report(expected, predicted))) print("Confusion matrix:n%s" % metrics.confusion_matrix(expected, predicted)) 11 Cicilia Lee @ PyCon TW 2016
  • 12. Script output (1/2) Classification report for classifier SVC(C=1.0, cache_size=200, class_weight=None, coef0=0.0, decision_function_shape=None, degree=3, gamma=0.001, kernel='rbf', max_iter=-1, probability=False, random_state=None, shrinking=True, tol=0.001, verbose=False): precision recall f1-score support 0 1.00 0.99 0.99 88 1 0.99 0.97 0.98 91 2 0.99 0.99 0.99 86 3 0.98 0.87 0.92 91 4 0.99 0.96 0.97 92 5 0.95 0.97 0.96 91 6 0.99 0.99 0.99 91 7 0.96 0.99 0.97 89 8 0.94 1.00 0.97 88 9 0.93 0.98 0.95 92 avg / total 0.97 0.97 0.97 899 12 Cicilia Lee @ PyCon TW 2016
  • 13. Script output (2/2) Confusion matrix: [[87 0 0 0 1 0 0 0 0 0] [ 0 88 1 0 0 0 0 0 1 1] [ 0 0 85 1 0 0 0 0 0 0] [ 0 0 0 79 0 3 0 4 5 0] [ 0 0 0 0 88 0 0 0 0 4] [ 0 0 0 0 0 88 1 0 0 2] [ 0 1 0 0 0 0 90 0 0 0] [ 0 0 0 0 0 1 0 88 0 0] [ 0 0 0 0 0 0 0 0 88 0] [ 0 0 0 1 0 1 0 0 0 90]] 13 Cicilia Lee @ PyCon TW 2016
  • 14. 前處理 1. Clean data 2. Feature extraction 3. Convert category and string to number 4. Sparse data 5. Feature selection 14 Cicilia Lee @ PyCon TW 2016
  • 16. 複習 1. 什麼是機器學習? 2. 機器學習的分類 3. 機器學習流程 4. Scikit-learn 範例 5. Scikit Learn 數字辨識步驟 6. 前處理 7. 選擇機器學習演算法 16 Cicilia Lee @ PyCon TW 2016
  • 17. Thank you  Reference  Scikit-learn 官網: http://scikit-learn.org/stable/index.html  Scikit-learn數字範例 http://scikit- learn.org/stable/auto_examples/classification/plot_digits_c lassification.html  選擇機器學習演算法 http://scikit- learn.org/stable/tutorial/machine_learning_map/index.ht ml  林軒田教授的機器學習教學影片 https://www.youtube.com/playlist?list=PLXVfgk9fNX2I7tB 6oIINGBmW50rrmFTqf Cicilia Lee @ PyCon TW 2016 17