Skip to content

predicting using trained model #280

Answered by kelly-sovacool
jdperera asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, you can do this!

library(dplyr)
library(mikropml)
# in this example, otu_mini_bin is your original dataset used for training the model
results <- run_ml(otu_mini_bin,
                  'glmnet',
                  outcome_colname = 'dx',
                  seed = 2019)

# for the sake of this example, let's use `test_data` and remove the outcome column.
# in the real world, this would be a separate dataset such as from a different hospital.
new_data <- results$test_data %>% select(-dx)
predictions <- predict(results$trained_model, new_data, type = 'prob')
head(predictions)
#>      cancer    normal
#> 1 0.4705888 0.5294112
#> 2 0.4886979 0.5113021
#> 3 0.5130865 0.4869135
#> 4 0.5291845…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@jdperera
Comment options

Answer selected by kelly-sovacool
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants