-
-
Notifications
You must be signed in to change notification settings - Fork 101
/
Copy pathchurn_serving_simple.py
46 lines (36 loc) · 1015 Bytes
/
churn_serving_simple.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import pickle
import numpy as np
def predict_single(customer, dv, model):
X = dv.transform([customer])
y_pred = model.predict_proba(X)[:, 1]
return y_pred[0]
with open('churn-model.bin', 'rb') as f_in:
dv, model = pickle.load(f_in)
customer = {
'customerid': '8879-zkjof',
'gender': 'female',
'seniorcitizen': 0,
'partner': 'no',
'dependents': 'no',
'tenure': 41,
'phoneservice': 'yes',
'multiplelines': 'no',
'internetservice': 'dsl',
'onlinesecurity': 'yes',
'onlinebackup': 'no',
'deviceprotection': 'yes',
'techsupport': 'yes',
'streamingtv': 'yes',
'streamingmovies': 'yes',
'contract': 'one_year',
'paperlessbilling': 'yes',
'paymentmethod': 'bank_transfer_(automatic)',
'monthlycharges': 79.85,
'totalcharges': 3320.75,
}
prediction = predict_single(customer, dv, model)
print('prediction: %.3f' % prediction)
if prediction >= 0.5:
print('verdict: Churn')
else:
print('verdict: Not churn')