Goal: to predict the average rating of horror movies. Click here for the data
horror_movies <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2022/2022-11-01/horror_movies.csv')
## Rows: 32540 Columns: 20
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (10): original_title, title, original_language, overview, tagline, post...
## dbl (8): id, popularity, vote_count, vote_average, budget, revenue, runtim...
## lgl (1): adult
## date (1): release_date
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
skimr::skim(horror_movies)
| Name | horror_movies |
| Number of rows | 32540 |
| Number of columns | 20 |
| _______________________ | |
| Column type frequency: | |
| character | 10 |
| Date | 1 |
| logical | 1 |
| numeric | 8 |
| ________________________ | |
| Group variables | None |
Variable type: character
| skim_variable | n_missing | complete_rate | min | max | empty | n_unique | whitespace |
|---|---|---|---|---|---|---|---|
| original_title | 0 | 1.00 | 1 | 191 | 0 | 30296 | 0 |
| title | 0 | 1.00 | 1 | 191 | 0 | 29563 | 0 |
| original_language | 0 | 1.00 | 2 | 2 | 0 | 97 | 0 |
| overview | 1286 | 0.96 | 1 | 1000 | 0 | 31020 | 0 |
| tagline | 19835 | 0.39 | 1 | 237 | 0 | 12513 | 0 |
| poster_path | 4474 | 0.86 | 30 | 32 | 0 | 28048 | 0 |
| status | 0 | 1.00 | 7 | 15 | 0 | 4 | 0 |
| backdrop_path | 18995 | 0.42 | 29 | 32 | 0 | 13536 | 0 |
| genre_names | 0 | 1.00 | 6 | 144 | 0 | 772 | 0 |
| collection_name | 30234 | 0.07 | 4 | 56 | 0 | 815 | 0 |
Variable type: Date
| skim_variable | n_missing | complete_rate | min | max | median | n_unique |
|---|---|---|---|---|---|---|
| release_date | 0 | 1 | 1950-01-01 | 2022-12-31 | 2012-12-09 | 10999 |
Variable type: logical
| skim_variable | n_missing | complete_rate | mean | count |
|---|---|---|---|---|
| adult | 0 | 1 | 0 | FAL: 32540 |
Variable type: numeric
| skim_variable | n_missing | complete_rate | mean | sd | p0 | p25 | p50 | p75 | p100 | hist |
|---|---|---|---|---|---|---|---|---|---|---|
| id | 0 | 1.00 | 445910.83 | 305744.67 | 17 | 146494.8 | 426521.00 | 707534.00 | 1033095.00 | ▇▆▆▅▅ |
| popularity | 0 | 1.00 | 4.01 | 37.51 | 0 | 0.6 | 0.84 | 2.24 | 5088.58 | ▇▁▁▁▁ |
| vote_count | 0 | 1.00 | 62.69 | 420.89 | 0 | 0.0 | 2.00 | 11.00 | 16900.00 | ▇▁▁▁▁ |
| vote_average | 0 | 1.00 | 3.34 | 2.88 | 0 | 0.0 | 4.00 | 5.70 | 10.00 | ▇▂▆▃▁ |
| budget | 0 | 1.00 | 543126.59 | 4542667.81 | 0 | 0.0 | 0.00 | 0.00 | 200000000.00 | ▇▁▁▁▁ |
| revenue | 0 | 1.00 | 1349746.73 | 14430479.15 | 0 | 0.0 | 0.00 | 0.00 | 701842551.00 | ▇▁▁▁▁ |
| runtime | 0 | 1.00 | 62.14 | 41.00 | 0 | 14.0 | 80.00 | 91.00 | 683.00 | ▇▁▁▁▁ |
| collection | 30234 | 0.07 | 481534.88 | 324498.16 | 656 | 155421.0 | 471259.00 | 759067.25 | 1033032.00 | ▇▅▅▅▅ |
data2 <- horror_movies %>%
# Treat Missing Values
select(-tagline, -collection_name, -collection, -backdrop_path, -original_title) %>%
filter(budget != 0) %>%
filter(revenue != 0) %>%
na.omit() %>%
separate_rows(genre_names) %>%
# Log Transform Variables with Pos-Skewed Distribution
mutate(vote_average = log(vote_average + 1))
skimr::skim(data2)
| Name | data2 |
| Number of rows | 2929 |
| Number of columns | 15 |
| _______________________ | |
| Column type frequency: | |
| character | 6 |
| Date | 1 |
| logical | 1 |
| numeric | 7 |
| ________________________ | |
| Group variables | None |
Variable type: character
| skim_variable | n_missing | complete_rate | min | max | empty | n_unique | whitespace |
|---|---|---|---|---|---|---|---|
| title | 0 | 1 | 1 | 50 | 0 | 1025 | 0 |
| original_language | 0 | 1 | 2 | 2 | 0 | 29 | 0 |
| overview | 0 | 1 | 17 | 991 | 0 | 1063 | 0 |
| poster_path | 0 | 1 | 30 | 32 | 0 | 1065 | 0 |
| status | 0 | 1 | 8 | 8 | 0 | 1 | 0 |
| genre_names | 0 | 1 | 2 | 11 | 0 | 21 | 0 |
Variable type: Date
| skim_variable | n_missing | complete_rate | min | max | median | n_unique |
|---|---|---|---|---|---|---|
| release_date | 0 | 1 | 1953-04-16 | 2022-10-05 | 2006-12-15 | 986 |
Variable type: logical
| skim_variable | n_missing | complete_rate | mean | count |
|---|---|---|---|---|
| adult | 0 | 1 | 0 | FAL: 2929 |
Variable type: numeric
| skim_variable | n_missing | complete_rate | mean | sd | p0 | p25 | p50 | p75 | p100 | hist |
|---|---|---|---|---|---|---|---|---|---|---|
| id | 0 | 1 | 165306.10 | 243903.76 | 83.0 | 10336.00 | 2.8355e+04 | 284564.00 | 1032494.00 | ▇▁▁▁▁ |
| popularity | 0 | 1 | 30.73 | 84.40 | 0.6 | 8.54 | 1.5870e+01 | 30.06 | 1863.63 | ▇▁▁▁▁ |
| vote_count | 0 | 1 | 1311.19 | 1942.79 | 0.0 | 156.00 | 5.7800e+02 | 1680.00 | 16900.00 | ▇▁▁▁▁ |
| vote_average | 0 | 1 | 1.88 | 0.38 | 0.0 | 1.87 | 1.9600e+00 | 2.03 | 2.40 | ▁▁▁▅▇ |
| budget | 0 | 1 | 15397444.01 | 22877970.21 | 1.0 | 1750000.00 | 7.0000e+06 | 19000000.00 | 200000000.00 | ▇▁▁▁▁ |
| revenue | 0 | 1 | 41869570.31 | 72358218.87 | 1.0 | 1261000.00 | 1.2600e+07 | 49169594.00 | 701842551.00 | ▇▁▁▁▁ |
| runtime | 0 | 1 | 95.69 | 22.69 | 0.0 | 89.00 | 9.6000e+01 | 105.00 | 179.00 | ▁▁▇▂▁ |
Identify good predictors
Revenue
data2 %>%
ggplot(aes(vote_average, revenue)) +
geom_point()
Popularity
data2 %>%
ggplot(aes(vote_average, popularity)) +
geom_point()
Budget
data2 %>%
ggplot(aes(vote_average, budget)) +
geom_point()
EDA Shortcut
# Step 1: Prepare data
data_binarized_tbl2 <- data2 %>%
select(-id, -title, -overview, -poster_path, -genre_names, -release_date) %>%
binarize()
data_binarized_tbl2 %>% glimpse()
## Rows: 2,929
## Columns: 31
## $ original_language__en <dbl> 1, 1, 1, 1, 1, 1, 1, 1…
## $ original_language__es <dbl> 0, 0, 0, 0, 0, 0, 0, 0…
## $ original_language__fr <dbl> 0, 0, 0, 0, 0, 0, 0, 0…
## $ original_language__hi <dbl> 0, 0, 0, 0, 0, 0, 0, 0…
## $ original_language__ja <dbl> 0, 0, 0, 0, 0, 0, 0, 0…
## $ original_language__ko <dbl> 0, 0, 0, 0, 0, 0, 0, 0…
## $ `original_language__-OTHER` <dbl> 0, 0, 0, 0, 0, 0, 0, 0…
## $ `popularity__-Inf_8.535` <dbl> 0, 0, 0, 0, 0, 0, 0, 0…
## $ popularity__8.535_15.868 <dbl> 0, 0, 0, 0, 0, 0, 0, 0…
## $ popularity__15.868_30.063 <dbl> 0, 0, 0, 0, 0, 0, 0, 0…
## $ popularity__30.063_Inf <dbl> 1, 1, 1, 1, 1, 1, 1, 1…
## $ `vote_count__-Inf_156` <dbl> 1, 1, 1, 0, 0, 1, 1, 1…
## $ vote_count__156_578 <dbl> 0, 0, 0, 0, 0, 0, 0, 0…
## $ vote_count__578_1680 <dbl> 0, 0, 0, 0, 0, 0, 0, 0…
## $ vote_count__1680_Inf <dbl> 0, 0, 0, 1, 1, 0, 0, 0…
## $ `vote_average__-Inf_1.87180217690159` <dbl> 0, 0, 0, 0, 0, 0, 0, 0…
## $ vote_average__1.87180217690159_1.96009478404727 <dbl> 0, 0, 0, 0, 0, 1, 1, 1…
## $ vote_average__1.96009478404727_2.02814824729229 <dbl> 0, 0, 0, 0, 0, 0, 0, 0…
## $ vote_average__2.02814824729229_Inf <dbl> 1, 1, 1, 1, 1, 0, 0, 0…
## $ `budget__-Inf_1750000` <dbl> 0, 0, 0, 0, 0, 0, 0, 0…
## $ `budget__1750000_7e+06` <dbl> 0, 0, 0, 0, 0, 0, 0, 0…
## $ `budget__7e+06_1.9e+07` <dbl> 1, 1, 1, 1, 1, 0, 0, 0…
## $ `budget__1.9e+07_Inf` <dbl> 0, 0, 0, 0, 0, 1, 1, 1…
## $ `revenue__-Inf_1261000` <dbl> 0, 0, 0, 0, 0, 0, 0, 0…
## $ revenue__1261000_12600000 <dbl> 0, 0, 0, 0, 0, 1, 1, 1…
## $ revenue__12600000_49169594 <dbl> 1, 1, 1, 0, 0, 0, 0, 0…
## $ revenue__49169594_Inf <dbl> 0, 0, 0, 1, 1, 0, 0, 0…
## $ `runtime__-Inf_89` <dbl> 0, 0, 0, 0, 0, 1, 1, 1…
## $ runtime__89_96 <dbl> 0, 0, 0, 0, 0, 0, 0, 0…
## $ runtime__96_105 <dbl> 0, 0, 0, 1, 1, 0, 0, 0…
## $ runtime__105_Inf <dbl> 1, 1, 1, 0, 0, 0, 0, 0…
# Step 2: Correlate
data_corr_tbl2 <- data_binarized_tbl2 %>%
correlate(vote_average__2.02814824729229_Inf)
data_corr_tbl2
## # A tibble: 31 × 3
## feature bin correlation
## <fct> <chr> <dbl>
## 1 vote_average 2.02814824729229_Inf 1
## 2 vote_average -Inf_1.87180217690159 -0.359
## 3 vote_average 1.87180217690159_1.96009478404727 -0.337
## 4 vote_average 1.96009478404727_2.02814824729229 -0.291
## 5 runtime 105_Inf 0.242
## 6 vote_count 1680_Inf 0.210
## 7 vote_count 156_578 -0.185
## 8 original_language en -0.167
## 9 original_language ja 0.140
## 10 runtime 89_96 -0.120
## # ℹ 21 more rows
# Step 3: Plot
data_corr_tbl2 %>%
plot_correlation_funnel()
## Warning: ggrepel: 1 unlabeled data points (too many overlaps). Consider
## increasing max.overlaps
Split Data
set.seed(1234)
# data2 <- sample_n(data2, 100)
# Split into train and testing data set
data_split2 <- rsample::initial_split(data2)
data_train2 <- training(data_split2)
data_test2 <- testing(data_split2)
# Further split training data set for cross-validation
set.seed(2345)
data_cv2 <- rsample::vfold_cv(data_train2)
data_cv2
## # 10-fold cross-validation
## # A tibble: 10 × 2
## splits id
## <list> <chr>
## 1 <split [1976/220]> Fold01
## 2 <split [1976/220]> Fold02
## 3 <split [1976/220]> Fold03
## 4 <split [1976/220]> Fold04
## 5 <split [1976/220]> Fold05
## 6 <split [1976/220]> Fold06
## 7 <split [1977/219]> Fold07
## 8 <split [1977/219]> Fold08
## 9 <split [1977/219]> Fold09
## 10 <split [1977/219]> Fold10
library(usemodels)
usemodels::use_xgboost(vote_average ~ ., data = data_train2)
## xgboost_recipe <-
## recipe(formula = vote_average ~ ., data = data_train2) %>%
## step_zv(all_predictors())
##
## xgboost_spec <-
## boost_tree(trees = tune(), min_n = tune(), tree_depth = tune(), learn_rate = tune(),
## loss_reduction = tune(), sample_size = tune()) %>%
## set_mode("classification") %>%
## set_engine("xgboost")
##
## xgboost_workflow <-
## workflow() %>%
## add_recipe(xgboost_recipe) %>%
## add_model(xgboost_spec)
##
## set.seed(19510)
## xgboost_tune <-
## tune_grid(xgboost_workflow, resamples = stop("add your rsample object"), grid = stop("add number of candidate points"))
# Specify Recipe
xgboost_recipe <-
recipe(formula = vote_average ~ ., data = data_train2) %>%
update_role(id, new_role = "id variable") %>%
step_tokenize(overview, title) %>%
step_tokenfilter(overview, title, max_tokens = 100) %>%
step_tfidf(overview, title) %>%
step_other(original_language, status) %>%
step_dummy(original_language, genre_names, one_hot = TRUE) %>%
step_YeoJohnson(popularity, vote_count, budget, revenue, runtime, vote_average) %>%
step_rm(release_date, status, adult, poster_path)
xgboost_recipe %>% prep() %>% juice() %>% glimpse()
## Rows: 2,196
## Columns: 229
## $ id <dbl> 11531, 9100, 412741, 27414, 280092, 9540, 10…
## $ popularity <dbl> 3.1907232, 3.5885065, 0.9090647, 3.2501419, …
## $ vote_count <dbl> 13.9368007, 17.5484561, 0.7467929, 10.695733…
## $ budget <dbl> 226.84834, 226.84834, 19.02226, 117.02621, 2…
## $ revenue <dbl> 131.07906, 115.78162, 19.65589, 74.38695, 15…
## $ runtime <dbl> 1450.2581, 1768.1464, 1341.3365, 1159.4754, …
## $ vote_average <dbl> 1.648659, 2.041220, 2.397895, 1.916923, 1.98…
## $ tfidf_overview_a <dbl> 0.00000000, 0.10668408, 0.12446476, 0.000000…
## $ tfidf_overview_about <dbl> 0.0000000, 0.0000000, 0.0000000, 0.0000000, …
## $ tfidf_overview_after <dbl> 0.00000000, 0.00000000, 0.00000000, 0.000000…
## $ tfidf_overview_against <dbl> 0.0000000, 0.2024950, 0.0000000, 0.0000000, …
## $ tfidf_overview_all <dbl> 0.0000000, 0.1800512, 0.0000000, 0.0000000, …
## $ tfidf_overview_an <dbl> 0.00000000, 0.00000000, 0.00000000, 0.120831…
## $ tfidf_overview_and <dbl> 0.06661274, 0.00000000, 0.00000000, 0.000000…
## $ tfidf_overview_are <dbl> 0.000000, 0.000000, 0.000000, 0.000000, 0.00…
## $ tfidf_overview_as <dbl> 0.00000000, 0.00000000, 0.00000000, 0.000000…
## $ tfidf_overview_at <dbl> 0.00000000, 0.00000000, 0.00000000, 0.000000…
## $ tfidf_overview_back <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_overview_be <dbl> 0.00000000, 0.16189350, 0.00000000, 0.000000…
## $ tfidf_overview_becomes <dbl> 0.0000000, 0.0000000, 0.0000000, 0.0000000, …
## $ tfidf_overview_been <dbl> 0.00000000, 0.00000000, 0.00000000, 0.000000…
## $ tfidf_overview_before <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_overview_begins <dbl> 0.0000000, 0.0000000, 0.0000000, 0.0000000, …
## $ tfidf_overview_but <dbl> 0.00000000, 0.00000000, 0.00000000, 0.000000…
## $ tfidf_overview_by <dbl> 0.11454532, 0.00000000, 0.00000000, 0.133636…
## $ tfidf_overview_can <dbl> 0.00000000, 0.00000000, 0.00000000, 0.000000…
## $ tfidf_overview_city <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_overview_dead <dbl> 0.0000000, 0.0000000, 0.0000000, 0.0000000, …
## $ tfidf_overview_death <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_overview_discovers <dbl> 0.0000000, 0.0000000, 0.0000000, 0.0000000, …
## $ tfidf_overview_evil <dbl> 0.00000000, 0.00000000, 0.00000000, 0.000000…
## $ tfidf_overview_family <dbl> 0.0000000, 0.0000000, 0.0000000, 0.0000000, …
## $ tfidf_overview_father <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_overview_film <dbl> 0.0000000, 0.0000000, 0.0000000, 0.0000000, …
## $ tfidf_overview_find <dbl> 0.1793707, 0.0000000, 0.0000000, 0.0000000, …
## $ tfidf_overview_finds <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_overview_for <dbl> 0.00000000, 0.00000000, 0.00000000, 0.125384…
## $ tfidf_overview_friend <dbl> 0.0000000, 0.0000000, 0.0000000, 0.0000000, …
## $ tfidf_overview_friends <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_overview_from <dbl> 0.00000000, 0.00000000, 0.00000000, 0.000000…
## $ tfidf_overview_girl <dbl> 0.0000000, 0.0000000, 0.0000000, 0.0000000, …
## $ tfidf_overview_group <dbl> 0.00000000, 0.00000000, 0.00000000, 0.000000…
## $ tfidf_overview_has <dbl> 0.00000000, 0.00000000, 0.00000000, 0.158741…
## $ tfidf_overview_have <dbl> 0.00000000, 0.00000000, 0.00000000, 0.000000…
## $ tfidf_overview_he <dbl> 0.00000000, 0.00000000, 0.15948515, 0.159485…
## $ tfidf_overview_her <dbl> 0.00000000, 0.00000000, 0.00000000, 0.000000…
## $ tfidf_overview_him <dbl> 0.00000000, 0.00000000, 0.00000000, 0.000000…
## $ tfidf_overview_his <dbl> 0.00000000, 0.00000000, 0.00000000, 0.232597…
## $ tfidf_overview_home <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_overview_house <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_overview_human <dbl> 0.0000000, 0.0000000, 0.2741432, 0.0000000, …
## $ tfidf_overview_in <dbl> 0.07576003, 0.07576003, 0.08838670, 0.176773…
## $ tfidf_overview_into <dbl> 0.13767181, 0.00000000, 0.00000000, 0.000000…
## $ tfidf_overview_is <dbl> 0.00000000, 0.00000000, 0.10230387, 0.000000…
## $ tfidf_overview_it <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_overview_its <dbl> 0.0000000, 0.0000000, 0.0000000, 0.0000000, …
## $ tfidf_overview_killer <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_overview_life <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_overview_lives <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_overview_man <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_overview_more <dbl> 0.0000000, 0.0000000, 0.0000000, 0.0000000, …
## $ tfidf_overview_must <dbl> 0.00000000, 0.00000000, 0.00000000, 0.000000…
## $ tfidf_overview_mysterious <dbl> 0.00000000, 0.00000000, 0.00000000, 0.000000…
## $ tfidf_overview_new <dbl> 0.0000000, 0.0000000, 0.0000000, 0.0000000, …
## $ tfidf_overview_night <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_overview_not <dbl> 0.00000000, 0.00000000, 0.00000000, 0.000000…
## $ tfidf_overview_now <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_overview_of <dbl> 0.06278884, 0.06278884, 0.07325364, 0.000000…
## $ tfidf_overview_old <dbl> 0.0000000, 0.0000000, 0.0000000, 0.0000000, …
## $ tfidf_overview_on <dbl> 0.00000000, 0.00000000, 0.00000000, 0.000000…
## $ tfidf_overview_one <dbl> 0.00000000, 0.00000000, 0.00000000, 0.000000…
## $ tfidf_overview_only <dbl> 0.0000000, 0.0000000, 0.0000000, 0.0000000, …
## $ tfidf_overview_out <dbl> 0.1671661, 0.0000000, 0.0000000, 0.0000000, …
## $ tfidf_overview_people <dbl> 0.0000000, 0.0000000, 0.0000000, 0.0000000, …
## $ tfidf_overview_secret <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_overview_serial <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_overview_she <dbl> 0.00000000, 0.00000000, 0.00000000, 0.000000…
## $ tfidf_overview_small <dbl> 0.0000000, 0.0000000, 0.0000000, 0.0000000, …
## $ tfidf_overview_soon <dbl> 0.00000000, 0.00000000, 0.00000000, 0.000000…
## $ tfidf_overview_that <dbl> 0.00000000, 0.00000000, 0.12064192, 0.000000…
## $ tfidf_overview_the <dbl> 0.17063313, 0.00000000, 0.13271466, 0.000000…
## $ tfidf_overview_their <dbl> 0.0000000, 0.1148559, 0.0000000, 0.0000000, …
## $ tfidf_overview_them <dbl> 0.00000000, 0.16040055, 0.00000000, 0.000000…
## $ tfidf_overview_themselves <dbl> 0.0000000, 0.0000000, 0.0000000, 0.0000000, …
## $ tfidf_overview_they <dbl> 0.13079632, 0.13079632, 0.00000000, 0.000000…
## $ tfidf_overview_this <dbl> 0.0000000, 0.0000000, 0.0000000, 0.0000000, …
## $ tfidf_overview_time <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_overview_to <dbl> 0.06137649, 0.06137649, 0.07160591, 0.071605…
## $ tfidf_overview_town <dbl> 0.00000000, 0.00000000, 0.00000000, 0.000000…
## $ tfidf_overview_two <dbl> 0.00000000, 0.00000000, 0.00000000, 0.000000…
## $ tfidf_overview_up <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_overview_vampire <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_overview_was <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_overview_what <dbl> 0.18966259, 0.00000000, 0.00000000, 0.000000…
## $ tfidf_overview_when <dbl> 0.00000000, 0.00000000, 0.00000000, 0.132445…
## $ tfidf_overview_where <dbl> 0.00000000, 0.00000000, 0.00000000, 0.000000…
## $ tfidf_overview_which <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_overview_while <dbl> 0.00000000, 0.00000000, 0.00000000, 0.000000…
## $ tfidf_overview_who <dbl> 0.00000000, 0.25334335, 0.00000000, 0.000000…
## $ tfidf_overview_wife <dbl> 0.0000000, 0.0000000, 0.0000000, 0.0000000, …
## $ tfidf_overview_will <dbl> 0.00000000, 0.00000000, 0.00000000, 0.000000…
## $ tfidf_overview_with <dbl> 0.00000000, 0.10276453, 0.11989195, 0.000000…
## $ tfidf_overview_woman <dbl> 0.0000000, 0.0000000, 0.0000000, 0.0000000, …
## $ tfidf_overview_world <dbl> 0.00000000, 0.00000000, 0.00000000, 0.000000…
## $ tfidf_overview_year <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_overview_years <dbl> 0.00000000, 0.00000000, 0.00000000, 0.227608…
## $ tfidf_overview_young <dbl> 0.1584682, 0.0000000, 0.0000000, 0.0000000, …
## $ tfidf_title_13th <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_2 <dbl> 1.193181, 0.000000, 0.000000, 0.000000, 0.00…
## $ tfidf_title_3 <dbl> 0.000000, 0.000000, 0.000000, 0.000000, 2.20…
## $ tfidf_title_3d <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_a <dbl> 0.0000000, 0.0000000, 0.0000000, 0.0000000, …
## $ tfidf_title_activity <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_alien <dbl> 0.00000, 0.00000, 0.00000, 0.00000, 0.00000,…
## $ tfidf_title_and <dbl> 0.000000, 0.000000, 0.000000, 0.000000, 0.00…
## $ tfidf_title_angel <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_at <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_bad <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_black <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_blob <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_blood <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_body <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_chapter <dbl> 0.000000, 0.000000, 0.000000, 0.000000, 2.75…
## $ tfidf_title_christmas <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_chucky <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_comes <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_creepers <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_cure <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_curse <dbl> 0.000000, 0.000000, 0.000000, 0.000000, 0.00…
## $ tfidf_title_damned <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_dark <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_darkness <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_day <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_days <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_dead <dbl> 0.000000, 0.000000, 0.000000, 0.000000, 0.00…
## $ tfidf_title_death <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_devil <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ `tfidf_title_devil's` <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_dog <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ `tfidf_title_don't` <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_dracula <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_earth <dbl> 0.000000, 0.000000, 0.000000, 0.000000, 0.00…
## $ tfidf_title_elm <dbl> 0.0000000, 0.0000000, 0.0000000, 0.0000000, …
## $ tfidf_title_evil <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_exorcism <dbl> 0.000000, 0.000000, 0.000000, 0.000000, 0.00…
## $ tfidf_title_eyes <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_final <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_firestarter <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_frankenstein <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_friday <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_friend <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_from <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_ghost <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_godzilla <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_grudge <dbl> 0.000000, 0.000000, 0.000000, 0.000000, 0.00…
## $ tfidf_title_halloween <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_haunted <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_hell <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_her <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_horror <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_house <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_i <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_ii <dbl> 0.000000, 0.000000, 0.000000, 0.000000, 0.00…
## $ tfidf_title_iii <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_in <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_island <dbl> 0.000000, 0.000000, 0.000000, 0.000000, 0.00…
## $ tfidf_title_it <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_jeepers <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_killer <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_last <dbl> 0.000000, 0.000000, 0.000000, 0.000000, 0.00…
## $ tfidf_title_legend <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_life <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_living <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_man <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_mars <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_me <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_my <dbl> 0.000000, 0.000000, 0.000000, 0.000000, 0.00…
## $ tfidf_title_new <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_night <dbl> 0.000000, 0.000000, 0.000000, 2.620028, 0.00…
## $ tfidf_title_nightmare <dbl> 0.0000000, 0.0000000, 0.0000000, 0.0000000, …
## $ tfidf_title_not <dbl> 0.000000, 0.000000, 0.000000, 0.000000, 0.00…
## $ tfidf_title_of <dbl> 0.8114261, 0.0000000, 2.4342783, 0.0000000, …
## $ tfidf_title_on <dbl> 0.0000000, 0.0000000, 0.0000000, 0.0000000, …
## $ tfidf_title_one <dbl> 0.000000, 0.000000, 0.000000, 0.000000, 0.00…
## $ tfidf_title_out <dbl> 0.000000, 0.000000, 0.000000, 0.000000, 0.00…
## $ tfidf_title_paranormal <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_part <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_psycho <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_purge <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_red <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_resident <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_return <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_revenge <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_saw <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_scream <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_silent <dbl> 0.000000, 0.000000, 0.000000, 1.664383, 0.00…
## $ tfidf_title_street <dbl> 0.0000000, 0.0000000, 0.0000000, 0.0000000, …
## $ tfidf_title_tales <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_the <dbl> 0.0000000, 1.4499735, 0.0000000, 0.0000000, …
## $ tfidf_title_thing <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_this <dbl> 0.000000, 0.000000, 0.000000, 0.000000, 0.00…
## $ tfidf_title_to <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_vampire <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_vs <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_witch <dbl> 1.622964, 0.000000, 0.000000, 0.000000, 0.00…
## $ tfidf_title_wolf <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ tfidf_title_zombie <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ original_language_en <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,…
## $ original_language_other <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ genre_names_Action <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ genre_names_Adventure <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ genre_names_Animation <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ genre_names_Comedy <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,…
## $ genre_names_Crime <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ genre_names_Documentary <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ genre_names_Drama <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ genre_names_Family <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ genre_names_Fantasy <dbl> 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0,…
## $ genre_names_Fiction <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,…
## $ genre_names_History <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ genre_names_Horror <dbl> 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0,…
## $ genre_names_Music <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ genre_names_Mystery <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ genre_names_Romance <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ genre_names_Science <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ genre_names_Thriller <dbl> 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,…
## $ genre_names_TV <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ genre_names_War <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ genre_names_Western <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
# Specify model
xgboost_spec <-
boost_tree(trees = tune(), min_n = tune(), mtry = tune(), learn_rate = tune()) %>%
set_mode("regression") %>%
set_engine("xgboost")
# Combine recipe and model using workflow
xgboost_workflow <-
workflow() %>%
add_recipe(xgboost_recipe) %>%
add_model(xgboost_spec)
# Tune hyperparameters
set.seed(6804)
xgboost_tune <-
tune_grid(xgboost_workflow, resamples = data_cv2, grid = 5)
## i Creating pre-processing data to finalize unknown parameter: mtry
## → A | warning: ! There are new levels in a factor: `TV`.
## There were issues with some computations A: x1There were issues with some computations A: x2There were issues with some computations A: x3There were issues with some computations A: x4There were issues with some computations A: x5 → B | warning: ! There are new levels in a factor: `Documentary`.
## There were issues with some computations A: x5There were issues with some computations A: x5 B: x1There were issues with some computations A: x5 B: x2There were issues with some computations A: x5 B: x3There were issues with some computations A: x5 B: x4There were issues with some computations A: x5 B: x5 → C | warning: ! There are new levels in a factor: `Western`.
## There were issues with some computations A: x5 B: x5There were issues with some computations A: x5 B: x5 C: x1There were issues with some computations A: x5 B: x5 C: x2There were issues with some computations A: x5 B: x5 C: x3There were issues with some computations A: x5 B: x5 C: x4There were issues with some computations A: x5 B: x5 C: x5There were issues with some computations A: x5 B: x5 C: x5
tune::show_best(xgboost_tune, metric = "rmse")
## # A tibble: 5 × 10
## mtry trees min_n learn_rate .metric .estimator mean n std_err .config
## <int> <int> <int> <dbl> <chr> <chr> <dbl> <int> <dbl> <chr>
## 1 150 1697 24 0.0671 rmse standard 0.0577 10 0.00406 Preproce…
## 2 95 777 35 0.100 rmse standard 0.0625 10 0.00369 Preproce…
## 3 219 1188 11 0.00768 rmse standard 0.0774 10 0.00307 Preproce…
## 4 13 361 6 0.0220 rmse standard 0.118 10 0.00499 Preproce…
## 5 71 1267 29 0.00253 rmse standard 0.127 10 0.00270 Preproce…
# Update the model by selecting the best hyperparameters.
xgboost_fw <- tune::finalize_workflow(xgboost_workflow,
tune::select_best(xgboost_tune, metric = "rmse"))
# Fit the model on the entire training data and test it on the test data
data_fit <- tune::last_fit(xgboost_fw, data_split2)
## → A | warning: ! There are new levels in a factor: `Movie`.
## There were issues with some computations A: x1There were issues with some computations A: x1
tune::collect_metrics(data_fit)
## # A tibble: 2 × 4
## .metric .estimator .estimate .config
## <chr> <chr> <dbl> <chr>
## 1 rmse standard 0.0606 Preprocessor1_Model1
## 2 rsq standard 0.978 Preprocessor1_Model1
tune::collect_predictions(data_fit) %>%
ggplot(aes(vote_average, .pred)) +
geom_point(alpha = 0.3, fill = "midnightblue") +
geom_abline(lty = 2, color = "gray50") +
coord_fixed()
Before I made my changes, I was getting a lot of errors and my model did not look like it had any correlation. I was trying to use the log function on variables that contained zeros, which is what was giving me the errors. To fix this, I used +1 with my log function and also used step_YeoJohnson in the recipe step. I also had variables misplaced in the recipe step, so I moved them to where they belong. I also used the full data set instead of a sample of 100. After my changes, my RMSE decreased to .0606, my R-squared increased to .978, and my model appears to have strong correlation.