binaryRatingMatrix-class: Class "binaryRatingMatrix": A Binary Rating Matrix

binaryRatingMatrixR Documentation

Class "binaryRatingMatrix": A Binary Rating Matrix

Description

A matrix to represent binary rating data. 1 codes for a positive rating and 0 codes for either no or a negative rating. This coding is common for market basked data where products are either bought or not.

Objects from the Class

Objects can be created by calls of the form new("binaryRatingMatrix", data = im), where im is an itemMatrix as defined in package arules, by coercion from a matrix (all non-zero values will be a 1), or by using binarize for an object of class "realRatingMatrix".

Slots

data:

Object of class "itemMatrix" (see package arules)

Extends

Class "ratingMatrix", directly.

Methods

coerce

signature(from = "matrix", to = "binaryRatingMatrix"): The matrix needs to be a logical matrix, or a 0-1 matrix (0 means FALSE and 1 means TRUE). NAs are interpreted as FALSE.

coerce

signature(from = "itemMatrix", to = "binaryRatingMatrix")

coerce

signature(from = "data.frame", to = "binaryRatingMatrix")

coerce

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

coerce

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

coerce

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

coerce

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

coerce

signature(from = "binaryRatingMatrix", to = "itemMatrix")

coerce

signature(from = "binaryRatingMatrix", to = "list")

See Also

itemMatrix in arules, getList.

Examples

## create a 0-1 matrix
m <- matrix(sample(c(0,1), 50, replace=TRUE), nrow=5, ncol=10,
    dimnames=list(users=paste("u", 1:5, sep=''),
    items=paste("i", 1:10, sep='')))
m

## coerce it into a binaryRatingMatrix
b <- as(m, "binaryRatingMatrix")
b

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

## use some methods defined in ratingMatrix
dim(b)
dimnames(b)

## counts
rowCounts(b) ## number of ratings per user
colCounts(b) ## number of ratings per item

## plot
image(b)

## sample and subset
sample(b,2)
b[1:2,1:5]

## coercion
as(b, "list")
head(as(b, "data.frame"))
head(getData.frame(b, ratings=FALSE))

## creation from user/item tuples
df <- data.frame(user=c(1,1,2,2,2,3), items=c(1,4,1,2,3,5))
df
b2 <- as(df, "binaryRatingMatrix")
b2
as(b2, "matrix")

recommenderlab documentation built on Sept. 20, 2023, 9:06 a.m.