公務機關對個人資料之利用與傳遞ja.lawbank.com.tw/pdf2/2291-2309.pdf · 我國電腦處理個人資料保護法就個人資料處理與利用之規範,形式上採歐洲
R 與 資料處理 - datascienceandr.orgdatascienceandr.org/slide/RDataEngineer-Introduction.pdf ·...
Transcript of R 與 資料處理 - datascienceandr.orgdatascienceandr.org/slide/RDataEngineer-Introduction.pdf ·...
R 與資料處理
Wush Wu國立台灣大學
R 與資料處理
1 of 58
課程內容
資料科學的Hello WorldR 的資料處理技術與今日課程介紹關於swirl
···
2/58
R 與資料處理
2 of 58
資料科學的Hello World
3/58
R 與資料處理
3 of 58
Dashboard是團隊的第一步4/58
R 與資料處理
4 of 58
檢驗資料的品質
乾淨正確
··
5/58
R 與資料處理
5 of 58
檢驗對資料的想法
設計問題設計KPI
··
6/58
R 與資料處理
6 of 58
一個資料源,一個Dashboard
價值會隨著資料源的多元而增加·
7/58
R 與資料處理
7 of 58
Dashboard 能快速建立信任感
資料科學團隊是成本單位資料科學團隊需要其他團隊的合作
··
8/58
R 與資料處理
8 of 58
R 社群活動:Cyber Security9/58
R 與資料處理
9 of 58
R 的資料處理技術
10/58
R 與資料處理
10 of 58
R 是一套完整的資料科學解決方案
資料的收集資料的處理資料的視覺化
···
11/58
R 與資料處理
11 of 58
讀取資料
RBasic-07-Loading-DataRDataEngineer-01-ParsingRDataEngineer-02-XMLRDataEngineer-03-JSONRDataEngineer-04-Database
·····
12/58
R 與資料處理
12 of 58
處理資料
RDataEngineer-05-Data-ManipulationRDataEngineer-06-Join
··
13/58
R 與資料處理
13 of 58
關於swirl使用自己電腦的同學,請依照課程網頁更新教材 -·
14/58
R 與資料處理
14 of 58
關於swirl
這次新增了以下指令:·chat()可以打開聊天室
issue()可以打開issues--
15/58
R 與資料處理
15 of 58
RBasic-07-Loading-Data
16/58
R 與資料處理
16 of 58
R 預設的讀取資料技術
套件中的資料CSV(comma-separated values)中文編碼
···
17/58
R 與資料處理
17 of 58
CSV(comma-separated values)
Year,Make,Model1997,Ford,E3502000,Mercury,Cougar
18/58
R 與資料處理
18 of 58
CSV(comma-separated values)
分隔符號:單一字符Hive的CSV:
··
欄位的分隔符號(Field)集合的分隔符號(Collection)Map key的分隔符號
---
19/58
R 與資料處理
19 of 58
字符編碼(Encoding)
20/58
R 與資料處理
20 of 58
Hex和Binary
Hex Code (16進位)·位元組(byte)是目前電腦處理記憶體的基本單位。一個位元組有8個位元(bit)。
用兩個hex code來代表一個位元組
-
00000001, 00110101--
00000001 ==> 0000,0001 ==> 0100110101 ==> 0011,0101 ==> 35
--
21/58
R 與資料處理
21 of 58
範例:文字的"0"與數字的0L
整數0L的記憶體,寫成hex code是 00 00 00 00 (佔有四個位元組)文字"0"的記憶體,寫成hex code是 30 (佔有一個位元組)
·
·
22/58
R 與資料處理
22 of 58
編碼(Encoding)
把位元組的組合轉換成文字的規則ASCII
··
30 => "0"、41 => "A"、0D => Enter(\r)、0A => 換行(\n)
-
23/58
R 與資料處理
23 of 58
中文編碼
UTF-8
BIG5
·E4 B8 AD => "中"E6 96 87 => "文"
--
·A4 A4 => "中"A4 E5 => "文"
--
24/58
R 與資料處理
24 of 58
編碼101
iconv
Encoding
Sys.getlocale(), Sys.setlocale(locale ="cht")
···
25/58
R 與資料處理
25 of 58
RDataEngineer-01-Parsing
26/58
R 與資料處理
26 of 58
非結構化的資料
請問電腦如何知道以下資訊的意義?·64.242.88.10 - - [07/Mar/2004:16:05:49 -0800] "GET/twiki/bin/edit/Main/Double_bounce_sender?topicparent=Main.Con�gurationVariaHTTP/1.1" 401 1284664.242.88.10 - - [07/Mar/2004:16:06:51 -0800] "GET/twiki/bin/rdi�/TWiki/NewUserTemplate?rev1=1.3&rev2=1.2 HTTP/1.1" 200 4523
-
-
27/58
R 與資料處理
27 of 58
什麼是Parsing?
根據Domain Knowledge,告訴電腦資料的規則·位置分隔符號Regular Expression
---
28/58
R 與資料處理
28 of 58
RDataEngineer-02-XML
29/58
R 與資料處理
29 of 58
XML(eXtensible Markup Language)
出自:https://zh.wikipedia.org/wiki/XML#.E4.BE.8B
讓電腦能理解資料意義的資料格式·標籤屬性內容
---
<?xml version="1.0"?><小紙條><收件人>大元</收件人><發件人>小張</發件人><主題>問候</主題><具體內容>早啊,飯吃了沒? </具體內容></小紙條>
30/58
R 與資料處理
30 of 58
HTML
有規範的標籤HTML用於撰寫網頁、XML用於傳輸資料
··
31/58
R 與資料處理
31 of 58
XPath(XML Path Language)
<A><B><C/>
</B></A>
/A/B/C
//B
··
32/58
R 與資料處理
32 of 58
RDataEngineer-03-JSON
33/58
R 與資料處理
33 of 58
JSON(JavaScript Object Notation)
{ "firstName": "John", "lastName": "Smith", "sex": "male", "age": 25}
34/58
R 與資料處理
34 of 58
JSON(JavaScript Object Notation)
字串:"firstName", "John"數字: 25
陣列: [1, 2, "3"]
物件: { "a" : 1, "b" : "string", "c" : {"c1" : 1 } }
····
35/58
R 與資料處理
35 of 58
RDataEngineer-04-Database
36/58
R 與資料處理
36 of 58
結構化資料
非結構化資料:純文字半結構化資料:CSV、XML、JSON結構化資料:關聯式資料庫(data.frame)
···
37/58
R 與資料處理
37 of 58
R 的物件導向系統
library(RSQLite)
Loading required package: DBI
Loading required package: methods
methods("dbConnect")
[1] dbConnect,SQLiteConnection-method dbConnect,SQLiteDriver-method see '?methods' for accessing help and source code
38/58
R 與資料處理
38 of 58
Transaction
保證一件工作:
範例:
·未執行已完成
--
·複製到暫存檔案重新命名
--
39/58
R 與資料處理
39 of 58
RDataEngineer-05-Data-Manipulation
40/58
R 與資料處理
40 of 58
R 的結構化資料來源
內部:data.frame、data.table
外部:關聯式資料庫
··
41/58
R 與資料處理
41 of 58
Grouped Operation
group_by
對group_by的輸出做操作
·分類-
·同步操作-
42/58
R 與資料處理
42 of 58
Grouped Operationsummarise(flights, mean(dep_delay, na.rm =TRUE))
group_by(flights, month) %>%summarise(flight, mean(dep_delay, na.rm =TRUE))
·
######## == summarise ==> result-·
######### == group_by ==> ### ### ###-### == summarise ==> result1### == summarise ==> result2### == summarise ==> result3
---
43/58
R 與資料處理
43 of 58
程式碼的壓縮
x1 <- filter(flights, ...)x2 <- select(x1, ...)x3 <- summarise(x2, ...)
44/58
R 與資料處理
44 of 58
程式碼的壓縮
把x1用filter(flights, ...)取代·
x2 <- select(filter(flights, ...), ...)x3 <- summarise(x2, ...)
45/58
R 與資料處理
45 of 58
程式碼的壓縮
summarise(select(filter(flights, ...), ...), ...)
46/58
R 與資料處理
46 of 58
Pipeline Operator
把filter的結果放到select的第一個參數
x2 <- filter(flights, ...) %>% select(...)x3 <- summarise(x2, ...)
47/58
R 與資料處理
47 of 58
Pipeline Operator
把filter的結果放到select的第一個參數 把select的結果放到summarise的第一個參數
x3 <- filter(flights, ...) %>% select(...) %>% summarise(...)
48/58
R 與資料處理
48 of 58
RDataEngineer-06-Join
49/58
R 與資料處理
49 of 58
多資料源能激盪出更高的價值
�ights�ights + weather�ights + weather + airports
···
50/58
R 與資料處理
50 of 58
left_join51/58
R 與資料處理
51 of 58
right_join52/58
R 與資料處理
52 of 58
inner_join53/58
R 與資料處理
53 of 58
full_join54/58
R 與資料處理
54 of 58
anti_join55/58
R 與資料處理
55 of 58
semi_join56/58
R 與資料處理
56 of 58
結束之後
57/58
R 與資料處理
57 of 58
你已經是一個初階的資料科學家
政府採購資料 v.s. 公司基本資料各里開票結果 v.s. 各里收入中位數登革熱病例變化 v.s. 電子發票
···
58/58
R 與資料處理
58 of 58