Created
June 10, 2015 01:41
-
-
Save yuu-ito/18ed436d93d0f6d68267 to your computer and use it in GitHub Desktop.
ベイズ分類のための変量の特徴を見る。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library("magrittr") | |
library("dplyr") | |
data(Titanic) | |
t <- Titanic %>% as.data.frame %>% arrange(Survived,Class,Sex,Age) | |
t %>% | |
group_by(Survived) %>% | |
summarize(ClassCount=sum(Freq)) %>% | |
group_by %>% | |
mutate(priprob=ClassCount/sum(ClassCount)) -> a | |
t %>% | |
group_by(attr=Class,Survived) %>% | |
summarize(valClassCount=sum(Freq)) %>% | |
left_join(.,a) %>% | |
mutate(pr_attr_bar_class=valClassCount/ClassCount, | |
priprob_lik=pr_attr_bar_class*priprob) -> b | |
t %>% | |
group_by(attr=Sex,Survived) %>% | |
summarize(valClassCount=sum(Freq)) %>% | |
left_join(.,a) %>% | |
mutate(pr_attr_bar_class=valClassCount/ClassCount, | |
priprob_lik=pr_attr_bar_class*priprob) -> c | |
t %>% | |
group_by(attr=Age,Survived) %>% | |
summarize(valClassCount=sum(Freq)) %>% | |
left_join(.,a) %>% | |
mutate(pr_attr_bar_class=valClassCount/ClassCount, | |
priprob_lik=pr_attr_bar_class*priprob) -> d | |
b %>% | |
rbind(c) %>% | |
rbind(d) %>% as.data.frame -> res | |
res %>% arrange(desc(priprob_lik)) |
Author
yuu-ito
commented
Jun 10, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment