This project will focus on Movies, in particular understanding what drives audience ratings and helping users categorise films into genres based on their features.As the world rapidly evolves into a ever-growing digital world, there is ample opportunity to improve our genre classification and understand what drives bad and good reviews.
The core objective of this initiative is to leverage Data Science
principles to discover the factors influencing movie ratings and
accurately categorise films into their respective genres. We aim to
achieve this by:
Predicting Average Movie Ratings: Developing a robust regression model to forecast the average rating a movie is likely to receive, providing valuable insights for creators and consumers alike.
Categorising Film Genres: Building an effective classification model to automatically assign genres to films based on their intrinsic features, streamlining content organization and discovery.
Setup all the packages that will be used in this project, from data preprocessing until application deployment
knitr::opts_chunk$set(echo = TRUE)
library(dplyr)
library(knitr)
library(kableExtra)
library(stringr)
library(tidyr)
library(readr)
library(ggplot2)
library(wordcloud)
library(tm)
library(tibble)
library(keras)
library(text2vec)
library(Matrix)
library(tibble)
library(tensorflow)
library(reticulate)
library(tidyverse)
library(randomForest)
library(caret)
library(shiny)
# install_miniconda()
use_miniconda("r-reticulate", required = TRUE)
# install_keras()
# install_tensorflow(version = "2.10.0", method = "conda", envname = "r-reticulate")
There will be 3 datasets used in this project, which are movies,
ratings and tags.
Import and explore the data from the files and
combine them into a single tabular dataset.
| movieId | title | genres |
|---|---|---|
| 1 | Toy Story (1995) | Adventure|Animation|Children|Comedy|Fantasy |
| 2 | Jumanji (1995) | Adventure|Children|Fantasy |
| 3 | Grumpier Old Men (1995) | Comedy|Romance |
| 4 | Waiting to Exhale (1995) | Comedy|Drama|Romance |
| 5 | Father of the Bride Part II (1995) | Comedy |
| userId | movieId | rating | timestamp |
|---|---|---|---|
| 1 | 2 | 3.5 | 1112486027 |
| 1 | 29 | 3.5 | 1112484676 |
| 1 | 32 | 3.5 | 1112484819 |
| 1 | 47 | 3.5 | 1112484727 |
| 1 | 50 | 3.5 | 1112484580 |
| userId | movieId | tag | timestamp |
|---|---|---|---|
| 18 | 4141 | Mark Waters | 1240597180 |
| 65 | 208 | dark hero | 1368150078 |
| 65 | 353 | dark hero | 1368150079 |
| 65 | 521 | noir thriller | 1368149983 |
| 65 | 592 | dark hero | 1368150078 |
Missing rate of title column in movie dataset: 0%
| movieId | title | year | Adventure | Animation | Children | Comedy | Fantasy | Romance | Drama | Action | Crime | Thriller | Horror | Mystery | Sci-Fi | IMAX | Documentary | War | Musical | Western | Film-Noir | NoGenre |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | Toy Story | 1995 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 2 | Jumanji | 1995 | 1 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 3 | Grumpier Old Men | 1995 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 4 | Waiting to Exhale | 1995 | 0 | 0 | 0 | 1 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 5 | Father of the Bride Part II | 1995 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
Missing rate of rating column in ratings dataset: 0%
| movieId | title | year | Adventure | Animation | Children | Comedy | Fantasy | Romance | Drama | Action | Crime | Thriller | Horror | Mystery | Sci-Fi | IMAX | Documentary | War | Musical | Western | Film-Noir | NoGenre | average_rating | count_rating |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | Toy Story | 1995 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 3.921240 | 49695 |
| 2 | Jumanji | 1995 | 1 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 3.211977 | 22243 |
| 3 | Grumpier Old Men | 1995 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 3.151040 | 12735 |
| 4 | Waiting to Exhale | 1995 | 0 | 0 | 0 | 1 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 2.861393 | 2756 |
| 5 | Father of the Bride Part II | 1995 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 3.064592 | 12161 |
Summary of full dataset:
## movieId title year Adventure
## Min. : 1 Length:27278 Min. :1891 Min. :0.00000
## 1st Qu.: 6931 Class :character 1st Qu.:1976 1st Qu.:0.00000
## Median : 68068 Mode :character Median :1998 Median :0.00000
## Mean : 59855 Mean :1989 Mean :0.08538
## 3rd Qu.:100293 3rd Qu.:2008 3rd Qu.:0.00000
## Max. :131262 Max. :2015 Max. :1.00000
## NA's :22
## Animation Children Comedy Fantasy
## Min. :0.00000 Min. :0.00000 Min. :0.000 Min. :0.00000
## 1st Qu.:0.00000 1st Qu.:0.00000 1st Qu.:0.000 1st Qu.:0.00000
## Median :0.00000 Median :0.00000 Median :0.000 Median :0.00000
## Mean :0.03765 Mean :0.04176 Mean :0.307 Mean :0.05176
## 3rd Qu.:0.00000 3rd Qu.:0.00000 3rd Qu.:1.000 3rd Qu.:0.00000
## Max. :1.00000 Max. :1.00000 Max. :1.000 Max. :1.00000
##
## Romance Drama Action Crime
## Min. :0.0000 Min. :0.0000 Min. :0.000 Min. :0.0000
## 1st Qu.:0.0000 1st Qu.:0.0000 1st Qu.:0.000 1st Qu.:0.0000
## Median :0.0000 Median :0.0000 Median :0.000 Median :0.0000
## Mean :0.1513 Mean :0.4892 Mean :0.129 Mean :0.1077
## 3rd Qu.:0.0000 3rd Qu.:1.0000 3rd Qu.:0.000 3rd Qu.:0.0000
## Max. :1.0000 Max. :1.0000 Max. :1.000 Max. :1.0000
##
## Thriller Horror Mystery Sci-Fi
## Min. :0.0000 Min. :0.00000 Min. :0.0000 Min. :0.0000
## 1st Qu.:0.0000 1st Qu.:0.00000 1st Qu.:0.0000 1st Qu.:0.0000
## Median :0.0000 Median :0.00000 Median :0.0000 Median :0.0000
## Mean :0.1532 Mean :0.09572 Mean :0.0555 Mean :0.0639
## 3rd Qu.:0.0000 3rd Qu.:0.00000 3rd Qu.:0.0000 3rd Qu.:0.0000
## Max. :1.0000 Max. :1.00000 Max. :1.0000 Max. :1.0000
##
## IMAX Documentary War Musical
## Min. :0.000000 Min. :0.00000 Min. :0.00000 Min. :0.00000
## 1st Qu.:0.000000 1st Qu.:0.00000 1st Qu.:0.00000 1st Qu.:0.00000
## Median :0.000000 Median :0.00000 Median :0.00000 Median :0.00000
## Mean :0.007185 Mean :0.09059 Mean :0.04377 Mean :0.03798
## 3rd Qu.:0.000000 3rd Qu.:0.00000 3rd Qu.:0.00000 3rd Qu.:0.00000
## Max. :1.000000 Max. :1.00000 Max. :1.00000 Max. :1.00000
##
## Western Film-Noir NoGenre average_rating
## Min. :0.00000 Min. :0.0000 Min. :0.000000 Min. :0.500
## 1st Qu.:0.00000 1st Qu.:0.0000 1st Qu.:0.000000 1st Qu.:2.800
## Median :0.00000 Median :0.0000 Median :0.000000 Median :3.235
## Mean :0.02478 Mean :0.0121 Mean :0.009018 Mean :3.133
## 3rd Qu.:0.00000 3rd Qu.:0.0000 3rd Qu.:0.000000 3rd Qu.:3.565
## Max. :1.00000 Max. :1.0000 Max. :1.000000 Max. :5.000
## NA's :534
## count_rating all_tags
## Min. : 1.0 Length:27278
## 1st Qu.: 3.0 Class :character
## Median : 18.0 Mode :character
## Mean : 747.8
## 3rd Qu.: 205.0
## Max. :67310.0
## NA's :534
Features that contain with missing values:
For tags missing value, an empty string will be used to replace
it.
As for others column missing values, since it is not too much,
thus the data will be truncated
==> Columns that contain with missing values after preprocessing: [There is no missing data]
The cleaned dataset will be saved as full_movies.csv.
Build a neural network model to train for the multi-label genre classifier.
From the plot, the model for training dataset is perform with high
accuracy while the testing dataset is not performing well.
This
happened might due to overfitting on the trained model.
Predict a movie genre:
Title –> Alien Resurrection
Tags
–> space | monster | thriller | future | horror
Year –> 2024
Count Rating –> 7000
## 1/1 - 0s - 219ms/epoch - 219ms/step
| genre | probability |
|---|---|
| Horror | 0.969 |
| Sci-Fi | 0.815 |
| Thriller | 0.724 |
From the result of the genre prediction, the genre classifier is successfully predict the genre with a given probability
Build a random forest regression model to predict on movie rating.
Regression Model Summary:
## Length Class Mode
## call 6 -none- call
## type 1 -none- character
## predicted 21377 -none- numeric
## mse 100 -none- numeric
## rsq 100 -none- numeric
## oob.times 21377 -none- numeric
## importance 44 -none- numeric
## importanceSD 22 -none- numeric
## localImportance 0 -none- NULL
## proximity 0 -none- NULL
## ntree 1 -none- numeric
## mtry 1 -none- numeric
## forest 11 -none- list
## coefs 0 -none- NULL
## y 21377 -none- numeric
## test 0 -none- NULL
## inbag 0 -none- NULL
## xNames 22 -none- character
## problemType 1 -none- character
## tuneValue 1 data.frame list
## obsLevels 1 -none- logical
## param 2 -none- list
| Metric | Value |
|---|---|
| RMSE | 0.6083 |
| MAE | 0.4319 |
| R² | 0.1607 |
From the metrics table, the model’s prediction deviate from the
actual values by about 0.62 units
Build an application for the movie genre and rating prediction
In this project, three datasets are pre-processed and merge into a
single tabular dataset.
This clean dataset will then be evaluated
to gain any potential sight in the EDA.
Besides, the model that
trained in this project is successful predict on a movie genre and
rating.
Finally, an apps is developed by shiny package for the
movie genre and rating prediction.