Learn R Programming

recommenderlab (version 1.0.6)

realRatingMatrix: Class "realRatingMatrix": Real-valued Rating Matrix

Description

A matrix containing ratings (typically 1-5 stars, etc.).

Arguments

Objects from the Class

Objects can be created by calls of the form new("realRatingMatrix", data = m), where m is sparse matrix of class dgCMatrix in package Matrix or by coercion from a regular matrix, a data.frame containing user/item/rating triplets as rows, or a sparse matrix in triplet form (dgTMatrix in package Matrix).

Slots

data:

Object of class "dgCMatrix", a sparse matrix defined in package Matrix. Note that this matrix drops NAs instead of zeroes. Operations on "dgCMatrix" potentially will delete zeroes.

normalize:

NULL or a list with normalizaton factors.

Extends

Class "ratingMatrix", directly.

Methods

coerce

signature(from = "matrix", to = "realRatingMatrix"): Note that unknown ratings have to be encoded in the matrix as NA and not as 0 (which would mean an actual rating of 0).

coerce

signature(from = "realRatingMatrix", to = "matrix")

coerce

signature(from = "data.frame", to = "realRatingMatrix"): coercion from a data.frame with three columns. Col 1 contains user ids, col 2 contains item ids and col 3 contains ratings.

coerce

signature(from = "realRatingMatrix", to = "data.frame"): produces user/item/rating triplets.

coerce

signature(from = "realRatingMatrix", to = "dgTMatrix")

coerce

signature(from = "dgTMatrix", to = "realRatingMatrix")

coerce

signature(from = "realRatingMatrix", to = "dgCMatrix")

coerce

signature(from = "dgCMatrix", to = "realRatingMatrix")

coerce

signature(from = "realRatingMatrix", to = "ngCMatrix")

binarize

signature(x = "realRatingMatrix"): create a "binaryRatingMatrix" by setting all ratings larger or equal to the argument minRating as 1 and all others to 0.

getTopNLists

signature(x = "realRatingMatrix"): create top-N lists from the ratings in x. Arguments are n (defaults to 10), randomize (default is NULL) and minRating (default is NA). Items with a rating below minRating will not be part of the top-N list. randomize can be used to get diversity in the predictions by randomly selecting items with a bias to higher rated items. The bias is introduced by choosing the items with a probability proportional to the rating \((r-min(r)+1)^{randomize}\). The larger the value the more likely it is to get very highly rated items and a negative value for randomize will select low-rated items.

removeKnownRatings

signature(x = "realRatingMatrix"): removes all ratings in x for which ratings are available in the realRatingMatrix (of same dimensions as x) passed as the argument known.

rowSds

signature(x = "realRatingMatrix"): calculate the standard deviation of ratings for rows (users).

colSds

signature(x = "realRatingMatrix"): calculate the standard deviation of ratings for columns (items).

See Also

See ratingMatrix inherited methods, binaryRatingMatrix, topNList, getList and getData.frame. Also see dgCMatrix, dgTMatrix and ngCMatrix in Matrix.

Examples

Run this code
## create a matrix with ratings
m <- matrix(sample(c(NA,0:5),100, replace=TRUE, prob=c(.7,rep(.3/6,6))),
	nrow=10, ncol=10, dimnames = list(
	    user=paste('u', 1:10, sep=''),
	    item=paste('i', 1:10, sep='')
    ))
m

## coerce into a realRatingMAtrix
r <- as(m, "realRatingMatrix")
r

## get some information
dimnames(r)
rowCounts(r) ## number of ratings per user
colCounts(r) ## number of ratings per item
colMeans(r) ## average item rating
nratings(r) ## total number of ratings
hasRating(r) ## user-item combinations with ratings

## histogram of ratings
hist(getRatings(r), breaks="FD")

## inspect a subset
image(r[1:5,1:5])

## coerce it back to see if it worked
as(r, "matrix")

## coerce to data.frame (user/item/rating triplets)
as(r, "data.frame")

## binarize into a binaryRatingMatrix with all 4+ rating a 1
b <- binarize(r, minRating=4)
b
as(b, "matrix")

Run the code above in your browser using DataLab