タイタニックをネタにRの使い方を学ぶ(その2)
前回の記事の続き
決定木
> titanicTree <- rpart(Survived ~ Age + Sex, data=titanic)
> titanicTree
n= 891node), split, n, deviance, yval
* denotes terminal node1) root 891 210.727300 0.3838384
2) Sex=male 577 88.409010 0.1889081
4) Age>=6.5 553 77.359860 0.1681736 *
5) Age< 6.5 24 5.333333 0.6666667 *
3) Sex=female 314 60.105100 0.7420382 *
>
男性で6歳以下、女性が生存率がよいということかしら?
試しに↑で結果をPostしてみたところ、73%->75%にスコアが上がった。
(73%は、単純に女性のみ生存予測)
もう一つ。
> titanicTree <- rpart(Survived ~ Age + Sex + Fare, data=titanic)
> titanicTree
n= 891node), split, n, deviance, yval
* denotes terminal node1) root 891 210.727300 0.3838384
2) Sex=male 577 88.409010 0.1889081
4) Age>=6.5 553 77.359860 0.1681736
8) Fare< 26.26875 404 39.207920 0.1089109 *
9) Fare>=26.26875 149 32.885910 0.3288591 *
5) Age< 6.5 24 5.333333 0.6666667 *
3) Sex=female 314 60.105100 0.7420382
6) Fare< 48.2 225 50.328890 0.6622222 *
7) Fare>=48.2 89 4.719101 0.9438202 *
これで条件変えられそうなのはなかった。
> titanicTree <- rpart(Survived ~ Age + Sex + Parch, data=titanic)
> titanicTree
n= 891node), split, n, deviance, yval
* denotes terminal node1) root 891 210.7273000 0.3838384
2) Sex=male 577 88.4090100 0.1889081
4) Age>=6.5 553 77.3598600 0.1681736 *
5) Age< 6.5 24 5.3333330 0.6666667 *
3) Sex=female 314 60.1051000 0.7420382
6) Parch>=3.5 7 0.8571429 0.1428571 *
7) Parch< 3.5 307 56.6775200 0.7557003 *
Parch=>3.5の女性は生存率が低いらしい。
これをPostすると、76%までアップ。
同じ確率の人がたくさんいることを考えると、同じ条件でPostしてるんだろうな、、、
分析って難しい。