-
Notifications
You must be signed in to change notification settings - Fork 0
/
IBCF.Rmd
51 lines (38 loc) · 1.08 KB
/
IBCF.Rmd
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
40
41
42
43
44
45
46
47
48
49
50
51
---
title: "Item Based Collabrative Filtering"
author: "Vijay S"
date: "22 May 2018"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
library(reshape2)
library(recommenderlab)
library(dplyr)
```
```{r}
movies = read.csv("movies.csv")
rating = read.csv("ratings.csv")
length(unique(rating$userId)) # Totally 671 users
length(unique(rating$movieId)) # Totally 9066 movies
ratings_matrix = as.matrix(dcast(data = rating, movieId~userId, value.var = 'rating'))
ranking_matrix = as(ratings_matrix[,-1], 'realRatingMatrix')
ubcf = Recommender(ranking_matrix, method = 'IBCF', param = list(method = 'Cosine', nn = 10))
result = predict(ubcf, ranking_matrix[1, ], n = 5)
movies_sugg = as(result, "list")[[1]]
movies %>% filter(movieId %in% movies_sugg) %>% select(title)
```
```{r}
data("Jester5k")
Jester5k
```
```{r}
class(Jester5k)
```
```{r}
ibcf = Recommender(Jester5k, method = "IBCF", parameter = list(method = "Cosine", k = 10))
pred = predict(ibcf, Jester5k[1], n = 5)
as(pred, 'list')
```