File size: 1,633 Bytes
0559035
b7d2fb4
 
 
df6fa2e
60fc559
df6fa2e
b7d2fb4
df6fa2e
b7d2fb4
df6fa2e
60fc559
b7d2fb4
 
 
 
 
60fc559
b7d2fb4
 
9df5c5b
b7d2fb4
 
 
 
 
 
 
 
9df5c5b
b7d2fb4
9df5c5b
b7d2fb4
f60a8ca
 
b7d2fb4
 
 
 
 
 
 
60fc559
b7d2fb4
9df5c5b
b7d2fb4
 
6104937
f60a8ca
b7d2fb4
 
 
 
 
 
aec9fc1
941a4c0
 
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
47
48
49
50
51
52
53
54
55
56
57
58
59
import pandas as pd
import numpy as np
import joblib
from flask import Flask,request,jsonify

app=Flask(__name__)

model=joblib.load('Churn_model_v1.joblib')

# let us create endpoint for home

@app.get('/')
def home():
  return "Welcome to the Backend API for Customer Churn Prediction"

# let us create endpoint for predict data record

@app.post('/Predict/Data')
def predict_data():
  data=request.get_json()

  user_input={ 'CreditScore':data['CreditScore'],
               'Geography':data['Geography'],
               'Age':data['Age'],
               'Tenure':data['Tenure'],
               'Balance':data['Balance'],
               'NumOfProducts':data['NumOfProducts'],
               'HasCrCard':data['HasCrCard'],
               'IsActiveMember':data['IsActiveMember'],
               'EstimatedSalary':data['EstimatedSalary']
                }

  df_user_input=pd.DataFrame([user_input])
  prediction1=model.predict_proba(df_user_input)[:,1]>0.21
  prediction=prediction1.tolist()[0]
  predict_label='Churn' if prediction==1 else 'Not Churn'

  return jsonify({'predict_label':predict_label})


# let us create endpoint for predicting batch data

@app.post('/Predict/Batch')
def predict_batch():

  file1=request.files['file']
  df_file=pd.read_csv(file1)
  prediction1=model.predict_proba(df_file.drop(['CustomerId','Surname'],axis=1))[:,1]>0.21
  prediction=prediction1.tolist()
  predictionlist=['Churn' if x==1 else 'Not Churn' for x in prediction]
  listofids=df_file.CustomerId.values.tolist()
  dictionary1=dict(zip(listofids,predictionlist))
  return dictionary1

if __name__=='__main__':
  app.run(debug=True)