人生的第一個 競賽
(沒有獎金的)
我可以, 你也可以
15 分鐘登上 kaggle 排行榜
Marconi Jiang 2018/12/28

about me
EE degree back in 1982
Z80 was the most popular CPU
Pascal/Fortran/COBOL were popular languages
Apple ][ + BASIC and CP/M
intel 80386SX PC mother board designer
......
Interested in Linux since 2016
Taiwan AI Academy -- Managerial 2018

Z80 CPU

intel 80386SX CPU
photo source: wikipedia.org

Apple ][
marconi.jiang@gmail.com
是誰
https://www.kaggle.com
Making Data Science a Sport 讓數據科學成為一項運動
- Google首席經濟師 Hal Ronald Varian 稱 Kaggle 提供了一種「將全世界最有才能的數據科學家組織起來並使各種規模的機構都能夠觸及」的方式
- Kaggle官方提供的數據,Kaggle在全球範圍內擁有將近20萬名數據科學家,專業領域從計算機科學到統計學、經濟學和數學
-
Kaggle是一個數據建模和數據分析競賽平台。
- 企業和研究者可在其上發布數據,統計學者和數據挖掘專家可在其上進行競賽以產生最好的模型。
- 這一眾包模式依賴於這一事實,即有眾多策略可以用於解決幾乎所有預測建模的問題,而研究者不可能在一開始就了解什麼方法對於特定問題是最為有效的。
- Kaggle的目標則是試圖通過眾包的形式來解決這一難題,進而使數據科學成為一場運動。
- 2017年3月8日谷歌官方宣布收購Kaggle。

Source: wikipedia.org
身為台灣 AI 界的黃埔軍校
AI Academy 第三期成員
怎可以在 Kaggle 國際舞台缺席


ps. 這份簡報針對懶得動手的人, 可以等到出現[動手]時才動手及可, 沒寫[動手]的部份, 可以看看就好, 一樣可以完成比賽
所有過程都完全在 Kaggle 網站上執行
先到 登錄


https://www.kaggle.com
有 Facebook 帳號就可以登錄了
登錄 後的首頁


(1) 我參加過的比賽
(2) 你的比賽就從這裡開始
準備參加 的手寫辨識競賽

(2) 點選 "Digit Recognizer" 正式加入比賽了
(1) 從這裡搜尋 "Digit" 就可以找的到

的手寫辨識競賽開始囉

這一頁提供的基礎課程可以很快跳過, 我們課堂都上過
需要注意 "Evaluation" 內容指定比賽上傳檔案的格式

Digit Recognizer 資料說明
(2) 三個原始檔案
(3) 原始檔案從這裡下載 (程式直接在 Kaggle 執行的話, 沒有必要下載)

1. train.csv 訓練資料 (validation 資料從 train 資料分割), dataframe (42000, 785), 785 = 28x28 (像素) + 1 (標記)
2. test.csv 測試資料, df(28000,784)
3. sample_submission.csv 測試 test.csv 的結果上傳格式
(4) 檔案及欄位說明
(1) 資料
開工了, 要認真寫(抄)程式
(1) 程式在 kernel 執行
(2) 許多善心人士公開提供程式及說明, 值得花時間細究
(3) 自己的程式儲存於此

(4) 第一個全新的程式由這裡開始
開始[動手]
當然選我們熟悉 Colab 用的 Notebook (ipynb)

進入程式開發 - 開發環境說明
(2) Console 內, 有執行狀態, 及輸出結果
(4) 資料位於 input 目錄下
(1) kaggle 提供的一小段程式, 說明基本設置與檔案目錄位置

(3) 不想看 Console 輸出, 按小箭頭關閉
進入程式開發 - 程式編寫
(1) 開始[動手]編寫程式, 可以參考我下頁(按 鍵, 不是 箭) 附上的程式碼, 已經驗證過可執行
(2) 執行方式跟 Colab 一樣按該單元 cell "三角形箭頭"或 "Shift"+"Enter"

進入程式開發 - 程式碼範例
# 環境設置
import numpy as np
import pandas as pd
import os
import tensorflow as tf
import csv
from keras.utils import to_categorical
train_file = '../input/train.csv'
test_file = '../input/test.csv'
submission_file = '../input/sample_submission.csv'
output_file = 'submission.csv'
train = pd.read_csv(train_file, encoding ='utf-8')
train_y = to_categorical(train['label'])
train_x = ((train.drop('label', axis = 1)).values) / 255.0
test = pd.read_csv(test_file, encoding ='utf-8')
test_x = test / 255.0
submission = pd.read_csv(submission_file, encoding ='utf-8')
# Import necessary modules
import keras
from keras.layers import Dense
from keras.models import Sequential
# 建立 model 及訓練
# Create the model: model
model = Sequential()
# Add the first hidden layer
model.add(Dense(50, activation='relu', input_shape=(784,)))
# Add the second hidden layer
model.add(Dense(50, activation='relu'))
# Add the output layer
model.add(Dense(10, activation='softmax'))
# Compile the model
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
# Fit the model
model.fit(train_x, train_y, validation_split=0.3, epochs =10)
# 執行 model 測試資料
# Calculate predictions: predictions
predictions = model.predict(test_x)
# columns of submission is ImageId, Label
for i in range(0,len(submission)):
digit = predictions[i].argmax(axis=0)
submission.loc[i,'Label'] = digit
submission.to_csv(output_file, index = False)
print(os.listdir("./"))
螢幕僅顯示部分內容, 可以拖拉 (drag) 選擇全部程式碼
程式執行及上傳
(1) [動手]執行後 ("shift"+"Enter"), 等執行完成, 確定輸出的檔案中有 submission.csv

(2) 將此次程式上傳 (commit)
程式上傳結果 - 成功 !
(1) 上傳成功後, 再從這裡進入 Notebook

查看輸出結果, 準備送成績
(1) 確定在 Output 選項下, 有 submission.csv 的資料, 就可以送成績了

(2) 送成績進比賽, 比排名
成績;排名出爐


(1) 成績 : 0.96242
(2) 排行
恭喜你 !
進入
Kaggle
排行榜
祝
台灣智慧學校
經理人班第三期全體同學
2019 年
事業蓬勃
闔家安康
My first Kaggle campaign
By jibo
My first Kaggle campaign
My first Kaggle campaign, motivated by AI Academy
- 441