CC This work is licensed under the Creative Commons Attribution 4.0 International License. For questions please contact Michael Hahsler.

library("recommenderlab")
## Loading required package: Matrix
## Loading required package: arules
## 
## Attaching package: 'arules'
## 
## The following objects are masked from 'package:base':
## 
##     abbreviate, write
## 
## Loading required package: proxy
## 
## Attaching package: 'proxy'
## 
## The following object is masked from 'package:Matrix':
## 
##     as.matrix
## 
## The following objects are masked from 'package:stats':
## 
##     as.dist, dist
## 
## The following object is masked from 'package:base':
## 
##     as.matrix
## 
## Loading required package: registry
data("Jester5k")
Jester5k
## 5000 x 100 rating matrix of class 'realRatingMatrix' with 362106 ratings.
Jester5k_norm <- normalize(Jester5k)

Bester Average Rating

Better jokes receive on average better ratings. Note: Items are in columns.

score <- colMeans(Jester5k_norm)
hist(score)

sort(score, decreasing = TRUE)
##          j50          j89          j36          j32          j27 
##  2.714767826  2.547600665  2.452554813  2.354357144  2.237205867 
##          j35          j53          j29          j62          j49 
##  2.150025145  2.129366464  2.089049584  2.031432740  1.929929445 
##          j54          j72          j68          j69          j66 
##  1.912800400  1.889886528  1.732781073  1.682309164  1.627968461 
##          j61          j93          j65          j76          j21 
##  1.571854654  1.508163094  1.442041313  1.427697641  1.309257508 
##          j31          j42          j88          j83          j91 
##  1.284286765  1.105314927  1.063002899  1.033907292  1.023882123 
##          j48          j56           j6          j11          j87 
##  0.966723680  0.923982810  0.866565799  0.840540309  0.805942692 
##          j81          j47          j28          j14          j78 
##  0.767171756  0.707352833  0.685164065  0.667652933  0.662420635 
##          j97          j46          j12          j26          j96 
##  0.613855951  0.610759262  0.606668279  0.446323982  0.445029547 
##          j10          j38         j100          j39          j92 
##  0.430361580  0.333256728  0.299368465  0.260343550  0.253690681 
##           j1          j45          j34          j40          j73 
##  0.233348866  0.169236666  0.147078920  0.103482342  0.099733238 
##          j22          j80          j82          j94          j95 
##  0.069292633  0.017110124  0.000886657 -0.023300146 -0.037227703 
##          j85          j98          j84          j70          j77 
## -0.081998260 -0.128241164 -0.263353408 -0.321165425 -0.362985152 
##          j25          j55           j2           j3          j90 
## -0.391709154 -0.400211437 -0.466244194 -0.477809821 -0.514080254 
##           j5          j63          j23          j19          j86 
## -0.529551873 -0.580188273 -0.619976012 -0.727085958 -0.728784176 
##          j52          j79          j99          j41          j60 
## -0.827426470 -0.961060183 -1.078072900 -1.116846429 -1.230324480 
##          j75          j30          j59           j7           j8 
## -1.259575396 -1.277344026 -1.386463195 -1.398752919 -1.412783958 
##          j64          j51           j9          j18          j67 
## -1.471400975 -1.473382369 -1.499654917 -1.621487958 -1.650091382 
##          j71          j43          j20          j17           j4 
## -1.651649449 -1.656143190 -1.842633958 -1.890251958 -2.227781301 
##          j37          j33          j24          j74          j13 
## -2.246134591 -2.260529829 -2.428174930 -2.546425675 -2.602059958 
##          j15          j57          j44          j16          j58 
## -2.637885958 -2.961409862 -3.071882967 -3.987152535 -4.678220267

Three jokes with the highest average rating.

cat(JesterJokes[head(order(score, decreasing = TRUE), 3)], sep = "\n\n")
## A guy goes into confession and says to the priest, "Father, I'm 80 years old, widower, with 11 grandchildren. Last night I met two beautiful flight attendants. They took me home and I made love to both of them. Twice." The priest said: "Well, my son, when was the last time you were in confession?" "Never Father, I'm Jewish." "So then, why are you telling me?" "I'm telling everybody."
## 
## A radio conversation of a US naval ship with Canadian authorities ... Americans: Please divert your course 15 degrees to the North to avoid a collision. Canadians: Recommend you divert YOUR course 15 degrees to the South to avoid a collision. Americans: This is the Captain of a US Navy ship. I say again, divert YOUR course. Canadians: No. I say again, you divert YOUR course. Americans: This is the aircraft carrier USS LINCOLN, the second largest ship in the United States' Atlantic Fleet. We are accompanied by three destroyers, three cruisers and numerous support vessels. I demand that you change your course 15 degrees north, that's ONE FIVE DEGREES NORTH, or counter-measures will be undertaken to ensure the safety of this ship. Canadians: This is a lighthouse. Your call.
## 
## A guy walks into a bar, orders a beer and says to the bartender, "Hey, I got this great Polish Joke..." The barkeep glares at him and says in a warning tone of voice: "Before you go telling that joke you better know that I'm Polish, both bouncers are Polish and so are most of my customers" "Okay" says the customer,"I'll tell it very slowly."

Most Often Rated Items

More popular items are known to more people and receive more ratings.

score <- colCounts(Jester5k_norm)
hist(score)

cat(JesterJokes[head(order(score, decreasing = TRUE), 3)], sep = "\n\n")
## Q. Did you hear about the dyslexic devil worshiper? A. He sold his soul to Santa.
## 
## They asked the Japanese visitor if they have elections in his country. "Every Morning" he answers.
## 
## Q: What did the blind person say when given some matzah? A: Who the hell wrote this?

Combination

How often was a joke rated better than +5?

score <- colCounts(binarize(Jester5k_norm, minRating = 5))
hist(score)

cat(JesterJokes[head(order(score, decreasing = TRUE), 3)], sep = "\n\n")
## A guy goes into confession and says to the priest, "Father, I'm 80 years old, widower, with 11 grandchildren. Last night I met two beautiful flight attendants. They took me home and I made love to both of them. Twice." The priest said: "Well, my son, when was the last time you were in confession?" "Never Father, I'm Jewish." "So then, why are you telling me?" "I'm telling everybody."
## 
## An old Scotsmen is sitting with a younger Scottish gentleman and says the boy. "Ah, lad look out that window. You see that stone wall there, I built it with me own bare hands, placed every stone meself. But do they call me MacGregor the wall builder? No! He Takes a few sips of his beer then says, "Aye, and look out on that lake and eye that beautiful pier. I built it meself, laid every board and hammered each nail but do they call me MacGregor the pier builder? No! He continues..."And lad, you see that road? That too I build with me own bare hands. Laid every inch of pavement meself, but do they call MacGregor the road builder? No!" Again he returns to his beer for a few sips, then says, "Agh, but you screw one sheep..."
## 
## A man arrives at the gates of heaven. St. Peter asks, "Religion?" The man says, "Methodist." St. Peter looks down his list, and says, "Go to room 24, but be very quiet as you pass room 8." Another man arrives at the gates of heaven. "Religion?" "Baptist." "Go to room 18, but be very quiet as you pass room 8." A third man arrives at the gates. "Religion?" "Jewish." "Go to room 11, but be very quiet as you pass room 8." The man says, "I can understand there being different rooms for different religions, but why must I be quiet when I pass room 8?" St. Peter tells him, "Well the Catholics are in room 8, and they think they're the only ones here.

How often is a joke in the top 1% for a user?

score <- colCounts(binarize(normalize(Jester5k, method="Z-score"),
  minRating = 2.2))
hist(score)

cat(JesterJokes[head(order(score, decreasing = TRUE), 3)], sep = "\n\n")
## An old Scotsmen is sitting with a younger Scottish gentleman and says the boy. "Ah, lad look out that window. You see that stone wall there, I built it with me own bare hands, placed every stone meself. But do they call me MacGregor the wall builder? No! He Takes a few sips of his beer then says, "Aye, and look out on that lake and eye that beautiful pier. I built it meself, laid every board and hammered each nail but do they call me MacGregor the pier builder? No! He continues..."And lad, you see that road? That too I build with me own bare hands. Laid every inch of pavement meself, but do they call MacGregor the road builder? No!" Again he returns to his beer for a few sips, then says, "Agh, but you screw one sheep..."
## 
## A guy goes into confession and says to the priest, "Father, I'm 80 years old, widower, with 11 grandchildren. Last night I met two beautiful flight attendants. They took me home and I made love to both of them. Twice." The priest said: "Well, my son, when was the last time you were in confession?" "Never Father, I'm Jewish." "So then, why are you telling me?" "I'm telling everybody."
## 
## Clinton returns from a vacation in Arkansas and walks down the steps of Air Force One with two pigs under his arms. At the bottom of the steps, he says to the honor guardsman, "These are genuine Arkansas Razor-Back Hogs. I got this one for Chelsea and this one for Hillary." The guardsman replies, "Nice trade, Sir."

Non-personalized recommender using recommenderlab

library(recommenderlab)
data("Jester5k")

recommenderRegistry$get_entry("POPULAR", type ="realRatingMatrix")
## Recommender method: POPULAR
## Description: Recommender based on item popularity (real data).
## Parameters: None
recom <- Recommender(Jester5k, method = "POPULAR")
recom
## Recommender of type 'POPULAR' for 'realRatingMatrix' 
## learned using 5000 users.
pred <- predict(recom, Jester5k[1:5,])
as(pred, "list")
## $u2841
##  [1] "j89" "j72" "j76" "j88" "j83" "j87" "j81" "j78" "j73" "j80"
## 
## $u15547
##  [1] "j89" "j93" "j76" "j88" "j91" "j83" "j87" "j81" "j97" "j78"
## 
## $u15221
## character(0)
## 
## $u15573
## character(0)
## 
## $u21505
##  [1] "j89" "j72" "j93" "j76" "j88" "j91" "j83" "j87" "j81" "j97"
pred2 <- predict(recom, Jester5k[1:5,], type = "ratings")
as(pred2, "matrix")
##      j1 j2 j3 j4 j5 j6 j7 j8 j9 j10 j11 j12 j13 j14 j15 j16 j17 j18 j19
## [1,] NA NA NA NA NA NA NA NA NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA
## [2,] NA NA NA NA NA NA NA NA NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA
## [3,] NA NA NA NA NA NA NA NA NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA
## [4,] NA NA NA NA NA NA NA NA NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA
## [5,] NA NA NA NA NA NA NA NA NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA
##      j20 j21 j22 j23 j24 j25 j26 j27 j28 j29 j30 j31 j32 j33 j34 j35 j36
## [1,]  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA
## [2,]  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA
## [3,]  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA
## [4,]  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA
## [5,]  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA
##      j37 j38 j39 j40 j41 j42 j43 j44 j45 j46 j47 j48 j49 j50 j51 j52 j53
## [1,]  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA
## [2,]  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA
## [3,]  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA
## [4,]  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA
## [5,]  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA
##      j54 j55 j56 j57       j58 j59 j60 j61 j62 j63 j64 j65 j66 j67 j68 j69
## [1,]  NA  NA  NA  NA        NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA
## [2,]  NA  NA  NA  NA -7.460192  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA
## [3,]  NA  NA  NA  NA        NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA
## [4,]  NA  NA  NA  NA        NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA
## [5,]  NA  NA  NA  NA        NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA
##      j70        j71      j72       j73       j74        j75       j76
## [1,]  NA  2.2035357 5.745072  3.954918  1.308760  2.5956098  5.282883
## [2,]  NA -4.4336213       NA -2.682239 -5.328398 -4.0415472 -1.354274
## [3,]  NA         NA       NA        NA        NA         NA        NA
## [4,]  NA         NA       NA        NA        NA         NA        NA
## [5,]  NA -0.4948439 3.046692  1.256539 -1.389620 -0.1027698  2.584503
##            j77       j78       j79       j80       j81       j82       j83
## [1,]        NA  4.517606  2.894125  3.872295  4.622357  3.856072  4.889092
## [2,]        NA -2.119551 -3.743032 -2.764862 -2.014800 -2.781085 -1.748065
## [3,]        NA        NA        NA        NA        NA        NA        NA
## [4,]        NA        NA        NA        NA        NA        NA        NA
## [5,] 0.7938204  1.819226        NA  1.173916  1.923977  1.157692  2.190713
##            j84       j85        j86       j87       j88        j89
## [1,]  3.591832  3.773187  3.1264010  4.661128  4.918188  6.4027859
## [2,] -3.045325 -2.863970 -3.5107560 -1.976029 -1.718969 -0.2343712
## [3,]        NA        NA         NA        NA        NA         NA
## [4,]        NA        NA         NA        NA        NA         NA
## [5,]        NA  1.074807  0.4280214  1.962748  2.219808  3.7044062
##             j90       j91       j92       j93       j94       j95
## [1,]  3.3411049        NA        NA        NA        NA        NA
## [2,] -3.2960521 -1.758090 -2.528281 -1.273809 -2.805272 -2.819200
## [3,]         NA        NA        NA        NA        NA        NA
## [4,]         NA        NA        NA        NA        NA        NA
## [5,]  0.6427253  2.180688  1.410496  2.664969  1.133505  1.119578
##            j96       j97       j98         j99      j100
## [1,]        NA        NA        NA          NA        NA
## [2,] -2.336942 -2.168116 -2.910213 -3.86004473 -2.482603
## [3,]        NA        NA        NA          NA        NA
## [4,]        NA        NA        NA          NA        NA
## [5,]  1.601835  1.770662  1.028564  0.07873266  1.456174