Skip to contents

Essentially is a call to parsnip::predict.model_fit, but also performs checks on the input data against the original model data used to fit the model.

Usage

tt_model_predict(model, x = NULL)

Arguments

model

Typing tool model, a model_fit object, output of shelf_make_tt_model.

x

A dataframe with features to predict segments by. By default, if left NULL, x field of model data will be used.

Examples

library(dplyr)
# randomly shuffle original data
new_x <- mutate_all(example_tt_model$data$x, sample)
tt_model_predict(example_tt_model, new_x)
#> → Checking provided features against the original feature set
#> ✔ Checking provided features against the original feature set ... done.
#> # A tibble: 100 × 1
#>    .pred_class
#>    <fct>      
#>  1 Red        
#>  2 Red        
#>  3 Green      
#>  4 Yellow     
#>  5 Red        
#>  6 Red        
#>  7 Green      
#>  8 Red        
#>  9 Yellow     
#> 10 Red        
#> # ℹ 90 more rows

# mess up the data and watch it complaining
new_x_corrupted <- new_x
new_x_corrupted$m2_1_5[7] <- 7
new_x_corrupted$m2_1_5[8] <- -1
attr(new_x_corrupted$m2_1_5, "labels") <- rev(attr(new_x$m2_1_5, "labels"))

tt_model_predict(example_tt_model, new_x_corrupted)
#> → Checking provided features against the original feature set
#> 
#> ! m2_1_5 values outside of the reference range -------
#> 
#> values
#> [1] -1  7
#> 
#> range
#> [ 1 ; 4 ]
#> ✔ Checking provided features against the original feature set ... done.
#> # A tibble: 100 × 1
#>    .pred_class
#>    <fct>      
#>  1 Red        
#>  2 Red        
#>  3 Green      
#>  4 Yellow     
#>  5 Red        
#>  6 Red        
#>  7 Green      
#>  8 Red        
#>  9 Yellow     
#> 10 Red        
#> # ℹ 90 more rows