SlideShare a Scribd company logo
連淡水阿嬤都聽得懂的
機器學習入門
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

More Related Content

What's hot

はじめてのパターン認識 第8章 サポートベクトルマシン
はじめてのパターン認識 第8章 サポートベクトルマシンはじめてのパターン認識 第8章 サポートベクトルマシン
はじめてのパターン認識 第8章 サポートベクトルマシンMotoya Wakiyama
 
AESについて 輪講資料
AESについて 輪講資料AESについて 輪講資料
AESについて 輪講資料
Sorasuke
 
ディジタル信号処理 課題解説 その5
ディジタル信号処理 課題解説 その5ディジタル信号処理 課題解説 その5
ディジタル信号処理 課題解説 その5noname409
 
暗号技術入門
暗号技術入門暗号技術入門
暗号技術入門
MITSUNARI Shigeo
 
Vivado hls勉強会1(基礎編)
Vivado hls勉強会1(基礎編)Vivado hls勉強会1(基礎編)
Vivado hls勉強会1(基礎編)
marsee101
 
ゲームアプリの数学@GREE GameDevelopers' Meetup
ゲームアプリの数学@GREE GameDevelopers' Meetupゲームアプリの数学@GREE GameDevelopers' Meetup
ゲームアプリの数学@GREE GameDevelopers' Meetup
gree_tech
 
Kaggle参加報告: Champs Predicting Molecular Properties
Kaggle参加報告: Champs Predicting Molecular PropertiesKaggle参加報告: Champs Predicting Molecular Properties
Kaggle参加報告: Champs Predicting Molecular Properties
Kazuki Fujikawa
 
系統動力學課程簡介
系統動力學課程簡介系統動力學課程簡介
系統動力學課程簡介
良政 張
 
報酬設計と逆強化学習
報酬設計と逆強化学習報酬設計と逆強化学習
報酬設計と逆強化学習
Yusuke Nakata
 
Multi-agent actor-critic for mixed cooperative-competitive environmentsの紹介
Multi-agent actor-critic for mixed cooperative-competitive environmentsの紹介Multi-agent actor-critic for mixed cooperative-competitive environmentsの紹介
Multi-agent actor-critic for mixed cooperative-competitive environmentsの紹介
Yusuke Nakata
 
[study] pointer networks
[study] pointer networks[study] pointer networks
[study] pointer networks
Gyuhyeon Nam
 
Deep Learningについて(改訂版)
Deep Learningについて(改訂版)Deep Learningについて(改訂版)
Deep Learningについて(改訂版)
Brains Consulting, Inc.
 
組込向けDeep Learning最新技術の紹介 量子化テクニックとDorefaNetについて
組込向けDeep Learning最新技術の紹介量子化テクニックとDorefaNetについて組込向けDeep Learning最新技術の紹介量子化テクニックとDorefaNetについて
組込向けDeep Learning最新技術の紹介 量子化テクニックとDorefaNetについて
Natsutani Minoru
 
きつねさんでもわかるLlvm読書会 第2回
きつねさんでもわかるLlvm読書会 第2回きつねさんでもわかるLlvm読書会 第2回
きつねさんでもわかるLlvm読書会 第2回
Tomoya Kawanishi
 
進化計算とは(what is evolutional algorythm)
進化計算とは(what is evolutional algorythm)進化計算とは(what is evolutional algorythm)
進化計算とは(what is evolutional algorythm)
tetuwo181
 
가깝고도 먼 Trpo
가깝고도 먼 Trpo가깝고도 먼 Trpo
가깝고도 먼 Trpo
Woong won Lee
 
資料結構-20個經典題型
資料結構-20個經典題型資料結構-20個經典題型
資料結構-20個經典題型
逸 張
 
20130716 はじパタ3章前半 ベイズの識別規則
20130716 はじパタ3章前半 ベイズの識別規則20130716 はじパタ3章前半 ベイズの識別規則
20130716 はじパタ3章前半 ベイズの識別規則
koba cky
 
東京都市大学 データ解析入門 5 スパース性と圧縮センシング 2
東京都市大学 データ解析入門 5 スパース性と圧縮センシング 2東京都市大学 データ解析入門 5 スパース性と圧縮センシング 2
東京都市大学 データ解析入門 5 スパース性と圧縮センシング 2
hirokazutanaka
 

What's hot (20)

はじめてのパターン認識 第8章 サポートベクトルマシン
はじめてのパターン認識 第8章 サポートベクトルマシンはじめてのパターン認識 第8章 サポートベクトルマシン
はじめてのパターン認識 第8章 サポートベクトルマシン
 
AESについて 輪講資料
AESについて 輪講資料AESについて 輪講資料
AESについて 輪講資料
 
ディジタル信号処理 課題解説 その5
ディジタル信号処理 課題解説 その5ディジタル信号処理 課題解説 その5
ディジタル信号処理 課題解説 その5
 
暗号技術入門
暗号技術入門暗号技術入門
暗号技術入門
 
Vivado hls勉強会1(基礎編)
Vivado hls勉強会1(基礎編)Vivado hls勉強会1(基礎編)
Vivado hls勉強会1(基礎編)
 
Chapter1 4.6
Chapter1 4.6Chapter1 4.6
Chapter1 4.6
 
ゲームアプリの数学@GREE GameDevelopers' Meetup
ゲームアプリの数学@GREE GameDevelopers' Meetupゲームアプリの数学@GREE GameDevelopers' Meetup
ゲームアプリの数学@GREE GameDevelopers' Meetup
 
Kaggle参加報告: Champs Predicting Molecular Properties
Kaggle参加報告: Champs Predicting Molecular PropertiesKaggle参加報告: Champs Predicting Molecular Properties
Kaggle参加報告: Champs Predicting Molecular Properties
 
系統動力學課程簡介
系統動力學課程簡介系統動力學課程簡介
系統動力學課程簡介
 
報酬設計と逆強化学習
報酬設計と逆強化学習報酬設計と逆強化学習
報酬設計と逆強化学習
 
Multi-agent actor-critic for mixed cooperative-competitive environmentsの紹介
Multi-agent actor-critic for mixed cooperative-competitive environmentsの紹介Multi-agent actor-critic for mixed cooperative-competitive environmentsの紹介
Multi-agent actor-critic for mixed cooperative-competitive environmentsの紹介
 
[study] pointer networks
[study] pointer networks[study] pointer networks
[study] pointer networks
 
Deep Learningについて(改訂版)
Deep Learningについて(改訂版)Deep Learningについて(改訂版)
Deep Learningについて(改訂版)
 
組込向けDeep Learning最新技術の紹介 量子化テクニックとDorefaNetについて
組込向けDeep Learning最新技術の紹介量子化テクニックとDorefaNetについて組込向けDeep Learning最新技術の紹介量子化テクニックとDorefaNetについて
組込向けDeep Learning最新技術の紹介 量子化テクニックとDorefaNetについて
 
きつねさんでもわかるLlvm読書会 第2回
きつねさんでもわかるLlvm読書会 第2回きつねさんでもわかるLlvm読書会 第2回
きつねさんでもわかるLlvm読書会 第2回
 
進化計算とは(what is evolutional algorythm)
進化計算とは(what is evolutional algorythm)進化計算とは(what is evolutional algorythm)
進化計算とは(what is evolutional algorythm)
 
가깝고도 먼 Trpo
가깝고도 먼 Trpo가깝고도 먼 Trpo
가깝고도 먼 Trpo
 
資料結構-20個經典題型
資料結構-20個經典題型資料結構-20個經典題型
資料結構-20個經典題型
 
20130716 はじパタ3章前半 ベイズの識別規則
20130716 はじパタ3章前半 ベイズの識別規則20130716 はじパタ3章前半 ベイズの識別規則
20130716 はじパタ3章前半 ベイズの識別規則
 
東京都市大学 データ解析入門 5 スパース性と圧縮センシング 2
東京都市大学 データ解析入門 5 スパース性と圧縮センシング 2東京都市大学 データ解析入門 5 スパース性と圧縮センシング 2
東京都市大学 データ解析入門 5 スパース性と圧縮センシング 2
 

Viewers also liked

Python的50道陰影
Python的50道陰影Python的50道陰影
Python的50道陰影
Tim (文昌)
 
機器學習簡報 / 机器学习简报 Machine Learning
機器學習簡報 / 机器学习简报 Machine Learning 機器學習簡報 / 机器学习简报 Machine Learning
機器學習簡報 / 机器学习简报 Machine Learning
Will Kuan 官大鈞
 
機器學習與資料探勘:決策樹
機器學習與資料探勘:決策樹機器學習與資料探勘:決策樹
機器學習與資料探勘:決策樹
Xavier Yin
 
TENSORFLOW深度學習講座講義(很硬的課程)
TENSORFLOW深度學習講座講義(很硬的課程)TENSORFLOW深度學習講座講義(很硬的課程)
TENSORFLOW深度學習講座講義(很硬的課程)
NTC.im(Notch Training Center)
 
淺談深度學習
淺談深度學習淺談深度學習
淺談深度學習
Mark Chang
 
TensorFlow 深度學習講座
TensorFlow 深度學習講座TensorFlow 深度學習講座
TensorFlow 深度學習講座
Mark Chang
 
寫給大家的 Git 教學
寫給大家的 Git 教學寫給大家的 Git 教學
寫給大家的 Git 教學
littlebtc
 
Python 2-基本語法
Python 2-基本語法Python 2-基本語法
Python 2-基本語法
阿Samn的物理課本
 
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
Audrey 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 Python
Sujith Kumar
 
Python 2 vs. Python 3
Python 2 vs. Python 3Python 2 vs. Python 3
Python 2 vs. Python 3
Pablo Enfedaque
 
Advance OOP concepts in Python
Advance OOP concepts in PythonAdvance OOP concepts in Python
Advance OOP concepts in Python
Sujith Kumar
 
Introduction to Python
Introduction to Python Introduction to Python
Introduction to Python
amiable_indian
 
進階主題
進階主題進階主題
進階主題
Justin Lin
 
型態與運算子
型態與運算子型態與運算子
型態與運算子
Justin Lin
 
常用內建模組
常用內建模組常用內建模組
常用內建模組
Justin Lin
 
Python 起步走
Python 起步走Python 起步走
Python 起步走
Justin Lin
 
NTU ML TENSORFLOW
NTU ML TENSORFLOWNTU ML TENSORFLOW
NTU ML TENSORFLOW
Mark 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 Minutes
Matt Harrison
 
[系列活動] Python 程式語言起步走
[系列活動] Python 程式語言起步走[系列活動] Python 程式語言起步走
[系列活動] Python 程式語言起步走
台灣資料科學年會
 

Viewers also liked (20)

Python的50道陰影
Python的50道陰影Python的50道陰影
Python的50道陰影
 
機器學習簡報 / 机器学习简报 Machine Learning
機器學習簡報 / 机器学习简报 Machine Learning 機器學習簡報 / 机器学习简报 Machine Learning
機器學習簡報 / 机器学习简报 Machine Learning
 
機器學習與資料探勘:決策樹
機器學習與資料探勘:決策樹機器學習與資料探勘:決策樹
機器學習與資料探勘:決策樹
 
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 程式語言起步走
 

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

扶搖職上:協助職涯發展之AI智慧聊天機器人(LineBot)
扶搖職上:協助職涯發展之AI智慧聊天機器人(LineBot)扶搖職上:協助職涯發展之AI智慧聊天機器人(LineBot)
扶搖職上:協助職涯發展之AI智慧聊天機器人(LineBot)
Eric Tseng
 
手把手打開Python資料分析大門
手把手打開Python資料分析大門手把手打開Python資料分析大門
手把手打開Python資料分析大門
Yen-lung Tsai
 
扶搖職上
扶搖職上扶搖職上
扶搖職上
ssuser82d625
 
Python分支作業
Python分支作業Python分支作業
Python分支作業
吳錫修 (ShyiShiou Wu)
 
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 classification
IttrainingIttraining
 
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 implementation
Yung-Chun Chang
 
漫談 Source Control Management
漫談 Source Control Management漫談 Source Control Management
漫談 Source Control Management
Wen-Shih Chao
 
基于覆盖信息的软件错误定位技术综述
基于覆盖信息的软件错误定位技术综述基于覆盖信息的软件错误定位技术综述
基于覆盖信息的软件错误定位技术综述Tao He
 
Pycontw2013x
Pycontw2013xPycontw2013x
Pycontw2013xweijr
 

Similar to 連淡水阿嬤都聽得懂的 機器學習入門 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