Error in sample.int(length(x), size, replace, prob) : invalid 'size' argument ; when i using evaluationScheme

5.9k Views Asked by At

I would like to evaluate my model with the function of the package Recommenderlab

scheme <- evaluationScheme(UserByProductRRM, method = "cross-validation", k = 10, given =-1 , goodRating = 4)

but I don't understand why I have this error

Error in sample.int(length(x), size, replace, prob) : invalid 'size' argument

2

There are 2 best solutions below

0
On

The reason for this error seems to be that the dimensions of the sample fraction you want to extract from the data set cannot be calculated. That is, the value of the "size" parameter you specified cannot be calculated. Therefore, I suggest you try to see the "size" parameter from the console. The "evaluationScheme" function refers to the sample function. Sample function cannot calculate "size". An example of this is the following.

library(tidytext)
library(tidyverse)
library(dplyr)
data("iris")
df_iris<-as.data.frame(iris)
train<-sample(1:nrow(df_iris),0.60*nrow(df))
nrow(df)

Console:

 > train<-sample(1:nrow(df_iris),0.60*nrow(df))
    Error in sample.int(length(x), size, replace, prob) : 
      invalid 'size' argument
    > nrow(df)
    NULL

There is nothing called "df" that can be calculated and passed to the "size" parameter. The calculation could not be done and the "size" parameter was missing. This caused an error.

0
On

Perhaps your dataset (UserByProductRRM) has lines with only 0s. You must delete those lines. In RealRatingMatrix or BinaryRatingMatrix all lines must have at least one 1. Try rowSums function to detect lines with only 0s.