⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bogo.r

📁 一个C语言写的快速贝叶斯垃圾邮件过滤工具
💻 R
字号:
# bogo.R - check calculations performed by bogofilter## Before running this script,# prepare file bogo.tbl as follows: run#   bogofilter -R <mailbox >bogo.tbl# where mailbox is a file with only one email message in it.# Then run R and type#   source("bogo.R")# first read the databogo <- read.table("bogo.tbl")attach(bogo)# next read the special values from the last linel <- length(fw)bogoS <- fw[l]s <- invfwlog[l]x <- fwlog[l]md <- as.real(levels(U[l])[3])# now truncate bogo and reset l to matchdetach(bogo)bogo[abs(0.5 - bogo$fw) >= md,] -> bogoattach(bogo)l <- length(fw)# next recalculate the fw values from the counts in the tableattach(bogo)pw2 <- pbad / (pbad + pgood)pw2[pbad + pgood == 0] <- 0fw2 <- (s * x + n * pw2) / (s + n)# display fw (calculated by bogofilter) and fw2 and compareprint.noquote("R f(w):")print(round(fw2, digits=6))print.noquote("")print.noquote("Bogofilter f(w):")print(fw)print.noquote("")print.noquote("Difference (R - bogo):")print(round(fw2, digits=6) - fw)# calculate S using fw2P <- 1 - exp(sum(log(1-fw2))/l)Q <- 1 - exp(sum(log(fw2))/l)Srob <- ( 1 + (P-Q)/(P+Q) ) / 2S <- pchisq(sum(log(1-fw2)) * -2, 2 * l)H <- pchisq(sum(log(fw2)) * -2, 2 * l)Sfis <- (1 + S - H) / 2Drob <- abs(Srob - bogoS)Dfis <- abs(Sfis - bogoS)diff <- min(Drob,Dfis)RS <- if(Drob < Dfis) Srob else Sfis# display S as calculated by bogofilter and by R and compareprint.noquote("")print.noquote(sprintf(  "R S: %8.2e, Bogofilter S: %8.2e, Difference (R - bogo): %10.4e",  RS, bogoS, diff))

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -