Goal: predict the prices of IKEA items Click here for the data
#Import Data
ikea <- read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-11-03/ikea.csv')
## New names:
## Rows: 3694 Columns: 14
## ── Column specification
## ──────────────────────────────────────────────────────── Delimiter: "," chr
## (7): name, category, old_price, link, other_colors, short_description, d... dbl
## (6): ...1, item_id, price, depth, height, width lgl (1): sellable_online
## ℹ 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.
## • `` -> `...1`
skimr::skim(ikea)
| Name | ikea |
| Number of rows | 3694 |
| Number of columns | 14 |
| _______________________ | |
| Column type frequency: | |
| character | 7 |
| logical | 1 |
| numeric | 6 |
| ________________________ | |
| Group variables | None |
Variable type: character
| skim_variable | n_missing | complete_rate | min | max | empty | n_unique | whitespace |
|---|---|---|---|---|---|---|---|
| name | 0 | 1 | 3 | 27 | 0 | 607 | 0 |
| category | 0 | 1 | 4 | 36 | 0 | 17 | 0 |
| old_price | 0 | 1 | 4 | 13 | 0 | 365 | 0 |
| link | 0 | 1 | 52 | 163 | 0 | 2962 | 0 |
| other_colors | 0 | 1 | 2 | 3 | 0 | 2 | 0 |
| short_description | 0 | 1 | 3 | 63 | 0 | 1706 | 0 |
| designer | 0 | 1 | 3 | 1261 | 0 | 381 | 0 |
Variable type: logical
| skim_variable | n_missing | complete_rate | mean | count |
|---|---|---|---|---|
| sellable_online | 0 | 1 | 0.99 | TRU: 3666, FAL: 28 |
Variable type: numeric
| skim_variable | n_missing | complete_rate | mean | sd | p0 | p25 | p50 | p75 | p100 | hist |
|---|---|---|---|---|---|---|---|---|---|---|
| …1 | 0 | 1.00 | 1846.50 | 1066.51 | 0 | 923.25 | 1846.5 | 2769.75 | 3693 | ▇▇▇▇▇ |
| item_id | 0 | 1.00 | 48632396.79 | 28887094.10 | 58487 | 20390574.00 | 49288078.0 | 70403572.75 | 99932615 | ▇▇▇▇▇ |
| price | 0 | 1.00 | 1078.21 | 1374.65 | 3 | 180.90 | 544.7 | 1429.50 | 9585 | ▇▁▁▁▁ |
| depth | 1463 | 0.60 | 54.38 | 29.96 | 1 | 38.00 | 47.0 | 60.00 | 257 | ▇▃▁▁▁ |
| height | 988 | 0.73 | 101.68 | 61.10 | 1 | 67.00 | 83.0 | 124.00 | 700 | ▇▂▁▁▁ |
| width | 589 | 0.84 | 104.47 | 71.13 | 1 | 60.00 | 80.0 | 140.00 | 420 | ▇▅▂▁▁ |
skimr::skim(ikea)
| Name | ikea |
| Number of rows | 3694 |
| Number of columns | 14 |
| _______________________ | |
| Column type frequency: | |
| character | 7 |
| logical | 1 |
| numeric | 6 |
| ________________________ | |
| Group variables | None |
Variable type: character
| skim_variable | n_missing | complete_rate | min | max | empty | n_unique | whitespace |
|---|---|---|---|---|---|---|---|
| name | 0 | 1 | 3 | 27 | 0 | 607 | 0 |
| category | 0 | 1 | 4 | 36 | 0 | 17 | 0 |
| old_price | 0 | 1 | 4 | 13 | 0 | 365 | 0 |
| link | 0 | 1 | 52 | 163 | 0 | 2962 | 0 |
| other_colors | 0 | 1 | 2 | 3 | 0 | 2 | 0 |
| short_description | 0 | 1 | 3 | 63 | 0 | 1706 | 0 |
| designer | 0 | 1 | 3 | 1261 | 0 | 381 | 0 |
Variable type: logical
| skim_variable | n_missing | complete_rate | mean | count |
|---|---|---|---|---|
| sellable_online | 0 | 1 | 0.99 | TRU: 3666, FAL: 28 |
Variable type: numeric
| skim_variable | n_missing | complete_rate | mean | sd | p0 | p25 | p50 | p75 | p100 | hist |
|---|---|---|---|---|---|---|---|---|---|---|
| …1 | 0 | 1.00 | 1846.50 | 1066.51 | 0 | 923.25 | 1846.5 | 2769.75 | 3693 | ▇▇▇▇▇ |
| item_id | 0 | 1.00 | 48632396.79 | 28887094.10 | 58487 | 20390574.00 | 49288078.0 | 70403572.75 | 99932615 | ▇▇▇▇▇ |
| price | 0 | 1.00 | 1078.21 | 1374.65 | 3 | 180.90 | 544.7 | 1429.50 | 9585 | ▇▁▁▁▁ |
| depth | 1463 | 0.60 | 54.38 | 29.96 | 1 | 38.00 | 47.0 | 60.00 | 257 | ▇▃▁▁▁ |
| height | 988 | 0.73 | 101.68 | 61.10 | 1 | 67.00 | 83.0 | 124.00 | 700 | ▇▂▁▁▁ |
| width | 589 | 0.84 | 104.47 | 71.13 | 1 | 60.00 | 80.0 | 140.00 | 420 | ▇▅▂▁▁ |
data <- ikea %>%
# Including predictors excluded: designer, old_price
select(-link, -depth) %>%
na.omit() %>%
# Log Transformation variables with positive skewed distribution
mutate(price = log(price)) %>%
mutate(width = log(width))
Identify good predictors:
category
data %>%
ggplot(aes(price, as.factor(category))) +
geom_boxplot()
short_description
data %>%
# tokenize description
unnest_tokens(output = word, input = short_description) %>%
# calculate avg word per item
group_by(word) %>%
summarise(price = mean(price),
n = n()) %>%
ungroup() %>%
filter(n > 10) %>%
slice_max(order_by = price, n = 20) %>%
# Plot
ggplot(aes(price, fct_reorder(word, price))) +
geom_point()
# Step 1: Prepare data
data_binarized_tbl <- data %>%
select(-item_id, -short_description) %>%
binarize()
## New names:
## New names:
## • `...1__bin1` -> `...11`
## • `...1__bin2` -> `...12`
## • `...1__bin3` -> `...13`
## • `...1__bin4` -> `...14`
data_binarized_tbl %>% glimpse()
## Rows: 2,591
## Columns: 78
## $ ...11 <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1…
## $ ...12 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ ...13 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ ...14 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ name__ALGOT <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ name__BEKANT <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ name__BESTÅ <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `name__BILLY_/_OXBERG` <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ name__BRIMNES <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ name__BROR <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ name__EKET <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ name__GRÖNLID <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ name__HAVSTA <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ name__HEMNES <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ name__IVAR <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ name__JONAXEL <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ name__KALLAX <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ name__LIDHULT <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ name__LIXHULT <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ name__NORDLI <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ name__PAX <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ name__PLATSA <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `name__STUVA_/_FRITIDS` <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ name__TROFAST <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ name__VALLENTUNA <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ name__VIMLE <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `name__-OTHER` <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1…
## $ category__Bar_furniture <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1…
## $ category__Beds <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `category__Bookcases_&_shelving_units` <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `category__Cabinets_&_cupboards` <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ category__Chairs <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `category__Chests_of_drawers_&_drawer_units` <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `category__Children's_furniture` <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ category__Nursery_furniture <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ category__Outdoor_furniture <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `category__Sofas_&_armchairs` <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `category__Tables_&_desks` <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ category__Trolleys <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `category__TV_&_media_furniture` <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ category__Wardrobes <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `category__-OTHER` <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `price__-Inf_5.57972982598622` <dbl> 1, 0, 1, 1, 0, 1, 1, 1, 0…
## $ price__5.57972982598622_6.45362499889269 <dbl> 0, 0, 0, 0, 1, 0, 0, 0, 1…
## $ price__6.45362499889269_7.34277918933185 <dbl> 0, 1, 0, 0, 0, 0, 0, 0, 0…
## $ price__7.34277918933185_Inf <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ old_price__No_old_price <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1…
## $ `old_price__-OTHER` <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ sellable_online__1 <dbl> 1, 0, 1, 1, 1, 1, 1, 1, 1…
## $ `sellable_online__-OTHER` <dbl> 0, 1, 0, 0, 0, 0, 0, 0, 0…
## $ other_colors__No <dbl> 1, 1, 0, 1, 1, 1, 1, 1, 1…
## $ other_colors__Yes <dbl> 0, 0, 1, 0, 0, 0, 0, 0, 0…
## $ designer__Carina_Bengs <dbl> 0, 0, 0, 0, 1, 0, 0, 0, 1…
## $ designer__Ebba_Strandmark <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ designer__Ehlén_Johansson <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `designer__Ehlén_Johansson/IKEA_of_Sweden` <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ designer__Francis_Cayouette <dbl> 0, 1, 0, 0, 0, 0, 0, 0, 0…
## $ designer__Henrik_Preutz <dbl> 0, 0, 1, 0, 0, 0, 0, 0, 0…
## $ designer__IKEA_of_Sweden <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `designer__IKEA_of_Sweden/Ehlén_Johansson` <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `designer__IKEA_of_Sweden/Jon_Karlsson` <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ designer__Johan_Kroon <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ designer__Jon_Karlsson <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `designer__K_Hagberg/M_Hagberg` <dbl> 0, 0, 0, 0, 0, 1, 1, 1, 0…
## $ designer__Marcus_Arvonen <dbl> 0, 0, 0, 1, 0, 0, 0, 0, 0…
## $ designer__Nike_Karlsson <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ designer__Ola_Wihlborg <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ designer__Studio_Copenhagen <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ designer__Tord_Björklund <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `designer__-OTHER` <dbl> 1, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `height__-Inf_70` <dbl> 0, 0, 0, 1, 0, 0, 0, 0, 0…
## $ height__70_83 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ height__83_127 <dbl> 1, 1, 1, 0, 1, 1, 1, 1, 1…
## $ height__127_Inf <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `width__-Inf_4.0943445622221` <dbl> 1, 0, 1, 0, 1, 1, 1, 1, 1…
## $ width__4.0943445622221_4.38202663467388 <dbl> 0, 1, 0, 1, 0, 0, 0, 0, 0…
## $ width__4.38202663467388_5.01063529409626 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ width__5.01063529409626_Inf <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0…
# Step 2: Correlate
data_corr_tbl <- data_binarized_tbl %>%
correlate(price__5.57972982598622_6.45362499889269)
## Warning: Expected 2 pieces. Missing pieces filled with `NA` in 4 rows [1, 2, 3,
## 4].
data_corr_tbl
## # A tibble: 78 × 3
## feature bin correlation
## <fct> <chr> <dbl>
## 1 price 5.57972982598622_6.45362499889269 1
## 2 price -Inf_5.57972982598622 -0.334
## 3 price 6.45362499889269_7.34277918933185 -0.333
## 4 price 7.34277918933185_Inf -0.332
## 5 width 5.01063529409626_Inf -0.245
## 6 width 4.0943445622221_4.38202663467388 0.189
## 7 category Sofas_&_armchairs -0.134
## 8 name PAX -0.113
## 9 category Wardrobes -0.109
## 10 category Tables_&_desks 0.0886
## # ℹ 68 more rows
# Step 3: Plot
data_corr_tbl %>%
plot_correlation_funnel()
## Warning: Removed 4 rows containing missing values (`geom_text_repel()`).
## Warning: ggrepel: 56 unlabeled data points (too many overlaps). Consider
## increasing max.overlaps
Split data
# Split into train and test dataset
set.seed(1234)
data_split <- rsample::initial_split(data)
data_training <- training(data_split)
data_test <- testing(data_split)
# Further split training dataset for cross-validation
set.seed(1234)
data_cv <- rsample::vfold_cv(data_training)
data_cv
## # 10-fold cross-validation
## # A tibble: 10 × 2
## splits id
## <list> <chr>
## 1 <split [1748/195]> Fold01
## 2 <split [1748/195]> Fold02
## 3 <split [1748/195]> Fold03
## 4 <split [1749/194]> Fold04
## 5 <split [1749/194]> Fold05
## 6 <split [1749/194]> Fold06
## 7 <split [1749/194]> Fold07
## 8 <split [1749/194]> Fold08
## 9 <split [1749/194]> Fold09
## 10 <split [1749/194]> Fold10
library(usemodels)
usemodels::use_ranger(price ~ ., data = data_training)
## ranger_recipe <-
## recipe(formula = price ~ ., data = data_training)
##
## ranger_spec <-
## rand_forest(mtry = tune(), min_n = tune(), trees = 1000) %>%
## set_mode("classification") %>%
## set_engine("ranger")
##
## ranger_workflow <-
## workflow() %>%
## add_recipe(ranger_recipe) %>%
## add_model(ranger_spec)
##
## set.seed(3821)
## ranger_tune <-
## tune_grid(ranger_workflow, resamples = stop("add your rsample object"), grid = stop("add number of candidate points"))
# Specify recipe
ranger_recipe <-
recipe(formula = price ~ ., data = data_training) %>%
recipes::update_role(item_id, new_role = "id variable") %>%
step_tokenize(short_description) %>%
step_tokenfilter(short_description, max_tokens = 140) %>%
step_tfidf(short_description) %>%
step_other(designer, old_price, name) %>%
step_dummy(designer, old_price, name, one_hot = TRUE) %>%
step_YeoJohnson(width)
ranger_recipe %>% prep() %>% juice() %>% glimpse()
## Rows: 1,943
## Columns: 154
## $ ...1 <dbl> 1368, 817, 1247, 528, 3074, 2242,…
## $ item_id <dbl> 39251926, 59248867, 30346986, 402…
## $ category <fct> "Chairs", "Cabinets & cupboards",…
## $ sellable_online <lgl> TRUE, TRUE, TRUE, TRUE, TRUE, TRU…
## $ other_colors <fct> No, Yes, No, Yes, No, Yes, Yes, N…
## $ height <dbl> 90, 60, 40, 64, 75, 85, 64, 77, 2…
## $ width <dbl> 10.067191, 11.233319, 5.731771, 1…
## $ price <dbl> 7.106606, 6.363028, 3.912023, 6.1…
## $ tfidf_short_description_1 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_120 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_120x60 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_125 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_140x200 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_140x78 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_140x85 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_147x147 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_150x44x236 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_150x60x236 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_150x66x236 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_150x75 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_155 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_156x90 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_160 <dbl> 0.000000, 0.000000, 0.000000, 0.0…
## $ tfidf_short_description_160x200 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_2 <dbl> 0.0000000, 0.0000000, 0.0000000, …
## $ tfidf_short_description_200x66x236 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_220x100 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_235x100 <dbl> 0.0000000, 0.0000000, 0.0000000, …
## $ tfidf_short_description_25x51x70 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_3 <dbl> 0.0000000, 0.0000000, 0.0000000, …
## $ tfidf_short_description_4 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_41x101 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_41x61 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_42x30x23 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_5 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_50x51x70 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_6 <dbl> 0.0000000, 0.0000000, 0.0000000, …
## $ tfidf_short_description_60x120 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_60x26 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_60x38 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_60x50x128 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_60x64 <dbl> 0.000000, 0.000000, 0.000000, 0.0…
## $ tfidf_short_description_63 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_7 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_74 <dbl> 0.0000000, 0.0000000, 0.0000000, …
## $ tfidf_short_description_74x74 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_75 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_77x147 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_8 <dbl> 0.000000, 0.000000, 0.000000, 0.0…
## $ tfidf_short_description_80x139 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_80x200 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_80x30x202 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_90x200 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_add <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_and <dbl> 0.0000000, 0.0000000, 0.0000000, …
## $ tfidf_short_description_armchair <dbl> 0.9758717, 0.0000000, 0.0000000, …
## $ tfidf_short_description_armrest <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_armrests <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_backrest <dbl> 0.0000000, 0.0000000, 0.0000000, …
## $ tfidf_short_description_bar <dbl> 0.0000000, 0.0000000, 0.0000000, …
## $ tfidf_short_description_baskets <dbl> 0.000000, 0.000000, 0.000000, 0.0…
## $ tfidf_short_description_bed <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_bench <dbl> 0.000000, 0.000000, 0.000000, 1.1…
## $ tfidf_short_description_bookcase <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_box <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_cabinet <dbl> 0.000000, 0.000000, 0.000000, 0.0…
## $ tfidf_short_description_cabinets <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_castors <dbl> 0.0000000, 0.0000000, 0.0000000, …
## $ tfidf_short_description_chair <dbl> 0.000000, 0.000000, 0.000000, 0.0…
## $ tfidf_short_description_chairs <dbl> 0.0000000, 0.0000000, 0.0000000, …
## $ tfidf_short_description_chaise <dbl> 0.0000, 0.0000, 0.0000, 0.0000, 0…
## $ tfidf_short_description_changing <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_chest <dbl> 0.0000000, 0.0000000, 0.0000000, …
## $ `tfidf_short_description_children's` <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_cm <dbl> 0.2100031, 0.2800041, 0.0000000, …
## $ tfidf_short_description_coffee <dbl> 0.000000, 0.000000, 0.000000, 0.0…
## $ tfidf_short_description_combination <dbl> 0.0000000, 0.7772729, 0.0000000, …
## $ tfidf_short_description_corner <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_cot <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_cover <dbl> 0.000000, 0.000000, 1.134554, 0.0…
## $ tfidf_short_description_day <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_desk <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_door <dbl> 0.000000, 0.000000, 0.000000, 0.0…
## $ tfidf_short_description_doors <dbl> 0.0000000, 0.0000000, 0.0000000, …
## $ tfidf_short_description_drawer <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_drawers <dbl> 0.0000000, 0.0000000, 0.0000000, …
## $ tfidf_short_description_drop <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_extendable <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_feet <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_foldable <dbl> 0.0000000, 0.0000000, 0.0000000, …
## $ tfidf_short_description_folding <dbl> 0.000000, 0.000000, 0.000000, 0.0…
## $ tfidf_short_description_footstool <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_for <dbl> 0.000000, 0.000000, 1.008623, 0.0…
## $ tfidf_short_description_frame <dbl> 0.0000000, 0.0000000, 0.0000000, …
## $ tfidf_short_description_front <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_glass <dbl> 0.0000000, 0.0000000, 0.0000000, …
## $ tfidf_short_description_headboard <dbl> 0.00000, 0.00000, 0.00000, 0.0000…
## $ tfidf_short_description_highchair <dbl> 0.000000, 0.000000, 1.253427, 0.0…
## $ tfidf_short_description_in <dbl> 1.081796, 0.000000, 0.000000, 0.0…
## $ tfidf_short_description_inserts <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_junior <dbl> 0.0000, 0.0000, 0.0000, 0.0000, 0…
## $ tfidf_short_description_kitchen <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_leg <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_legs <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_lock <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_longue <dbl> 0.0000, 0.0000, 0.0000, 0.0000, 0…
## $ tfidf_short_description_mattresses <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_mesh <dbl> 0.0000000, 0.0000000, 0.0000000, …
## $ tfidf_short_description_modular <dbl> 0.0000000, 0.0000000, 0.0000000, …
## $ tfidf_short_description_module <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_mounted <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_of <dbl> 0.0000000, 0.0000000, 0.0000000, …
## $ tfidf_short_description_on <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_outdoor <dbl> 0.7495451, 0.0000000, 0.0000000, …
## $ tfidf_short_description_plinth <dbl> 0.000000, 0.000000, 0.000000, 0.0…
## $ tfidf_short_description_rail <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_rails <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_rocking <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_seat <dbl> 0.0000000, 0.0000000, 0.5895387, …
## $ tfidf_short_description_section <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_sections <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_shelf <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_shelves <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_shelving <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_side <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_sliding <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_smart <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_sofa <dbl> 0.0000000, 0.0000000, 0.0000000, …
## $ tfidf_short_description_step <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_stool <dbl> 0.0000000, 0.0000000, 0.0000000, …
## $ tfidf_short_description_stools <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_storage <dbl> 0.0000000, 0.7409298, 0.0000000, …
## $ tfidf_short_description_table <dbl> 0.0000000, 0.0000000, 0.0000000, …
## $ tfidf_short_description_three <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_top <dbl> 0.000000, 0.000000, 0.000000, 0.0…
## $ tfidf_short_description_tray <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_trolley <dbl> 0.000000, 0.000000, 0.000000, 0.0…
## $ tfidf_short_description_tv <dbl> 0.000000, 0.000000, 0.000000, 1.0…
## $ tfidf_short_description_two <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_underframe <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_unit <dbl> 0.0000000, 0.0000000, 0.0000000, …
## $ tfidf_short_description_upright <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_ut <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_w <dbl> 0.0000000, 0.0000000, 0.0000000, …
## $ tfidf_short_description_wall <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_wardrobe <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_wire <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tfidf_short_description_with <dbl> 0.0000000, 0.0000000, 0.0000000, …
## $ designer_IKEA.of.Sweden <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ designer_other <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, …
## $ old_price_No.old.price <dbl> 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, …
## $ old_price_other <dbl> 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, …
## $ name_BESTÅ <dbl> 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, …
## $ name_other <dbl> 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, …
# Specify model
ranger_spec <-
rand_forest(trees = tune()) %>%
set_mode("regression") %>%
set_engine("ranger")
# Combine recipe and model using workflow
ranger_workflow <-
workflow() %>%
add_recipe(ranger_recipe) %>%
add_model(ranger_spec)
# Tune hyperparameters
set.seed(1434)
ranger_tune <-
tune_grid(ranger_workflow,
resamples = data_cv,
grid = 5)
tune::show_best(ranger_tune, metric = "rmse")
## # A tibble: 5 × 7
## trees .metric .estimator mean n std_err .config
## <int> <chr> <chr> <dbl> <int> <dbl> <chr>
## 1 1552 rmse standard 0.486 10 0.0126 Preprocessor1_Model2
## 2 1858 rmse standard 0.486 10 0.0126 Preprocessor1_Model3
## 3 1117 rmse standard 0.486 10 0.0126 Preprocessor1_Model1
## 4 154 rmse standard 0.486 10 0.0119 Preprocessor1_Model4
## 5 577 rmse standard 0.486 10 0.0128 Preprocessor1_Model5
# Update the model by selecting the best hyper parameters.
ranger_fw <- tune::finalize_workflow(ranger_workflow,
tune::select_best(ranger_tune, metric = "rmse"))
# Fit the model on the entire training data and test it on test data.
data_fit <- tune::last_fit(ranger_fw, data_split)
tune::collect_metrics(data_fit)
## # A tibble: 2 × 4
## .metric .estimator .estimate .config
## <chr> <chr> <dbl> <chr>
## 1 rmse standard 0.495 Preprocessor1_Model1
## 2 rsq standard 0.863 Preprocessor1_Model1
tune::collect_predictions(data_fit) %>%
ggplot(aes(price, .pred)) +
geom_point(alpha = 0.3, fill = "midnightblue") +
geom_abline(lty = 2, color = "gray50") +
coord_fixed()