[R] kernlab ksvm rbfdot kernel - prediction returning fewer rows than provided for input

Tom Woolman twoo|m@n @end|ng |rom ont@rgettek@com
Thu Jun 11 00:51:01 CEST 2020


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



More information about the R-help mailing list