Learn R Programming

recommenderlab (version 0.1-4)

calcPredictionError: Calculate the Prediction Error for a Recommendation

Description

Calculates MAE (mean average error), MSE (means squared error) and RMSE (root means squared error) for predicted ratings given the actual ratings by the user.

Usage

calcPredictionError(x, data, ...)
## S3 method for class 'realRatingMatrix,realRatingMatrix':
calcPredictionError(x, data, byUser=FALSE)

Arguments

x
Predicted ratings as a "realRatingMatrix"
data
Actual ratings by the user as a "realRatingMatrix"
byUser
logical; Should the errors be averaged by user or over all recommendations?
...
further arguments.

Value

  • Returns a matrix with columns for the different error measures. For byUser=TRUE each user is a row in the matrix, otherwise the matrix has only a single row with the global averages.

See Also

realRatingMatrix.

Examples

Run this code
data(Jester5k)

## create 90/10 split (known/unknown) for the first 500 users in Jester5k
e <- evaluationScheme(Jester5k[1:500], method="split", train=0.9, 
    k=1, given=15, goodRating=5)
e

## create a user-based CF recommender using training data
r <- Recommender(getData(e, "train"), "UBCF")

## create predictions for the test data using known ratings (see given above)
p <- predict(r, getData(e, "known"), type="ratings")
p

## compute error metrics averaged per user and then averaged over all 
## recommendations
calcPredictionError(p, getData(e, "unknown"))
calcPredictionError(p, getData(e, "unknown"), byUser=TRUE)

Run the code above in your browser using DataLab