Dear R-experts, I am trying to find the best span for my loess regression. Here below a reproducible example. I don't get the result. Am I missing something ? Many thanks for your help. ############################################################ a<-c(2,3,4,3,2,6,5,7,4,5,12,13,21,6,4,5,6,7) b<-c(12,13,32,14,23,21,76,34,12,32,43,23,12,32,43,12,32,11) model <- loess(b ~ a) bestLoess <- function(model, spans = c(.05, .95)) { ?f <- function(span) { ???????? mod <- update(model, span = span) ???????? loessGCV(mod)[["gcv"]] ???? } ???? result <- optimize(f, spans) ???? result ?} #######################################################################
On Tue, 14 Apr 2020 21:00:34 +0000 (UTC) varin sacha via R-help <r-help at r-project.org> wrote:> Here below a reproducible example. I don't get the result.Thanks for providing a concise piece of code. The code doesn't return any visible results because the bestLoess function created by it is never called. To get the results you should call the function and pass the model object to it as an argument. Another problem with the code is missing definition for loessGCV function. I can only assume that the code is supposed to reference the recently archived NormalizeMets CRAN package. -- Best regards, Ivan
Dear Ivan, Many thanks I got it now. Best, Le mercredi 15 avril 2020 ? 09:49:26 UTC+2, Ivan Krylov <krylov.r00t at gmail.com> a ?crit : On Tue, 14 Apr 2020 21:00:34 +0000 (UTC) varin sacha via R-help <r-help at r-project.org> wrote:> Here below a reproducible example. I don't get the result.Thanks for providing a concise piece of code. The code doesn't return any visible results because the bestLoess function created by it is never called. To get the results you should call the function and pass the model object to it as an argument. Another problem with the code is missing definition for loessGCV function. I can only assume that the code is supposed to reference the recently archived NormalizeMets CRAN package. -- Best regards, Ivan
Tom Woolman
2020-Jun-10 22:49 UTC
[R] kernlab ksvm rbfdot kernel - prediction returning fewer rows than provided for input
Hi everyone. I'm using the kernlab ksvm function with the rbfdot kernel for a binary classification problem and getting a strange result back. The predictions seem to be very accurate judging by the training results provided by the algorithm, but I'm unable to generate a confusion matrix because there is a difference in the number of output records from my model test compared to what was input into the test dataframe. I've used ksvm before but never had this problem. Here's my sample code: install.packages("kernlab") library(kernlab) set.seed(3233) trainIndex <- caret::createDataPartition(dataset_labeled_fraud$isFraud, p=0.70,kist=FALSE) train <- dataset_labeled_fraud[trainIndex,] test <- dataset_labeled_fraud[-trainIndex,] #clear out the training model filter <- NULL filter <- kernlab::ksvm(isFraud~.,data=train,kernel="rbfdot",kpar=list(sigma=0.5),C=3,prob.model=TRUE) #clear out the test results test_pred_rbfdot <- NULL test_pred_rbfdot <- kernlab::predict(filter,test,type="probabilities") dataframe_test_pred_rbfdot <- as.data.frame(test_pred_rbfdot) nrow(dataframe_test_pred_rbfdot)> 23300nrow(test)> 24408# ok, how did I go from 24408 input rows to only 23300 output prediction rows? :( Thanks in advance anyone! Thomas A. Woolman PhD Candidate, Technology Management Indiana State University
Tom Woolman
2020-Jun-10 22:51 UTC
[R] kernlab ksvm rbfdot kernel - prediction returning fewer rows than provided for input
forgot to mention, the training and testing dataframes are composed of 4 IVs (one double numeric IV and three factor IVs) and one DV (dichotomous factor, i.e. true or false). The training dataframe consists of 48819 rows and test dataframe consists of 24408 rows. Thanks again. Quoting Tom Woolman <twoolman at ontargettek.com>:> Hi everyone. I'm using the kernlab ksvm function with the rbfdot > kernel for a binary classification problem and getting a strange > result back. The predictions seem to be very accurate judging by the > training results provided by the algorithm, but I'm unable to > generate a confusion matrix because there is a difference in the > number of output records from my model test compared to what was > input into the test dataframe. > > I've used ksvm before but never had this problem. > > Here's my sample code: > > > > install.packages("kernlab") > library(kernlab) > > > set.seed(3233) > > > trainIndex <- > caret::createDataPartition(dataset_labeled_fraud$isFraud, > p=0.70,kist=FALSE) > > train <- dataset_labeled_fraud[trainIndex,] > test <- dataset_labeled_fraud[-trainIndex,] > > > #clear out the training model > filter <- NULL > > filter <- > kernlab::ksvm(isFraud~.,data=train,kernel="rbfdot",kpar=list(sigma=0.5),C=3,prob.model=TRUE) > > > #clear out the test results > test_pred_rbfdot <- NULL > > test_pred_rbfdot <- kernlab::predict(filter,test,type="probabilities") > > dataframe_test_pred_rbfdot <- as.data.frame(test_pred_rbfdot) > > > nrow(dataframe_test_pred_rbfdot) > >> 23300 > > nrow(test) > >> 24408 > > > # ok, how did I go from 24408 input rows to only 23300 output > prediction rows? :( > > > Thanks in advance anyone! > > > > > Thomas A. Woolman > PhD Candidate, Technology Management > Indiana State University