# histogram of samples from binomiarl distribution # x<-dbinom(0:200,8100,1/81)*8100 plot(x,type="h",xlim=c(70,130)) # PlayTennis の訓練データとテストデータの読み込み # library(e1071) # 下記は例。使うディレクトリを設定してください。 setwd("D:/R/Sample") # xy<-read.csv("04PlayTennis.csv", header=TRUE) xyt<-read.csv("04PlayTennisTest01.csv",header=TRUE,as.is=TRUE) tt<-as.data.frame(factor(xyt[,1],levels=levels(xy[,1]))) for (i in 2:5) { tt<-data.frame(tt,factor(xyt[,i],levels=levels(xy[,i]))) } names(tt)<-names(xy) tt m <- naiveBayes(xy[,-5], xy[,5]) predict(m, tt) # 予測した確率値. # predict(m, tt, type="raw") # 計算の背景である、学習結果の中味 # m # confusion matrix # table(predict(m, xy[,-5]), xy[,5])