Learn R Programming

recommenderlab (version 1.0.6)

predict: Predict Recommendations

Description

Creates recommendations using a recommender model and data about new users.

Usage

# S4 method for Recommender
predict(object, newdata, n = 10, data=NULL,
    type="topNList", ...)

Value

Returns an object of class "topNList" or of other appropriate classes.

Arguments

object

a recommender model (class "Recommender").

newdata

data for active users (class "ratingMatrix") or the index of users in the training data to create recommendations for. If an index is used then some recommender algorithms need to be passed the training data as argument data. Some algorithms may only support user indices.

n

number of recommendations in the top-N list.

data

training data needed by some recommender algorithms if newdata is a user index and not user data.

type

type of recommendation. The default type is "topNList" which creates a top-N recommendation list with recommendations. Some recommenders can also predict ratings with type "ratings" which returns only predicted ratings with known ratings represented by NA, or type "ratingMatrix" which returns a completed rating matrix (Note that the predicted ratings may differ from the known ratings).

...

further arguments.

See Also

Recommender, ratingMatrix.

Examples

Run this code
data("MovieLense")
MovieLense100 <- MovieLense[rowCounts(MovieLense) >100,]
train <- MovieLense100[1:50]

rec <- Recommender(train, method = "POPULAR")
rec

## create top-N recommendations for new users
pre <- predict(rec, MovieLense100[101:102], n = 10)
pre
as(pre, "list")

## predict ratings for new users
pre <- predict(rec, MovieLense100[101:102], type="ratings")
pre
as(pre, "matrix")[,1:10]


## create recommendations using user ids with ids 1..10 in the
## training data
pre <- predict(rec, 1:10 , data = train, n = 10)
pre
as(pre, "list")

Run the code above in your browser using DataLab