Churn prediction is the task of identifying users that are likely to stop using a service, product or website. In this tutorial, you will learn how to:
In [2]:
import graphlab as gl
import datetime
gl.canvas.set_target('ipynb') # make sure plots appear inline
In [3]:
interactions_ts = gl.TimeSeries("data/user_activity_data.ts/")
users = gl.SFrame("data/users.sf/")
model = gl.load_model("data/churn_model.mdl")
In [4]:
(train, valid) = gl.churn_predictor.random_split(interactions_ts, user_id = 'CustomerID', fraction = 0.9, seed = 12)
In [5]:
churn_period_oct = datetime.datetime(year = 2011, month = 10, day = 1)
In [5]:
v = model.views.overview(train, churn_period_oct, valid, user_data=users)
v.show()
In [6]:
importance = model.get_feature_importance()
In [7]:
print "What are the top 5 factors that impact predictions?"
print "----------------------------------------------------"
print '\n'.join(["%s. %s" % (i+1, x) for i,x in enumerate(importance['description'][0:5])])
In [9]:
report = model.get_churn_report(interactions_ts, user_data=users)
report
Out[9]:
In [10]:
report['num_users'].show()
In [11]:
segment = report[report['segment_id'] == '2'][0]
In [14]:
print ""
print "Segment 2"
print "---------------------------------------"
print 'Segment size : %.2f %% of users' % segment["num_users_percentage"]
print 'Churn probability : %s' % segment["avg_probability"]
print ""
print "Characteristics of users in segment 2?"
print "-----------------------------------------------"
print "\n".join(['%s. %s' % (i + 1, x) for i, x in enumerate(segment["explanation"])])
In [15]:
particular_user = valid[valid['CustomerID'] == '16200']
particular_user
Out[15]:
In [16]:
explanations = model.explain(particular_user, user_data=users)
In [17]:
print ""
print "Model explanations"
print "---------------------------------------"
print 'Customer ID : %s' % explanations["CustomerID"]
print 'Churn probability : %s' % explanations["probability"]
print ""
print "Why did the model make this prediction?"
print "---------------------------------------"
print "\n".join(['%s. %s' % (i + 1, x) for i, x in enumerate(explanations["explanation"][0])])