2017-04-09 44 views
0

我想在naive_bayes函数(naivebayes包),predict.naive_bayes函数(naivebayes包)和naiveBayes函数(e1071)中查看底层算法(代码)包)。 我得到像下面这样的东西,但我看不到算法本身。 naiveBayes 功能(X,...) UseMethod( “naiveBayes”) 我该如何查看朴素贝叶斯的R函数的算法

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

对于我来说,查找代码最简单的方法是CRAN的GitHub上的只读镜像。

predict.naive_bayeshere

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 
... 

e1071的naiveBayeshere ...你的要点(双关语意)。

+0

很酷!谢谢。 – matt