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

Description Objects from the Class Slots Extends Methods See Also Examples

Description

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

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")

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.

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
## 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)
colCounts(r)
rowMeans(r)


## 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")

audachang/recommenderlab.test documentation built on May 20, 2019, 1:27 p.m.