WilDsc0p
2009-Apr-25 06:44 UTC
[R] Overlapping parameters "k" in different functions in "ipred"
Dear List, I have a question regarding "ipred" package. Under 10-fold cv, for different knn ( = 1,3,...25), I am getting same misclassification errors: ############################################# library(ipred) data(iris) cv.k = 10 ## 10-fold cross-validation bwpredict.knn <- function(object, newdata) predict.ipredknn(object, newdata, type="class") for (i in seq(1,25,2)){ set.seed(19) a<-errorest(Species ~ ., data=iris, model=ipredknn, estimator="cv", est.para=control.errorest(k=cv.k), predict=bwpredict.knn, nk = i)$err print(a) } [1] 0.02666667 [1] 0.02666667 [1] 0.02666667 [1] 0.02666667 [1] 0.02666667 [1] 0.02666667 [1] 0.02666667 [1] 0.02666667 [1] 0.02666667 [1] 0.02666667 [1] 0.02666667 [1] 0.02666667 [1] 0.02666667 ############################################# I think its is because in "ipredknn" and "control.errorest" has the same variable "k" (I guess k=5 default in ipredknn is returning). If I use errorest(Species ~ ., data=iris, model=ipredknn, estimator="cv", est.para=control.errorest(k=cv.k), predict=bwpredict.knn, k = 1) the following message is generated: Error in cv.factor(y, formula, data, model = model, predict = predict, : formal argument "k" matched by multiple actual arguments I can't seem to change "k" to "nk" in "ipredknn". If I try ipred::ipredknn <- function (formula, data, subset, na.action, nk = 5, ...){.......} I get the message- Error in ipred::ipredknn <- function(formula, data, subset, na.action, : object "ipred" not found How can I fix that? Any suggestion would be greatly appreciated. Thanks in advance, - mek R.Version() $platform "i386-pc-mingw32" $arch "i386" $os "mingw32" $system "i386, mingw32" $status "" $major "2" $minor "8.1" $year "2008" $month "12" $day "22" $`svn rev` "47281" $language "R" $version.string "R version 2.8.1 (2008-12-22)"
Uwe Ligges
2009-Apr-26 14:43 UTC
[R] Overlapping parameters "k" in different functions in "ipred"
WilDsc0p wrote:> Dear List, > > I have a question regarding "ipred" package. Under 10-fold cv, for different knn ( = 1,3,...25), I am getting same misclassification errors: > ############################################# > library(ipred) > data(iris) > cv.k = 10 ## 10-fold cross-validation > bwpredict.knn <- function(object, newdata) predict.ipredknn(object, newdata, type="class") > for (i in seq(1,25,2)){ > set.seed(19) > a<-errorest(Species ~ ., data=iris, model=ipredknn, estimator="cv", est.para=control.errorest(k=cv.k), predict=bwpredict.knn, nk = i)$err > print(a) > } > [1] 0.02666667 > [1] 0.02666667 > [1] 0.02666667 > [1] 0.02666667 > [1] 0.02666667 > [1] 0.02666667 > [1] 0.02666667 > [1] 0.02666667 > [1] 0.02666667 > [1] 0.02666667 > [1] 0.02666667 > [1] 0.02666667 > [1] 0.02666667 > ############################################# > I think its is because in "ipredknn" and "control.errorest" has the same variable "k" (I guess k=5 default in ipredknn is returning). If I useNo, but because you are resetting the seed of the random number generator to the same value in each iteration of your loop.> > errorest(Species ~ ., data=iris, model=ipredknn, estimator="cv", est.para=control.errorest(k=cv.k), predict=bwpredict.knn, k = 1) > > the following message is generated: > Error in cv.factor(y, formula, data, model = model, predict = predict, : > formal argument "k" matched by multiple actual arguments > > I can't seem to change "k" to "nk" in "ipredknn". If I try > ipred::ipredknn <- function (formula, data, subset, na.action, nk = 5, ...){.......} > I get the message- > Error in ipred::ipredknn <- function(formula, data, subset, na.action, : > object "ipred" not found > > How can I fix that? Any suggestion would be greatly appreciated.You don't need (see above), but you can with assignInNamespace() and friends, see ?assignInNamespace. Uwe Ligges> Thanks in advance, > > > - mek > > R.Version() $platform "i386-pc-mingw32" $arch "i386" $os "mingw32" $system "i386, mingw32" $status "" $major "2" $minor "8.1" $year "2008" $month "12" $day "22" $`svn rev` "47281" $language "R" $version.string "R version 2.8.1 (2008-12-22)" > > ______________________________________________ > 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.