0
$\begingroup$

I have customer training data set from telecom industry along with its test data set containing churn values 0 & 1 for each customer. I also have customer data set whose churn value is to be predicted ie 0 & 1. It is also required to get the churn prediction probability at individual customer level so that they can be arranged in descending order of the propensity to churn

For brevity, showing limited features cust_train.xls

cust_id Account Length VMail Message Day Mins Eve Mins Night Mins Intl Mins CustServ Calls

cust_train_output.xls

cust_id churn (0/1)

I want to know if it is possible to get the churn prediction probability at individual customer level & how by random forest algorithm rather than class level provided by: predict_proba(X) => Predict class probabilities for X.

Goal is to arrange the customer in descending order of the propensity to churn.

Alterntively, is this possible with Logistic Regression Model?

Thanks

$\endgroup$
  • $\begingroup$ It would be helpful to know how you are implementing the Random Forest. I suspect sci-kit learn. $\endgroup$ – Skiddles Nov 29 '18 at 16:00
0
$\begingroup$

I want to know if it is possible to get the churn prediction probability at individual customer level & how by random forest algorithm rather than class level provided by: predict_proba(X) => Predict class probabilities for X.

I think the predict_proba(X) is actually the correct method to accomplish your task. For each instance (person) the function will display the probability for each class label. So, if you know which class is churn, I'll just assume class 1, you just need to slice the results on that column. For example:

from sklearn.ensemble import RandomForestClassifier
from sklearn.datasets import make_classification
from tabulate import tabulate

X, y = make_classification(n_samples=1000, n_features=50,
                           n_informative=2, n_redundant=0,
                           random_state=1, shuffle=False)
clf = RandomForestClassifier(n_estimators=100, max_depth=2,
                             random_state=0)

clf.fit(X, y)

train_class_probability = clf.predict_proba(X)

print(tabulate(train_class_probability[0:4], ['Churn', 'No Churn']))

NewData, y = make_classification(n_samples=10, n_features=50,
                                 n_informative=2, n_redundant=0,
                                 random_state=1000, shuffle=False)
class_prediction = clf.predict(NewData)
class_probability = clf.predict_proba(NewData)

print(tabulate(class_prediction.reshape(-1, 1), ['0 - Churn / 1 - No-Churn']))
print(tabulate(class_probability, ['Churn', 'No Churn']))
# Just print the first column, Churn
print(tabulate(class_probability[:, 0].reshape(-1, 1), ['Probability of Churn']))

Output will be:

Class Probabilities of the Training Data (First four instances)

   Churn    No Churn
--------  ----------
0.595298    0.404702
0.620975    0.379025
0.601251    0.398749
0.610663    0.389337

Class Prediction on New Data

  0 - Churn / 1 - No-Churn
--------------------------
                         0
                         0
                         0
                         1
                         1
                         1
                         1
                         0
                         1
                         1

Class Probability Prediction on New Data

   Churn    No Churn
--------  ----------
0.553698    0.446302
0.602109    0.397891
0.587715    0.412285
0.423982    0.576018
0.419588    0.580412
0.419984    0.580016
0.369798    0.630202
0.572373    0.427627
0.414734    0.585266
0.40422     0.59578

Probability of Churn on New Data

  Probability of Churn
----------------------
              0.553698
              0.602109
              0.587715   <- new customer #3
              0.423982   <- new customer #4
              0.419588
              0.419984
              0.369798
              0.572373
              0.414734
              0.40422

So, the probability that "new customer #3" will churn is ~59% and the probability that "new customer #4" will churn is ~42%.

Hopefully, I have understood your question.

HTH

| improve this answer | |
$\endgroup$
  • $\begingroup$ Yep this is what I was looking for. Thank you. Apologies for deplay in getting back. $\endgroup$ – coolcoder Dec 3 '18 at 0:43

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.