Setup library
Upload data
Data preparation
dd <- d %>% select(MonthlyCharges,PaymentMethod,group_tenure,Churn)
dd$Churn <- as.numeric(mapvalues(dd$Churn,from=c("No","Yes"),
to=c("1", "2")))
dd$PaymentMethod <- as.factor(mapvalues(dd$PaymentMethod,
from=c("Bank transfer (automatic)","Credit card (automatic)","Electronic check","Mailed check"),
to=c("1","2","3","4")))
Data spliting
set.seed(1)
# randomly pick 70% of the number of observations (129)
index <- sample(1:nrow(dd),size = 0.7*nrow(dd))
# subset weather to include only the elements in the index
train <- dd[index,]
# subset weather to include all but the elements in the index
test <- dd[-index,]
Create model
set.seed(1)
churn_rf <- randomForest(Churn ~ PaymentMethod+group_tenure, data = train, method="rf", ntree = 100)
plot(churn_rf)

Explainer
Variable importance
vi_regr_rf <- variable_importance(explainer_regr_rf, loss_function = loss_root_mean_square)
plot(vi_regr_rf ) #ok

Variable response
pdp_regr_rf <- variable_response(explainer_regr_rf, variable = "PaymentMethod", type = "factor")
plot(pdp_regr_rf) #ok
## Scale for 'x' is already present. Adding another scale for 'x', which will
## replace the existing scale.

Prediction of no churn use breakdown
plot(p_explainer_regr_rf)#ok
