[R] NaiveBayes fails with one input variable (caret and klarR packages)

Max max.kuhn at pfizer.com
Tue Jun 30 20:51:01 CEST 2009


I just put a new version on cran...


On 6/30/09 2:12 PM, "Max Kuhn" <mxkuhn at gmail.com> wrote:

> I'm figuring this out now and I'll let you know when it is resolved...
> 
> On Tue, Jun 30, 2009 at 11:31 AM, Damian Krstajic<dkrstajic at hotmail.com>
> wrote:
>> 
>> Hello,
>> 
>> We have a system which creates thousands of regression/classification models
>> and in cases where we have only one input variable  NaiveBayes throws an
>> error. Maybe I am mistaken and I shouldn't expect to have a model with only
>> one input variable.
>> 
>> We use R version 2.6.0 (2007-10-03). We use caret (v4.1.19), but have tested
>> similar code with klaR (v.0.5.8), because caret relies on NaiveBayes
>> implementation from klaR. I get different error messages from caret than from
>> klaR so I will provide the code for caret usage and klaR usage.
>> 
>> Here is the code which uses the iris dataset.
>> 
>>> library(klaR);
>> Loading required package: MASS
>>> X<-iris["Sepal.Length"];
>>> Y<-iris["Species"];
>>> mnX<-as.matrix (X);
>>> mnY<-as.matrix (Y);
>>> cY<-factor(mnY);
>>> d <- data.frame (cbind(mnX,cY));
>>> m<-NaiveBayes(cY~mnX, data=d);
>>> predict(m);
>> Error in as.vector(x, mode) : invalid argument 'mode'
>>> library(caret);
>> Loading required package: lattice
>>> mCaret<-train(mnX,cY,method="nb",trControl = trainControl(method = "cv",
>>> number = 10));
>> Loading required package: class
>> Fitting: usekernel=TRUE
>> Fitting: usekernel=FALSE
>>> predicted <- predict(mCaret, newdata=mnX);
>> Error in 1:nrow(newdata) : NA/NaN argument
>>> 
>> 
>> We use caret to call NaiveBayes and we don't have any error messages in cases
>> where the number of input variables is greater than 1.
>> 
>> Cheers
>> DK
>> 
>> _________________________________________________________________
>> [[elided Hotmail spam]]
>> 
>>        [[alternative HTML version deleted]]
>> 
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>> 
> 
> 




More information about the R-help mailing list