首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何看待朴素bayes的R函数算法

如何看待朴素bayes的R函数算法
EN

Stack Overflow用户
提问于 2017-04-09 10:32:41
回答 1查看 539关注 0票数 0

我正在尝试在naive_bayes函数(naivebayes包)、predict.naive_bayes函数(naivebayes包)和naiveBayes函数(e1071包)中看到底层算法(代码)。我得到了像下面这样的东西,但我看不到算法本身。naiveBayes函数(x,.)UseMethod("naiveBayes")

代码语言:javascript
复制
 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
>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-04-09 10:38:48

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

predict.naive_bayes这里

代码语言:javascript
复制
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
...

E 1071的naiveBayes这里.你得到了要点(双关意)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43305691

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档