Kaggle



Kaggle  這是一個數據分析的競賽平台,

之前從這篇 - 資料科學自學清單上看到

似乎 2013/2014 就有了, 但後來看結果排名, 很多 2016 都還在玩呢

https://www.kaggle.com/c/titanic/leaderboard


一開始註冊登錄後, 會介紹這一篇 : 鐵達尼號

Getting Started -> Titanic:Machine Learning from Disaster


會先建議學習 Python R 語言

競賽可以從 101 或 playground 開始




蠻建議新手從這個推薦的鐵達尼號分析開始. 挺有趣的.

會提供/解說相關的資料, training data, 建立預測模型, 看預測結果.

通常 80% 都是很不錯的系統預測模型.


 大致想說的架構如下圖 :






一開始進去有個國家地理的節錄影片, 音樂很好聽呢.





可以先在這

取得資料


抓到的 csv 檔是可以打開直接看的, 也可以匯入到 excel.

會告訴前面這 891 乘客的資料和生死,
並提供後面 418 位乘客 資料, 但不知生死, 用以推測;

最後把結果上傳, 正確結果網站知道, 會給個結果的正確率和排名,


VARIABLE DESCRIPTIONS:
survival        Survival
                (0 = No; 1 = Yes)
pclass          Passenger Class
                (1 = 1st; 2 = 2nd; 3 = 3rd)
name            Name
sex             Sex
age             Age
sibsp           Number of Siblings/Spouses Aboard
parch           Number of Parents/Children Aboard
ticket          Ticket Number
fare            Passenger Fare
cabin           Cabin
embarked        Port of Embarkation
                (C = Cherbourg; Q = Queenstown; S = Southampton)

SPECIAL NOTES:
Pclass is a proxy for socio-economic status (SES)
 1st ~ Upper; 2nd ~ Middle; 3rd ~ Lower

Age is in Years; Fractional if Age less than One (1)
 If the Age is Estimated, it is in the form xx.5

With respect to the family relation variables (i.e. sibsp and parch)
some relations were ignored.  The following are the definitions used
for sibsp and parch.

Sibling:  Brother, Sister, Stepbrother, or Stepsister of Passenger Aboard Titanic
Spouse:   Husband or Wife of Passenger Aboard Titanic (Mistresses and Fiances Ignored)
Parent:   Mother or Father of Passenger Aboard Titanic
Child:    Son, Daughter, Stepson, or Stepdaughter of Passenger Aboard Titanic

Other family relatives excluded from this study include cousins,
nephews/nieces, aunts/uncles, and in-laws.  Some children travelled
only with a nanny, therefore parch=0 for them.  As well, some
travelled with very close friends or neighbors in a village, however,
the definitions do not support such relations.



Excel - train.csv

有 891 位 乘客.



想用 python 寫可以從 python 這篇 開始看看. -


讀取 csv 檔 程式 - github

Python csv 程式說明


可以用這做一些統計

number of passengers :  891
number of survived :  342.0
survivor's proportion :  0.383838383838
Proportion of women who survived is 0.742038216561

Proportion of men who survived is 0.188908145581

透過這我們可以發現, 女人比男人有較高的存活率

接下來用 Pandas 來讀取 table

...

前兩個 web training 大致介紹 python 用法.


===

Training 3 介紹的就是用 machine learning 方式來解 :

為此學習了一下 非線性廻歸分析

    random forest , 亂數森林 :


 Kaggle 也有稍微介紹:  亂森 教學 -

找一篇別人的心得, 先按照這繼續學習 ;

自己學習的心得 ;

(1) Name / Ticket / Cabin :

他說不重要.. 但前面例子似乎 cabin 還是有相依性,
應該先從探討個變數對生存率的關係係數 開始做

而且 Name 可以決定家族關係圖; Ticket/Cabin 可以看出是多富有.
不過先照他的做看看

(2) dropna

他把資料有欠缺的全刪了, 剩下 712 個有效 training, 其實看前面教學,
應該是想教補齊 data 的方法. (e.g. 平均數 )
果然後面, 他覺得這樣太浪費了, 改往補齊 891 筆資料來做


(3) 使用 random forest, 它採用 0.7 / 0.3 split 自我測試 : 0.79 / 0.80

(4) 輸入 test data 預測
      在前面取得資料部分, 有一個 test.csv ; 裡面有 418 筆資料.
      須注意他沒有 Survived 欄位, 輸入到 亂森 需要相同格式的 data,
      才能產生預測值

     在做的時候, 有產生一個 float 轉換 的 value error ;
     需增加 :

     from sklearn.preprocessing import Imputer

     X_tests = Imputer().fit_transform(X_tests)

     其實這邊應該逐項檢查 Test 資料, 用統計方式補上一個好的數值. 
     再進 model 分析


(5) 產生 結果的 csv 檔.

      只需要兩欄 : PassengerID / Survived

PassengerID,Survived
892,0

893,0
...


output = np.column_stack((X_tests[:,0], y_results))
df_results = pd.DataFrame(output.astype('int'), columns=['PassengerID', 'Survived'])
df_results.to_csv('titanic_results.csv', index=False)


      接著把結果檔上傳 : 
 
https://www.kaggle.com/c/titanic/submissions/attach



就會列出 結果和排名 : 

( 一天可以上傳十次的樣子 )

用這方法, 正確率 74%, 看來還有很大改進的空間 , 不過 7 成勝率就值得賭一把了. 

亂數森林還真是神奇.. 

果然 大數據 / 資料統計處理預測 / 機器學習 是目前的顯學呢




程式 : github


接續改進1 : http://njiot.blogspot.tw/2016/07/kaggle-titanic-1.html

---
參考 :


http://agconti.github.io/kaggle-titanic/


* 數字識別

https://wefollownews.appspot.com/cittopnews201408_21/11121.html




留言

熱門文章