fatma BEN MAKHLOUF
fatma BEN MAKHLOUF

Reputation: 21

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

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

Upvotes: 1

Views: 6349

Answers (2)

NCC1701
NCC1701

Reputation: 149

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.

Upvotes: 0

agfac
agfac

Reputation: 183

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.

Upvotes: 0

Related Questions