2020/10/05

keras Titanic MLP 分析

Titanic 在 1912/4/12 撞上冰山沈沒,乘客與船員共 2224 人,其中 1502 人死亡。接下來以 MLP 預測每一個乘客的存活率。

乘客資料

下載 Titanic 客戶資料

# get titanic data
import urllib.request
import os

import os
if not os.path.exists('data'):
    os.makedirs('data')

url="http://biostat.mc.vanderbilt.edu/wiki/pub/Main/DataSets/titanic3.xls"
filepath="data/titanic3.xls"
if not os.path.isfile(filepath):
    result=urllib.request.urlretrieve(url,filepath)
    print('downloaded:',result)

訓練資料共 1309 筆,資料處理後,會有 9 個特徵欄位,label 欄位是 1: 存活 2: 死亡

透過 pandas 讀取資料並進行預處理

原始資料欄位

欄位 說明 資料說明
survival 是否存活 0: 否, 1: 是
pclass 艙等 1: 頭等艙, 2: 二等艙, 3: 三等艙
name 姓名
sex 性別 female: 女性, male: 男性
age 年齡
sibsp 手足或配偶也在船上的數量
parch 雙親或子女也在船上的數量
ticket 車票號碼
fare 旅客費用
cabin 艙位號碼
embarked 登船港口 C: Cherbourg, Q: Queenstown, S: Southampton

MLP

訓練過程

Train on 943 samples, validate on 105 samples
Epoch 1/30
 - 1s - loss: 0.6894 - acc: 0.5885 - val_loss: 0.6668 - val_acc: 0.7810
Epoch 2/30
 - 0s - loss: 0.6613 - acc: 0.6066 - val_loss: 0.5626 - val_acc: 0.7810
Epoch 3/30
 - 0s - loss: 0.6067 - acc: 0.6585 - val_loss: 0.4871 - val_acc: 0.8190
Epoch 4/30
 - 0s - loss: 0.5551 - acc: 0.7508 - val_loss: 0.4578 - val_acc: 0.7714
Epoch 5/30
 - 0s - loss: 0.5250 - acc: 0.7625 - val_loss: 0.4412 - val_acc: 0.8190
Epoch 6/30
 - 0s - loss: 0.5076 - acc: 0.7550 - val_loss: 0.4274 - val_acc: 0.8190
Epoch 7/30
 - 0s - loss: 0.5013 - acc: 0.7688 - val_loss: 0.4276 - val_acc: 0.8190
Epoch 8/30
 - 0s - loss: 0.4936 - acc: 0.7688 - val_loss: 0.4255 - val_acc: 0.8190
Epoch 9/30
 - 0s - loss: 0.4897 - acc: 0.7699 - val_loss: 0.4211 - val_acc: 0.8190
Epoch 10/30
 - 0s - loss: 0.4851 - acc: 0.7731 - val_loss: 0.4228 - val_acc: 0.8190
Epoch 11/30
 - 0s - loss: 0.4819 - acc: 0.7699 - val_loss: 0.4161 - val_acc: 0.8190
Epoch 12/30
 - 0s - loss: 0.4796 - acc: 0.7709 - val_loss: 0.4142 - val_acc: 0.8381
Epoch 13/30
 - 0s - loss: 0.4773 - acc: 0.7762 - val_loss: 0.4168 - val_acc: 0.8190
Epoch 14/30
 - 0s - loss: 0.4733 - acc: 0.7805 - val_loss: 0.4130 - val_acc: 0.8190
Epoch 15/30
 - 0s - loss: 0.4732 - acc: 0.7752 - val_loss: 0.4120 - val_acc: 0.8286
Epoch 16/30
 - 0s - loss: 0.4709 - acc: 0.7815 - val_loss: 0.4107 - val_acc: 0.8286
Epoch 17/30
 - 0s - loss: 0.4692 - acc: 0.7815 - val_loss: 0.4125 - val_acc: 0.8476
Epoch 18/30
 - 0s - loss: 0.4677 - acc: 0.7847 - val_loss: 0.4134 - val_acc: 0.8381
Epoch 19/30
 - 0s - loss: 0.4670 - acc: 0.7826 - val_loss: 0.4092 - val_acc: 0.8571
Epoch 20/30
 - 0s - loss: 0.4645 - acc: 0.7741 - val_loss: 0.4109 - val_acc: 0.8571
Epoch 21/30
 - 0s - loss: 0.4646 - acc: 0.7858 - val_loss: 0.4123 - val_acc: 0.8571
Epoch 22/30
 - 0s - loss: 0.4615 - acc: 0.7953 - val_loss: 0.4178 - val_acc: 0.8095
Epoch 23/30
 - 0s - loss: 0.4614 - acc: 0.7858 - val_loss: 0.4111 - val_acc: 0.8571
Epoch 24/30
 - 0s - loss: 0.4611 - acc: 0.7900 - val_loss: 0.4128 - val_acc: 0.8571
Epoch 25/30
 - 0s - loss: 0.4610 - acc: 0.7847 - val_loss: 0.4170 - val_acc: 0.8381
Epoch 26/30
 - 0s - loss: 0.4574 - acc: 0.7911 - val_loss: 0.4122 - val_acc: 0.8571
Epoch 27/30
 - 0s - loss: 0.4580 - acc: 0.7953 - val_loss: 0.4161 - val_acc: 0.8286
Epoch 28/30
 - 0s - loss: 0.4561 - acc: 0.7985 - val_loss: 0.4168 - val_acc: 0.8381
Epoch 29/30
 - 0s - loss: 0.4582 - acc: 0.7879 - val_loss: 0.4154 - val_acc: 0.8381
Epoch 30/30
 - 0s - loss: 0.4574 - acc: 0.7794 - val_loss: 0.4181 - val_acc: 0.8286
261/261 [==============================] - 0s 20us/step

References

TensorFlow+Keras深度學習人工智慧實務應用

沒有留言:

張貼留言