# Supervised Binning with Naive Bayes

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:

head(data)
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:

library("klaR")
library("caret")

rn_train <- sample(nrow(data),
floor(nrow(data)*0.7))

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?)