私は以下の問題を抱えています。Bayesクラシファイアで2つの変数 "sex"と "agegroup"を使用して、因子変数 "cancer"(yesまたはno)を指定したいと思います。Naive Bayes R - strange結果の分類
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例(73%)が正しく分類されています。
| testset$original
testset$predicted | no | yes | Row Total |
------------------|-----------|-----------|-----------|
no | 88 | 12 | 100 |
------------------|-----------|-----------|-----------|
yes | 54 | 46 | 100 |
------------------|-----------|-----------|-----------|
Column Total | 142 | 58 | 200 |
------------------|-----------|-----------|-----------|
しかし、その後、私は唯一の1つの分類変数(性別)を使用して同じことをやっていた:
## 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%)。私は元のデータに私のモデルを適用すると今、すべての場合は、同じクラスに分類されている
# 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)
:
Total Observations in Table: 200
| testset2$cancer
testset2$predicted | no | yes | Row Total |
-------------------|-----------|-----------|-----------|
no | 129 | 71 | 200 |
-------------------|-----------|-----------|-----------|
Column Total | 129 | 71 | 200 |
-------------------|-----------|-----------|-----------|
両方の女性と男性が割り当てられている、なぜ誰もが、私に説明していただけます同じクラス?