Update README.md
Browse files
README.md
CHANGED
|
@@ -61,24 +61,71 @@ The complete training and evaluation notebook is available on GitHub:
|
|
| 61 |
π [View on GitHub](https://github.com/joyjitroy/Machine_Learning/blob/main/Bank_Customer_Churn_Prediction_using_Artificial_Neural_Networks.ipynb)
|
| 62 |
|
| 63 |
---
|
|
|
|
| 64 |
|
| 65 |
-
## π Example Usage
|
| 66 |
```python
|
| 67 |
-
|
|
|
|
|
|
|
| 68 |
import numpy as np
|
| 69 |
|
| 70 |
-
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
sample = np.array([[600, 40, 3, 60000, 2, 1, 1, 50000, 0, 1, 1]])
|
| 76 |
|
| 77 |
-
|
| 78 |
-
pred
|
| 79 |
-
print("Churn Probability:", pred[0][0])
|
| 80 |
|
| 81 |
-
if pred[0][0] > 0.5:
|
| 82 |
-
print("Prediction: Customer likely to churn")
|
| 83 |
-
else:
|
| 84 |
-
print("Prediction: Customer likely to stay")
|
|
|
|
| 61 |
π [View on GitHub](https://github.com/joyjitroy/Machine_Learning/blob/main/Bank_Customer_Churn_Prediction_using_Artificial_Neural_Networks.ipynb)
|
| 62 |
|
| 63 |
---
|
| 64 |
+
## π Example Usage
|
| 65 |
|
|
|
|
| 66 |
```python
|
| 67 |
+
# Inference example aligned to your dataset schema
|
| 68 |
+
|
| 69 |
+
import pandas as pd
|
| 70 |
import numpy as np
|
| 71 |
|
| 72 |
+
CSV_PATH = "Data/Churn.csv"
|
| 73 |
+
TARGET = "Exited"
|
| 74 |
+
|
| 75 |
+
# Columns exactly as in your table
|
| 76 |
+
ALL_COLS = [
|
| 77 |
+
"CustomerId","Surname","CreditScore","Geography","Gender","Age","Tenure",
|
| 78 |
+
"NumOfProducts","Balance","HasCrCard","EstimatedSalary","IsActiveMember","Exited"
|
| 79 |
+
]
|
| 80 |
+
|
| 81 |
+
NUM_COLS = ["CreditScore","Age","Tenure","NumOfProducts","Balance","EstimatedSalary","HasCrCard","IsActiveMember"]
|
| 82 |
+
CAT_COLS = ["Geography","Gender"]
|
| 83 |
+
DROP_COLS = ["CustomerId","Surname"]
|
| 84 |
+
|
| 85 |
+
# Load data
|
| 86 |
+
df = pd.read_csv(CSV_PATH)[ALL_COLS]
|
| 87 |
+
|
| 88 |
+
def prepare_features(df_in, fit_cols=None):
|
| 89 |
+
X = df_in.drop(columns=[TARGET] + DROP_COLS).copy()
|
| 90 |
+
# one hot on the two categoricals
|
| 91 |
+
X = pd.get_dummies(X, columns=CAT_COLS, drop_first=True)
|
| 92 |
+
# align to training columns
|
| 93 |
+
if fit_cols is not None:
|
| 94 |
+
X = X.reindex(columns=fit_cols, fill_value=0)
|
| 95 |
+
return X
|
| 96 |
+
|
| 97 |
+
# If you trained in this notebook, reuse `model` and `feature_cols` from training:
|
| 98 |
+
# model.save("bank_churn_ann.keras")
|
| 99 |
+
# feature_cols = X_train.columns.tolist()
|
| 100 |
+
|
| 101 |
+
# If loading a saved model:
|
| 102 |
+
# from tensorflow.keras.models import load_model
|
| 103 |
+
# model = load_model("bank_churn_ann.keras")
|
| 104 |
+
# feature_cols = [...] # same list you used during training after get_dummies
|
| 105 |
+
|
| 106 |
+
# Single example constructed with your schema
|
| 107 |
+
example = {
|
| 108 |
+
"CustomerId": 15788241,
|
| 109 |
+
"Surname": "Smith",
|
| 110 |
+
"CreditScore": 600,
|
| 111 |
+
"Geography": "Germany", # France, Germany, Spain in this dataset
|
| 112 |
+
"Gender": "Male", # Male or Female
|
| 113 |
+
"Age": 40,
|
| 114 |
+
"Tenure": 3,
|
| 115 |
+
"NumOfProducts": 2,
|
| 116 |
+
"Balance": 60000.0,
|
| 117 |
+
"HasCrCard": 1,
|
| 118 |
+
"EstimatedSalary": 50000.0,
|
| 119 |
+
"IsActiveMember": 1,
|
| 120 |
+
"Exited": 0 # ignored at inference
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
ex_df = pd.DataFrame([example])
|
| 124 |
+
X_ex = prepare_features(ex_df, fit_cols=feature_cols)
|
| 125 |
|
| 126 |
+
pred_prob = float(model.predict(X_ex, verbose=0)[0][0])
|
| 127 |
+
pred = int(pred_prob >= 0.5)
|
|
|
|
| 128 |
|
| 129 |
+
print(f"Churn Probability: {pred_prob:.4f}")
|
| 130 |
+
print("Prediction:", "Likely to churn" if pred else "Likely to stay")
|
|
|
|
| 131 |
|
|
|
|
|
|
|
|
|
|
|
|