learning-it by example

#195 Machine learning and data science 6.3 min

Recommender From Scratch: Watch 24 Films Find Their Genres

A program learned three numbers for each of 24 made-up films, and films of one genre ended up together in 3D.

1. In the matrix factorisation built in the video, how is one star rating guessed?
2. Guessing the average of 3.19 stars for every film gave a test error of 1.28. Where did the test error settle after training for 60 epochs?
3. Why is it a mistake to judge this model on the ratings it learned from?
4. Across all 60 people, how many of the 180 top-three picks came from the person's favourite genre?
5. What is the cold start problem for a model like this one?
6. What does the pull toward zero (the penalty on big numbers) do in training?

Practice only: nothing is saved and no score counts towards anything. Each answer comes with the reason.

  1. Recommend for a different person

    Copy the code folder first. Run python run.py recommend. Then in run.py change favourite[3] to favourite[4], top_three(3) to top_three(4), and the words person 3 in the print to person 4, and run it again. You should see that person 4 likes romance and the top three unseen films are Second Orchard, Quiet Goodbyes and Lantern Post.

    A hint

    There are three small edits, all in the last block of run.py.

  2. Turn off the penalty

    In run.py change the train call to train(ratings, 60, len(FILMS), reg=0.0, on_epoch=record) and run python run.py train. Predict first whether the test error at epoch 60 will be lower or higher than 0.78. You should see the training error fall to 0.41 while the test error ends at 0.93.

    A hint

    reg is the pull toward zero on every number.

  3. Use one number instead of three

    In run.py change the train call to train(ratings, 60, len(FILMS), k=1, on_epoch=record). Run python run.py train and then python run.py recommend. You should see the test error end at 1.14, the top three films for person 3 turn into romance films, and the favourite-genre count drop to 99 of 180.

    A hint

    k is how many numbers each person and each film gets. The video used 3 so it could draw them.

  4. Take a much bigger step

    In run.py change the train call to train(ratings, 60, len(FILMS), lr=0.2, on_epoch=record) and run python run.py train. The learning rate was 0.02. You should see that training does not settle: the training error stays near 0.6 instead of reaching 0.46, and the test error moves between 0.77 and 0.90 across the printed epochs.

    A hint

    lr is the size of each nudge.

These tasks are for you to try on your own machine. Nothing is checked or saved.

What this does not show

Made-up ratings with genres built in, so the result is easy: 60 people, 24 films, three factors chosen for the picture, 120 test ratings from one split. No real ratings file, no alternating least squares, no implicit feedback, no cold start. The 3D picture is drawn from the real numbers of this run.

Up next in Machine learning and data science

More in Machine learning and data science

All Machine learning and data science videos

Related videos