realRatingMatrix | R Documentation |
A matrix containing ratings (typically 1-5 stars, etc.).
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).
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.
Class "ratingMatrix"
, directly.
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).
signature(from = "realRatingMatrix", to = "matrix")
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.
signature(from = "realRatingMatrix", to = "data.frame")
: produces user/item/rating triplets.
signature(from = "realRatingMatrix", to = "dgTMatrix")
signature(from = "dgTMatrix", to = "realRatingMatrix")
signature(from = "realRatingMatrix", to = "dgCMatrix")
signature(from = "dgCMatrix", to = "realRatingMatrix")
signature(from = "realRatingMatrix", to = "ngCMatrix")
signature(x = "realRatingMatrix")
: create a
"binaryRatingMatrix"
by setting all ratings larger or equal to
the argument minRating
as 1 and all others to 0.
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.
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
.
signature(x = "realRatingMatrix")
: calculate
the standard deviation of ratings for rows (users).
signature(x = "realRatingMatrix")
: calculate
the standard deviation of ratings for columns (items).
See ratingMatrix
inherited methods,
binaryRatingMatrix
,
topNList
,
getList
and getData.frame
.
Also see dgCMatrix
,
dgTMatrix
and
ngCMatrix
ngCMatrix
in Matrix.
## 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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.