knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
The explore package offers a simplified way to use machine learning and make a prediction.
explain_tree()
creates a decision treeexplain_forest()
creates a random forestexplain_logreg()
creates a logistic regressionpredict_target()
uses a model to make a predictionWe use synthetic data in this example
library(dplyr) library(explore) train <- create_data_buy(obs = 1000, seed = 1) glimpse(train)
First we create a decision tree model, using buy
as target (buy
contains only 0 and 1 values)
train %>% explain_tree(target = buy)
We see some clear patterns. Now we create a random forest model (as it is more accurate).
To get the model itself, use parameter out = "model"
model <- train %>% explain_forest(target = buy, out = "model")
Now we create test data and use the model for a prediction. We use a different seed so we get different data.
test <- create_data_buy(obs = 1000, seed = 2) glimpse(test)
test <- test %>% predict_target(model = model) glimpse(test)
Now we got 2 new variables prediction_0
(the probability of buy == 0
) and
prediction_1
(the probability of buy == 1
). We can check the predictions by comparing prediction_1
with real values of buy.
test %>% explore(prediction_1, target = buy)
There is a clear difference between buy == 0
and buy == 1
. So the prediction works.
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.