Presentation is loading. Please wait.

Presentation is loading. Please wait.

Data Mining 工具介紹 (Weka/R to MySQL)

Similar presentations


Presentation on theme: "Data Mining 工具介紹 (Weka/R to MySQL)"— Presentation transcript:

1 Data Mining 工具介紹 (Weka/R to MySQL)
Supplement Data Mining 工具介紹 (Weka/R to MySQL) 楊立偉教授 台灣大學工管系 2018 1

2 Data Mining 工具 The R Project for Statistical Computing
Weka : Data Mining Software in Java scikit-learn: machine learning in Python SAS Enterprise Miner (EM) Business Analytics and Business Intelligence Software IBM SPSS Predictive analytics software and solutions and others

3 使用WEKA連接資料庫 3

4 Using Weka (1) 下載安裝Java 下載Weka 下載MySQL Connector/J
下載Weka 選擇Other platforms版本,解壓縮後取得weka.jar 下載MySQL Connector/J 選擇Platform Independent版本,解壓縮後取得mysql-connector-java jar

5 unzip WEKA 下載跨平台版本並解壓縮至特定目錄,例如/weka
V

6 unzip MySQL Connector/J
下載跨平台版本,並解壓縮至同一目錄,例如/weka V

7 Using Weka (2) 找到mysql-connector-java jar 並複製到與weka.jar同一目錄下,如右圖

8 Windows請搜尋cmd後執行,開啟命令提示字元
開啟命令提示字元 (或終端機) Windows請搜尋cmd後執行,開啟命令提示字元 Mac請開啟工具程式下的終端機 輸入 java,若有出現版本訊息,代表java環境已備妥 利用cd指令切換至weka所在目錄 (範例是在Downloads下的weka-3-8-3) 輸入下列指令,如下圖 java -cp weka.jar;mysql-connector-java jar weka.gui.GUIChooser (Mac用戶請將上述指令的分號 ; 換成冒號 :,其餘不變) 切換至該目錄

9 Using Weka (3) 啟動Weka後選KnowledgeFlow,在DataSources選DatabaseLoader,在右邊工作畫布上放置一個,選取後按右鍵選Configure…

10 Using Weka (4) Database URL輸入 輸入使用者名稱及密碼 輸入Query指令 選擇DB config file
jdbc:mysql://sqldb.demo.tornado.com.tw:3306/sample?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC 輸入使用者名稱及密碼 輸入Query指令 SELECT outlook, temperature, humidity, windy, play FROM tennis 選擇DB config file 下載課程網頁上mysql.props檔 選擇該檔案

11 Using Weka (5) 在Visualization選TextViewer,在右邊工作畫布上放置一個,選取DatabaseLoader後按右鍵選dataSet,產生一條線連至TextViewer

12 Using Weka (6) 在左上角按下執行按鈕,下方訊息若出現Finished表示完成 (若有錯誤訊息請檢查設定)
選取TextViewer後按右鍵選Show results,若出現查詢結果表示成功

13 使用WEKA進行Data Mining 13

14 Using Weka – Tree (1) 放置Evaluation→ClassAssigner,以及TrainingSetMaker
放置Classifiers→trees→J48 (即C4.5演算法之實作) 放置Visualization→TextViewer

15 Using Weka – Tree (2) 在DatabaseLoader按右鍵選dataSet到ClassAssigner
在ClassAssigner按右鍵選dataSet到TrainingSetMaker 在TrainingSetMaker按右鍵選trainingSet到J48 在J48按右鍵選text到TextViewer

16 Using Weka – Tree (3) 在ClassAssigner按右鍵選configure確認目標欄位是play
在DatabaseLoader按右鍵選Start loading 執行完畢,在TextViewer按右鍵選Show results看結果

17 Using Weka – Clustering
使用Simple Kmeans演算法,用TextViewer看結果 以k=3為例

18 Using Weka – Association (1)
使用Apriori演算法,用TextViewer看結果 只能處理nominal value

19 Using Weka – Association (2)
使用Apriori演算法結果如下 * 決策樹的每條path可能就是一條rule;可能會找到更多的rules

20 可儲存畫布上的流程圖,重新再設計 其他可參考手冊 WekaManual.pdf
推薦閱讀 tutorial 的p7~p9 如何做cross-validation,以及如何化ROC curve

21 使用R連接資料庫 (Windows / Mac通用)
21

22 Using R with Database (1)
挑選CRAN(Comprehensive R Archive Network)中之站點,下載R安裝後執行 台大資工站點 選擇base版本下載,點擊安裝 之後執行R

23 Using R with Database (2)
使用RODBC套件 透過ODBC介面及對應驅動程式driver 使用RJDBC套件 透過JDBC介面及對應驅動程式driver 使用RMySQL套件 透過網路協定直接連接

24 如果選擇RMySQL套件 選程式套件>設定CRAN鏡像>挑選站點: 0-Cloud 執行指令
install.packages("RMySQL") 安裝套件 library(RMySQL) 載入套件 library(DBI) 載入相關套件 c = dbConnect(MySQL(), host='主機名稱', user='帳戶', password='密碼', dbname='資料庫名稱') 開啟連線, 取名為c dbListTables(c) 列出有哪些表格 x = dbGetQuery(c, 'select outlook, temperature, humidity, windy, play from tennis') 執行SQL x 顯示結果

25 如果選擇RODBC套件 選程式套件>設定CRAN鏡像>挑選站點: 0-Cloud 執行指令
install.packages("RODBC") 安裝套件 library(RODBC) 載入套件 c <- odbcConnect('ODBC DSN名稱') 開啟連線, 取名為c x = sqlFetch(c, 'tennis') 從該來源取出某張表 x = sqlQuery(c, 'SELECT outlook, temperature, humidity, windy, play FROM tennis') 或執行SQL

26 執行結果

27 Using R with Database (3)
安裝C50套件 選程式套件>設定CRAN鏡像>挑選站點: 0-Cloud 執行指令 install.packages("C50") 安裝套件 library(C50) 載入套件 m=C5.0(x[,1:4], as.factor(x$play)) 以第1~4欄做訓練,目標欄位為play (轉換為factor型態) summary(m)

28 執行結果

29 Using R with Database (4)
安裝arules套件 選程式套件>設定CRAN鏡像>挑選站點: 0-Cloud 執行指令 install.packages("arules") 安裝套件 library(arules) 載入套件 r=apriori(x[,1:5]) 以第1~5欄分析 rs=sort(r,by='confidence') 將結果排序 inspect(rs) 顯示結果

30 執行結果

31 Good LUCK !


Download ppt "Data Mining 工具介紹 (Weka/R to MySQL)"

Similar presentations


Ads by Google