我试图在naive_bayes函数(naivebayes包),predict.naive_bayes函数(naivebayes包)和naiveBayes函数(e1071包)中看到底层算法(代码)。 我得到的东西就像下面的东西,但我看不到算法本身。 naiveBayes 功能(x,...) UseMethod( “naiveBayes”)
naive_bayes
function (x, ...)
{
UseMethod("naive_bayes")
}
<environment: namespace:naivebayes>
predict.naive_bayes
Error: object 'predict.naive_bayes' not found
> predict
function (object, ...)
UseMethod("predict")
<bytecode: 0x000000000ad686d0>
<environment: namespace:stats>
naivebayes::naive_bayes
function (x, ...)
{
UseMethod("naive_bayes")
}
<environment: namespace:naivebayes>
> naivebayes:::naive_bayes
function (x, ...)
{
UseMethod("naive_bayes")
}
<environment: namespace:naivebayes>
>
I also tried this
> download.packages(naivebayes)
Error in dir.exists(destdir) :
argument "destdir" is missing, with no default
> download.packages(naivebayes, destdir = ".",type = "source")
Error in unique(pkgs) : object 'naivebayes' not found
> download.packages(e1071, destdir = ".",type = "source")
Error in unique(pkgs) : object 'e1071' not found
>
答案 0 :(得分:0)
对我来说,最容易查找代码的方法是CRAN在GitHub上的只读镜像。
<httpRuntime fcnMode="Disabled" />
是here。
predict.naive_bayes
e1071的predict.naive_bayes <- function(object, newdata = NULL, type = c("class", "prob"),
threshold = 0.001, ...) {
if (is.null(newdata)) newdata <- object$data$x
else newdata <- as.data.frame(newdata)
na <- sapply(newdata, anyNA)
type <- match.arg(type)
lev <- object$levels
n_lev <- length(lev)
n_obs <- dim(newdata)[1L]
usekernel <- object$usekernel
prior <- as.double(object$prior)
tables <- object$tables
features <- names(newdata)[names(newdata) %in% names(tables)]
log_sum <- 0
...
是here ...你得到了主旨(双关语)。