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

Description Objects from the Class Slots Extends Methods See Also Examples

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

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

 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
36
37
38
39
## 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)
colCounts(b)

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

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