Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new model: Customer Churn Prediction #64

Merged
merged 6 commits into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions form_configs/churn_detection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"Churn Detection Form": {
"Credit Score": {
"type": "number",
"min_value": 0,
"max_value": 1000,
"default_value": 0,
"step": 10,
"field_name": "credit_score"
},
"Geography": {
"type": "dropdown",
"options": ["France", "Germany","Spain"],
"default_value": "No",
"field_name": "geography"
},
"Gender": {
"type": "dropdown",
"options": ["Female", "Male"],
"default_value": "No",
"field_name": "gender"
},
"Age": {
"type": "number",
"min_value": 0,
"max_value": 100,
"default_value": 0,
"step": 1,
"field_name": "age"
},
"Tenure": {
"type": "number",
"min_value": 0,
"max_value": 30,
"default_value": 0,
"step": 1,
"field_name": "tenure"
},
"Balance": {
"type": "float",
"min_value": 0.0,
"max_value": 1000000.0,
"default_value": 0,
"step": 10.5,
"field_name": "balance"
},
"Number Of Products": {
"type": "number",
"min_value": 0,
"max_value": 10,
"default_value": 0.0,
"step": 1,
"field_name": "number_of_products"
},
"Has Credit Card": {
"type": "dropdown",
"field_name": "has_credit_card",
"options": ["Yes","No"],
"default_value": "No"
},
"Is Active Member": {
"type": "dropdown",
"field_name": "is_active_member",
"options": ["Yes","No"],
"default_value": "No"
},
"Estimated Salary": {
"type": "float",
"min_value": 0.0,
"max_value": 1000000.0,
"default_value": 0.0,
"step": 10.5,
"field_name": "estimated_salary"
}

}
}

20 changes: 20 additions & 0 deletions models/Customer_Churn_Prediction/Model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import joblib
import numpy as np


model = joblib.load('models/Customer_Churn_Prediction/saved_models/Gradient_Boosting_Classifier.joblib')
scaler = joblib.load('models/Customer_Churn_Prediction/saved_models/scaler.joblib')

def customer_churn_prediction(cs,geo,gen,age,tenure,bal,nop,hcc,iam,es):
features = {'CreditScore':cs,'Geography':geo,'Gender':gen,'Age':age,'Tenure':tenure,'Balance':bal,'NumOfProducts':nop,'HasCrCard':hcc,'IsActiveMember':iam,'EstimatedSalary':es}
geography_map = {'France': 0, 'Spain': 1, 'Germany': 2}
gender_map = {'Female': 0, 'Male': 1}
features['Geography'] = geography_map[features['Geography']]
features['Gender'] = gender_map[features['Gender']]
input_array = np.array(list(features.values())).reshape(1, -1)
scaled_input = scaler.transform(input_array)
preprocessed_input = scaled_input
prediction = model.predict(preprocessed_input)
probability = model.predict_proba(preprocessed_input)[0][1]
print(prediction)
return prediction[0], probability
13 changes: 13 additions & 0 deletions models/Customer_Churn_Prediction/Predict.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from models.Customer_Churn_Prediction.Model import customer_churn_prediction
def get_prediction(cs,geo,gen,age,tenure,bal,nop,hcc,iam,es):
prediction,probability=customer_churn_prediction(cs,geo,gen,age,tenure,bal,nop,hcc,iam,es)
output=""
if prediction == 1:
output=f"The customer is likely to churn with a probability of {probability:.2f}"
else:
output=f"The customer is likely to stay with a probability of {1-probability:.2f}"
return output




10,001 changes: 10,001 additions & 0 deletions models/Customer_Churn_Prediction/data/Churn_Modelling.csv

Large diffs are not rendered by default.

Loading