Context. I am working on a model to predict "churn". Subscription service where users pay a monthly fee to access the service. We would like to predict which accounts are likely to cancel or "churn".

One of the variables in the model is "months of service" aka "length of subscription". Since this is numerical data I was not sure how to work with it in the context of this model. I read about "binning" where you split the numerical data into categories based on some pre determined cut offs e.g. "low", "medium" or "long". I was reading a post here.

In that post they talk about "entropy based binning". That makes sense at a high level, find the split that leads to the greatest information gain wrt class label.

My question is, how would I actually implement this using R?

If this is what my data look like:

 eid months_subscription     medium revenue     churned
1 904056                   1    unknown      40 not churned
2 905290                   8        cpc      40     churned
3 905434                   1        cpc      70 not churned
4 905472                  20        cpc      40 not churned
5 905524                   1   referral      70    churned
6 905590                   0       none      40 not churned

Here is my simple model:


data_imp <- read.csv("data.csv")

rn_train <- sample(nrow(data),

train <- data[rn_train,]
test <- data[-rn_train,]

model <- NaiveBayes(churned ~., data=train)

predictions <- predict(model, test)

confusionMatrix(test$churned, predictions$class)

How would I apply this entropy based method of binning the variable "months_subscription" using R? (Do I want to bin this variable?)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.