다음과 같은 문제점이 있습니다. bayes 분류자를 사용하여 "sex"와 "agegroup"의 두 변수를 사용하여 factor 변수 "cancer"(예 또는 아니오)를 지정하고 싶습니다.Naive Bayes R- 이상한 결과로 분류
install.packages("e1071")
install.packages("gmodels")
library(e1071)
library(gmodels)
data<-read.csv("http://www.reduts.net/cancer.csv", sep=";", stringsAsFactors = T)
## Sex and Agegroup ##
######################
# classification
testset<-data[,c("sex", "agegroup")]
cancer<-data[,"cancer"]
model<-naiveBayes(testset, cancer)
model
# apply model on testset
testset$predicted<-predict(model, testset)
testset$cancer<-cancer
CrossTable(testset$predicted, testset$cancer, prop.chisq=F, prop.r=F, prop.c=F, prop.t = F)
결과는 내 데이터의 남성과 젊은 사람에 따라 암이 자주 발생 내게 보여줍니다 이 내 (가상의) 샘플 데이터입니다. 실제 암 분류와 비교할 때 제 모델은 200 건 중 147 건 (= 88 + 59 건)을 올바르게 분류했습니다 (73.5 %).
| testset$original
testset$predicted | no | yes | Row Total |
------------------|-----------|-----------|-----------|
no | 88 | 12 | 100 |
------------------|-----------|-----------|-----------|
yes | 54 | 46 | 100 |
------------------|-----------|-----------|-----------|
Column Total | 142 | 58 | 200 |
------------------|-----------|-----------|-----------|
그러나, 나는 단 하나의 분류 변수 (섹스)를 사용하여 같은 일을하고 있었다 :
## Sex only ##
######################
# classification
testset2<-data[,c("sex")]
cancer<-data[,"cancer"]
model2<-naiveBayes(testset2, cancer)
model2
모델은 다음과 같다 :
Naive Bayes Classifier for Discrete Predictors
Call:
naiveBayes.default(x = testset2, y = cancer)
A-priori probabilities:
cancer
no yes
0.645 0.355
Conditional probabilities:
x
cancer f m
no 0.4573643 0.5426357
yes 0.5774648 0.4225352
을 분명히을, 남성은 암에 걸릴 가능성이 더 높습니다 (54 % 대 46 %).
Total Observations in Table: 200
| testset2$cancer
testset2$predicted | no | yes | Row Total |
-------------------|-----------|-----------|-----------|
no | 129 | 71 | 200 |
-------------------|-----------|-----------|-----------|
Column Total | 129 | 71 | 200 |
-------------------|-----------|-----------|-----------|
사람이 설명해 주시겠습니까, 여성과 남성 모두에 할당하는 이유 : 나는 원래의 데이터에 내 모델을 적용 할 때
이제# apply model on testset
testset2$predicted<-predict(model2, testset2)
testset2$cancer<-cancer
CrossTable(testset2$predicted, testset2$cancer, prop.chisq=F, prop.r=F, prop.c=F, prop.t = F)
는, 모든 경우는 같은 클래스로 분류된다 같은 클래스?