AbhishekShrimali commited on
Commit
6f4597e
Β·
verified Β·
1 Parent(s): e483eed

Upload 7 files

Browse files
Dataset/Churn_Modelling.csv ADDED
The diff for this file is too large to render. See raw diff
 
Requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ streamlit
2
+ tensorflow
3
+ numpy
4
+ pandas
5
+ scikit-learn
6
+ joblib
7
+
Scaler/scaler.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:674b9f3f1a9277fbb786dc270fc4d96044ae4b38782e59671b456e342aa79000
3
+ size 1239
Trained Model/churn_prediction_model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8f9ffaedf97712c45955a5933b567769ce2bfa7f93a6bfc037dd5ca80a885225
3
+ size 37960
Trained Model/churn_prediction_model.keras ADDED
Binary file (31 kB). View file
 
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import numpy as np
3
+ import tensorflow as tf
4
+ import pandas as pd
5
+ import joblib
6
+ from sklearn.preprocessing import StandardScaler
7
+
8
+ # load the trained model
9
+ @st.cache_resource
10
+ def load_model():
11
+ return tf.keras.models.load_model("Trained Model/churn_prediction_model.keras")
12
+ model = load_model()
13
+
14
+ # load the saved scaler
15
+ scaler = joblib.load("Scaler/scaler.pkl")
16
+ st.title("Customer Churn Prediciton")
17
+ st.markdown("<h6 style='text-align: right; color: gray;'>Developed by Abhishek</h6>", unsafe_allow_html=True)
18
+ st.write("Enter customer details to predict churn")
19
+
20
+ # creating input fields
21
+ input = []
22
+ dataset = pd.read_csv("Dataset/Churn_Modelling.csv")
23
+ dataset.drop(["RowNumber","Empty","CustomerId","Geography","Gender"], axis = 1, inplace = True)
24
+ columns = [
25
+ ("Credit Score", "CreditScore", 650),
26
+ ("Age", "Age", 30),
27
+ ("Tenure (Years)", "Tenure", 5),
28
+ ("Account Balance", "Balance", 100000),
29
+ ("Number of Products", "NumOfProducts", 1),
30
+ ("Has Credit Card (1=Yes, 0=No)", "HasCrCard", 1),
31
+ ("Is Active Member (1=Yes, 0=No)", "IsActiveMember", 1),
32
+ ("Estimated Salary", "EstimatedSalary", 50000)
33
+ ]
34
+ for label, col, default in columns:
35
+ value = st.number_input(label, value=float(default), format="%.2f")
36
+ input.append(value)
37
+
38
+ if st.button("Predict Churn"):
39
+ input_array = np.array([input])
40
+ input_scaled = scaler.transform(input_array)
41
+ prediction = model.predict(input_scaled)
42
+ result = "Churn" if prediction[0][0]>0.5 else "No Churn"
43
+ st.write(f"### Prediction: {result}")
44
+
churn prediction model.ipynb ADDED
@@ -0,0 +1,607 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": null,
6
+ "metadata": {},
7
+ "outputs": [
8
+ {
9
+ "name": "stdout",
10
+ "output_type": "stream",
11
+ "text": [
12
+ " RowNumber CustomerId Empty CreditScore Geography Gender Age Tenure \\\n",
13
+ "0 1 15634602 NaN 619 France Female 42 2 \n",
14
+ "1 2 15647311 NaN 608 Spain Female 41 1 \n",
15
+ "2 3 15619304 NaN 502 France Female 42 8 \n",
16
+ "3 4 15701354 NaN 699 France Female 39 1 \n",
17
+ "4 5 15737888 NaN 850 Spain Female 43 2 \n",
18
+ "\n",
19
+ " Balance NumOfProducts HasCrCard IsActiveMember EstimatedSalary \\\n",
20
+ "0 0.00 1 1 1 101348.88 \n",
21
+ "1 83807.86 1 0 1 112542.58 \n",
22
+ "2 159660.80 3 1 0 113931.57 \n",
23
+ "3 0.00 2 0 0 93826.63 \n",
24
+ "4 125510.82 1 1 1 79084.10 \n",
25
+ "\n",
26
+ " Exited \n",
27
+ "0 1 \n",
28
+ "1 0 \n",
29
+ "2 1 \n",
30
+ "3 0 \n",
31
+ "4 0 \n"
32
+ ]
33
+ },
34
+ {
35
+ "data": {
36
+ "text/plain": [
37
+ "np.int64(10000)"
38
+ ]
39
+ },
40
+ "execution_count": 1,
41
+ "metadata": {},
42
+ "output_type": "execute_result"
43
+ }
44
+ ],
45
+ "source": [
46
+ "import pandas as pd\n",
47
+ "from sklearn.preprocessing import StandardScaler\n",
48
+ "\n",
49
+ "dataset = pd.read_csv(\"Dataset/Churn_Modelling.csv\")\n",
50
+ "print(dataset.head())\n",
51
+ "dataset.isnull().sum().sum()\n"
52
+ ]
53
+ },
54
+ {
55
+ "cell_type": "code",
56
+ "execution_count": 2,
57
+ "metadata": {},
58
+ "outputs": [],
59
+ "source": [
60
+ "dataset.drop([\"RowNumber\",\"Empty\",\"CustomerId\",\"Geography\",\"Gender\"], axis = 1,inplace = True)"
61
+ ]
62
+ },
63
+ {
64
+ "cell_type": "code",
65
+ "execution_count": 3,
66
+ "metadata": {},
67
+ "outputs": [],
68
+ "source": [
69
+ "input_data = dataset.iloc[:,: -1]\n",
70
+ "output_data = dataset.iloc[:, -1]"
71
+ ]
72
+ },
73
+ {
74
+ "cell_type": "code",
75
+ "execution_count": 4,
76
+ "metadata": {},
77
+ "outputs": [],
78
+ "source": [
79
+ "## standardiazation \n",
80
+ "ssl = StandardScaler()\n",
81
+ "input_data = pd.DataFrame(ssl.fit_transform(input_data),columns = input_data.columns)\n"
82
+ ]
83
+ },
84
+ {
85
+ "cell_type": "code",
86
+ "execution_count": 5,
87
+ "metadata": {},
88
+ "outputs": [
89
+ {
90
+ "name": "stdout",
91
+ "output_type": "stream",
92
+ "text": [
93
+ "Shapes after splitting:\n",
94
+ "X_train: (8000, 8)\n",
95
+ "y_train: (8000,)\n",
96
+ "X_test: (2000, 8)\n",
97
+ "y_test: (2000,)\n"
98
+ ]
99
+ }
100
+ ],
101
+ "source": [
102
+ "# train test split\n",
103
+ "from sklearn.model_selection import train_test_split\n",
104
+ "x_train, x_test, y_train, y_test = train_test_split(input_data,output_data , test_size= 0.2 , random_state= 42)\n",
105
+ "\n",
106
+ "print(\"Shapes after splitting:\")\n",
107
+ "print(\"X_train:\", x_train.shape)\n",
108
+ "print(\"y_train:\", y_train.shape)\n",
109
+ "print(\"X_test:\", x_test.shape)\n",
110
+ "print(\"y_test:\", y_test.shape)\n"
111
+ ]
112
+ },
113
+ {
114
+ "cell_type": "code",
115
+ "execution_count": 6,
116
+ "metadata": {},
117
+ "outputs": [],
118
+ "source": [
119
+ "# building ann \n",
120
+ "import tensorflow\n",
121
+ "from keras.layers import Dense\n",
122
+ "from keras.models import Sequential"
123
+ ]
124
+ },
125
+ {
126
+ "cell_type": "code",
127
+ "execution_count": 7,
128
+ "metadata": {},
129
+ "outputs": [
130
+ {
131
+ "name": "stderr",
132
+ "output_type": "stream",
133
+ "text": [
134
+ "c:\\Users\\abhis\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\keras\\src\\layers\\core\\dense.py:87: UserWarning: Do not pass an `input_shape`/`input_dim` argument to a layer. When using Sequential models, prefer using an `Input(shape)` object as the first layer in the model instead.\n",
135
+ " super().__init__(activity_regularizer=activity_regularizer, **kwargs)\n"
136
+ ]
137
+ }
138
+ ],
139
+ "source": [
140
+ "ann = Sequential()\n",
141
+ "ann.add(Dense(6, input_dim = 8, activation= \"relu\"))\n",
142
+ "ann.add(Dense(4, activation= \"relu\"))\n",
143
+ "ann.add(Dense(2, activation= \"relu\"))\n",
144
+ "ann.add(Dense(1, activation= \"sigmoid\"))"
145
+ ]
146
+ },
147
+ {
148
+ "cell_type": "code",
149
+ "execution_count": 8,
150
+ "metadata": {},
151
+ "outputs": [],
152
+ "source": [
153
+ "ann.compile(optimizer= \"adam\", loss = \"binary_crossentropy\", metrics = [\"accuracy\"])\n"
154
+ ]
155
+ },
156
+ {
157
+ "cell_type": "code",
158
+ "execution_count": 9,
159
+ "metadata": {},
160
+ "outputs": [
161
+ {
162
+ "name": "stdout",
163
+ "output_type": "stream",
164
+ "text": [
165
+ "Epoch 1/50\n",
166
+ "\u001b[1m80/80\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m2s\u001b[0m 2ms/step - accuracy: 0.8023 - loss: 0.5640\n",
167
+ "Epoch 2/50\n",
168
+ "\u001b[1m80/80\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 2ms/step - accuracy: 0.7947 - loss: 0.4930\n",
169
+ "Epoch 3/50\n",
170
+ "\u001b[1m80/80\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 2ms/step - accuracy: 0.7971 - loss: 0.4660\n",
171
+ "Epoch 4/50\n",
172
+ "\u001b[1m80/80\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 2ms/step - accuracy: 0.7970 - loss: 0.4533\n",
173
+ "Epoch 5/50\n",
174
+ "\u001b[1m80/80\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 2ms/step - accuracy: 0.7918 - loss: 0.4495\n",
175
+ "Epoch 6/50\n",
176
+ "\u001b[1m80/80\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 2ms/step - accuracy: 0.7924 - loss: 0.4447\n",
177
+ "Epoch 7/50\n",
178
+ "\u001b[1m80/80\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 2ms/step - accuracy: 0.7970 - loss: 0.4367\n",
179
+ "Epoch 8/50\n",
180
+ "\u001b[1m80/80\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 2ms/step - accuracy: 0.7936 - loss: 0.4407\n",
181
+ "Epoch 9/50\n",
182
+ "\u001b[1m80/80\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 2ms/step - accuracy: 0.7878 - loss: 0.4429\n",
183
+ "Epoch 10/50\n",
184
+ "\u001b[1m80/80\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 2ms/step - accuracy: 0.7970 - loss: 0.4297\n",
185
+ "Epoch 11/50\n",
186
+ "\u001b[1m80/80\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 2ms/step - accuracy: 0.7901 - loss: 0.4330\n",
187
+ "Epoch 12/50\n",
188
+ "\u001b[1m80/80\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 2ms/step - accuracy: 0.7954 - loss: 0.4227\n",
189
+ "Epoch 13/50\n",
190
+ "\u001b[1m80/80\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 2ms/step - accuracy: 0.7922 - loss: 0.4289\n",
191
+ "Epoch 14/50\n",
192
+ "\u001b[1m80/80\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 3ms/step - accuracy: 0.8070 - loss: 0.4167\n",
193
+ "Epoch 15/50\n",
194
+ "\u001b[1m80/80\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 3ms/step - accuracy: 0.8193 - loss: 0.4184\n",
195
+ "Epoch 16/50\n",
196
+ "\u001b[1m80/80\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 3ms/step - accuracy: 0.8175 - loss: 0.4197\n",
197
+ "Epoch 17/50\n",
198
+ "\u001b[1m80/80\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 2ms/step - accuracy: 0.8182 - loss: 0.4139\n",
199
+ "Epoch 18/50\n",
200
+ "\u001b[1m80/80\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 2ms/step - accuracy: 0.8127 - loss: 0.4322\n",
201
+ "Epoch 19/50\n",
202
+ "\u001b[1m80/80\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 2ms/step - accuracy: 0.8181 - loss: 0.4128\n",
203
+ "Epoch 20/50\n",
204
+ "\u001b[1m80/80\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 2ms/step - accuracy: 0.8202 - loss: 0.4235\n",
205
+ "Epoch 21/50\n",
206
+ "\u001b[1m80/80\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 2ms/step - accuracy: 0.8172 - loss: 0.4202\n",
207
+ "Epoch 22/50\n",
208
+ "\u001b[1m80/80\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 2ms/step - accuracy: 0.8325 - loss: 0.3909\n",
209
+ "Epoch 23/50\n",
210
+ "\u001b[1m80/80\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 2ms/step - accuracy: 0.8237 - loss: 0.4101\n",
211
+ "Epoch 24/50\n",
212
+ "\u001b[1m80/80\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 2ms/step - accuracy: 0.8311 - loss: 0.4025\n",
213
+ "Epoch 25/50\n",
214
+ "\u001b[1m80/80\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 2ms/step - accuracy: 0.8303 - loss: 0.4055\n",
215
+ "Epoch 26/50\n",
216
+ "\u001b[1m80/80\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 2ms/step - accuracy: 0.8343 - loss: 0.3941\n",
217
+ "Epoch 27/50\n",
218
+ "\u001b[1m80/80\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 2ms/step - accuracy: 0.8289 - loss: 0.4029\n",
219
+ "Epoch 28/50\n",
220
+ "\u001b[1m80/80\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 2ms/step - accuracy: 0.8345 - loss: 0.3982\n",
221
+ "Epoch 29/50\n",
222
+ "\u001b[1m80/80\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 2ms/step - accuracy: 0.8399 - loss: 0.3928\n",
223
+ "Epoch 30/50\n",
224
+ "\u001b[1m80/80\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 2ms/step - accuracy: 0.8349 - loss: 0.3970\n",
225
+ "Epoch 31/50\n",
226
+ "\u001b[1m80/80\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 2ms/step - accuracy: 0.8455 - loss: 0.3846\n",
227
+ "Epoch 32/50\n",
228
+ "\u001b[1m80/80\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 2ms/step - accuracy: 0.8465 - loss: 0.3733\n",
229
+ "Epoch 33/50\n",
230
+ "\u001b[1m80/80\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 2ms/step - accuracy: 0.8397 - loss: 0.3904\n",
231
+ "Epoch 34/50\n",
232
+ "\u001b[1m80/80\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 2ms/step - accuracy: 0.8401 - loss: 0.3864\n",
233
+ "Epoch 35/50\n",
234
+ "\u001b[1m80/80\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 2ms/step - accuracy: 0.8491 - loss: 0.3753\n",
235
+ "Epoch 36/50\n",
236
+ "\u001b[1m80/80\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 2ms/step - accuracy: 0.8478 - loss: 0.3714\n",
237
+ "Epoch 37/50\n",
238
+ "\u001b[1m80/80\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 2ms/step - accuracy: 0.8497 - loss: 0.3709\n",
239
+ "Epoch 38/50\n",
240
+ "\u001b[1m80/80\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 2ms/step - accuracy: 0.8513 - loss: 0.3698\n",
241
+ "Epoch 39/50\n",
242
+ "\u001b[1m80/80\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 2ms/step - accuracy: 0.8527 - loss: 0.3696\n",
243
+ "Epoch 40/50\n",
244
+ "\u001b[1m80/80\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 2ms/step - accuracy: 0.8612 - loss: 0.3533\n",
245
+ "Epoch 41/50\n",
246
+ "\u001b[1m80/80\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 2ms/step - accuracy: 0.8559 - loss: 0.3661\n",
247
+ "Epoch 42/50\n",
248
+ "\u001b[1m80/80\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 2ms/step - accuracy: 0.8538 - loss: 0.3576\n",
249
+ "Epoch 43/50\n",
250
+ "\u001b[1m80/80\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 2ms/step - accuracy: 0.8521 - loss: 0.3696\n",
251
+ "Epoch 44/50\n",
252
+ "\u001b[1m80/80\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 2ms/step - accuracy: 0.8591 - loss: 0.3591\n",
253
+ "Epoch 45/50\n",
254
+ "\u001b[1m80/80\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 2ms/step - accuracy: 0.8499 - loss: 0.3689\n",
255
+ "Epoch 46/50\n",
256
+ "\u001b[1m80/80\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 2ms/step - accuracy: 0.8523 - loss: 0.3640\n",
257
+ "Epoch 47/50\n",
258
+ "\u001b[1m80/80\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━��\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 2ms/step - accuracy: 0.8541 - loss: 0.3567\n",
259
+ "Epoch 48/50\n",
260
+ "\u001b[1m80/80\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 2ms/step - accuracy: 0.8563 - loss: 0.3632\n",
261
+ "Epoch 49/50\n",
262
+ "\u001b[1m80/80\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 2ms/step - accuracy: 0.8524 - loss: 0.3694\n",
263
+ "Epoch 50/50\n",
264
+ "\u001b[1m80/80\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 2ms/step - accuracy: 0.8427 - loss: 0.3741\n"
265
+ ]
266
+ },
267
+ {
268
+ "data": {
269
+ "text/plain": [
270
+ "<keras.src.callbacks.history.History at 0x57a56ae0>"
271
+ ]
272
+ },
273
+ "execution_count": 9,
274
+ "metadata": {},
275
+ "output_type": "execute_result"
276
+ }
277
+ ],
278
+ "source": [
279
+ "ann.fit(x_train, y_train, batch_size= 100 , epochs = 50)"
280
+ ]
281
+ },
282
+ {
283
+ "cell_type": "code",
284
+ "execution_count": 10,
285
+ "metadata": {},
286
+ "outputs": [
287
+ {
288
+ "name": "stdout",
289
+ "output_type": "stream",
290
+ "text": [
291
+ "\u001b[1m63/63\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 2ms/step\n"
292
+ ]
293
+ }
294
+ ],
295
+ "source": [
296
+ "# to find the accuracy \n",
297
+ "prd = ann.predict(x_test)\n",
298
+ "prd_data = []\n",
299
+ "for i in prd:\n",
300
+ " if i[0]>0.5:\n",
301
+ " prd_data.append(1)\n",
302
+ " else:\n",
303
+ " prd_data.append(0)"
304
+ ]
305
+ },
306
+ {
307
+ "cell_type": "code",
308
+ "execution_count": 11,
309
+ "metadata": {},
310
+ "outputs": [
311
+ {
312
+ "name": "stdout",
313
+ "output_type": "stream",
314
+ "text": [
315
+ "\u001b[1m250/250\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 993us/step\n"
316
+ ]
317
+ }
318
+ ],
319
+ "source": [
320
+ "prd1 = ann.predict(x_train)\n",
321
+ "prd_data1 = []\n",
322
+ "for i in prd1:\n",
323
+ " if i[0]>0.5:\n",
324
+ " prd_data1.append(1)\n",
325
+ " else:\n",
326
+ " prd_data1.append(0)"
327
+ ]
328
+ },
329
+ {
330
+ "cell_type": "code",
331
+ "execution_count": 12,
332
+ "metadata": {},
333
+ "outputs": [
334
+ {
335
+ "name": "stdout",
336
+ "output_type": "stream",
337
+ "text": [
338
+ "(accuracy on testing data 85.35000000000001\n",
339
+ "(accuraacy on training data 85.5\n"
340
+ ]
341
+ }
342
+ ],
343
+ "source": [
344
+ "from sklearn.metrics import accuracy_score\n",
345
+ "# testing accuracy\n",
346
+ "print(f\"(accuracy on testing data {accuracy_score(y_test, prd_data)*100}\")\n",
347
+ "# training accuracy (to check overfitting)\n",
348
+ "print(f\"(accuraacy on training data {accuracy_score(y_train, prd_data1)*100}\")\n"
349
+ ]
350
+ },
351
+ {
352
+ "cell_type": "code",
353
+ "execution_count": 13,
354
+ "metadata": {},
355
+ "outputs": [
356
+ {
357
+ "data": {
358
+ "text/html": [
359
+ "<div>\n",
360
+ "<style scoped>\n",
361
+ " .dataframe tbody tr th:only-of-type {\n",
362
+ " vertical-align: middle;\n",
363
+ " }\n",
364
+ "\n",
365
+ " .dataframe tbody tr th {\n",
366
+ " vertical-align: top;\n",
367
+ " }\n",
368
+ "\n",
369
+ " .dataframe thead th {\n",
370
+ " text-align: right;\n",
371
+ " }\n",
372
+ "</style>\n",
373
+ "<table border=\"1\" class=\"dataframe\">\n",
374
+ " <thead>\n",
375
+ " <tr style=\"text-align: right;\">\n",
376
+ " <th></th>\n",
377
+ " <th>CreditScore</th>\n",
378
+ " <th>Age</th>\n",
379
+ " <th>Tenure</th>\n",
380
+ " <th>Balance</th>\n",
381
+ " <th>NumOfProducts</th>\n",
382
+ " <th>HasCrCard</th>\n",
383
+ " <th>IsActiveMember</th>\n",
384
+ " <th>EstimatedSalary</th>\n",
385
+ " </tr>\n",
386
+ " </thead>\n",
387
+ " <tbody>\n",
388
+ " <tr>\n",
389
+ " <th>9254</th>\n",
390
+ " <td>0.367013</td>\n",
391
+ " <td>-0.660018</td>\n",
392
+ " <td>0.341352</td>\n",
393
+ " <td>-1.225848</td>\n",
394
+ " <td>0.807737</td>\n",
395
+ " <td>0.646092</td>\n",
396
+ " <td>0.970243</td>\n",
397
+ " <td>1.373784</td>\n",
398
+ " </tr>\n",
399
+ " <tr>\n",
400
+ " <th>1561</th>\n",
401
+ " <td>-0.191713</td>\n",
402
+ " <td>0.293517</td>\n",
403
+ " <td>-0.350204</td>\n",
404
+ " <td>0.691389</td>\n",
405
+ " <td>0.807737</td>\n",
406
+ " <td>0.646092</td>\n",
407
+ " <td>0.970243</td>\n",
408
+ " <td>1.667407</td>\n",
409
+ " </tr>\n",
410
+ " <tr>\n",
411
+ " <th>1670</th>\n",
412
+ " <td>-0.947028</td>\n",
413
+ " <td>-1.422847</td>\n",
414
+ " <td>-0.695982</td>\n",
415
+ " <td>0.613102</td>\n",
416
+ " <td>-0.911583</td>\n",
417
+ " <td>0.646092</td>\n",
418
+ " <td>-1.030670</td>\n",
419
+ " <td>-0.246910</td>\n",
420
+ " </tr>\n",
421
+ " <tr>\n",
422
+ " <th>6087</th>\n",
423
+ " <td>-0.926334</td>\n",
424
+ " <td>-1.136786</td>\n",
425
+ " <td>1.378686</td>\n",
426
+ " <td>0.948021</td>\n",
427
+ " <td>-0.911583</td>\n",
428
+ " <td>0.646092</td>\n",
429
+ " <td>-1.030670</td>\n",
430
+ " <td>0.921446</td>\n",
431
+ " </tr>\n",
432
+ " <tr>\n",
433
+ " <th>6669</th>\n",
434
+ " <td>-1.381593</td>\n",
435
+ " <td>1.628468</td>\n",
436
+ " <td>1.378686</td>\n",
437
+ " <td>1.052363</td>\n",
438
+ " <td>-0.911583</td>\n",
439
+ " <td>-1.547768</td>\n",
440
+ " <td>-1.030670</td>\n",
441
+ " <td>-1.053812</td>\n",
442
+ " </tr>\n",
443
+ " </tbody>\n",
444
+ "</table>\n",
445
+ "</div>"
446
+ ],
447
+ "text/plain": [
448
+ " CreditScore Age Tenure Balance NumOfProducts HasCrCard \\\n",
449
+ "9254 0.367013 -0.660018 0.341352 -1.225848 0.807737 0.646092 \n",
450
+ "1561 -0.191713 0.293517 -0.350204 0.691389 0.807737 0.646092 \n",
451
+ "1670 -0.947028 -1.422847 -0.695982 0.613102 -0.911583 0.646092 \n",
452
+ "6087 -0.926334 -1.136786 1.378686 0.948021 -0.911583 0.646092 \n",
453
+ "6669 -1.381593 1.628468 1.378686 1.052363 -0.911583 -1.547768 \n",
454
+ "\n",
455
+ " IsActiveMember EstimatedSalary \n",
456
+ "9254 0.970243 1.373784 \n",
457
+ "1561 0.970243 1.667407 \n",
458
+ "1670 -1.030670 -0.246910 \n",
459
+ "6087 -1.030670 0.921446 \n",
460
+ "6669 -1.030670 -1.053812 "
461
+ ]
462
+ },
463
+ "execution_count": 13,
464
+ "metadata": {},
465
+ "output_type": "execute_result"
466
+ }
467
+ ],
468
+ "source": [
469
+ "x_train.head()"
470
+ ]
471
+ },
472
+ {
473
+ "cell_type": "code",
474
+ "execution_count": 14,
475
+ "metadata": {},
476
+ "outputs": [
477
+ {
478
+ "name": "stdout",
479
+ "output_type": "stream",
480
+ "text": [
481
+ "\u001b[1m1/1\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 113ms/step\n"
482
+ ]
483
+ },
484
+ {
485
+ "name": "stderr",
486
+ "output_type": "stream",
487
+ "text": [
488
+ "c:\\Users\\abhis\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\keras\\src\\models\\functional.py:238: UserWarning: The structure of `inputs` doesn't match the expected structure.\n",
489
+ "Expected: keras_tensor\n",
490
+ "Received: inputs=('Tensor(shape=(1, 8))',)\n",
491
+ " warnings.warn(msg)\n"
492
+ ]
493
+ },
494
+ {
495
+ "data": {
496
+ "text/plain": [
497
+ "[0]"
498
+ ]
499
+ },
500
+ "execution_count": 14,
501
+ "metadata": {},
502
+ "output_type": "execute_result"
503
+ }
504
+ ],
505
+ "source": [
506
+ "# checking on diffrnt data \n",
507
+ "import numpy as np\n",
508
+ "input = np.array([[-0.191713,0.293517,-0.350204,0.691389,0.807737,0.646092,0.970243,1.66740]])\n",
509
+ "prd1 = ann.predict([input])\n",
510
+ "prd_data1 = []\n",
511
+ "for i in prd1:\n",
512
+ " if i[0]>0.5:\n",
513
+ " prd_data1.append(1)\n",
514
+ " else:\n",
515
+ " prd_data1.append(0)\n",
516
+ "prd_data1"
517
+ ]
518
+ },
519
+ {
520
+ "cell_type": "code",
521
+ "execution_count": 15,
522
+ "metadata": {},
523
+ "outputs": [
524
+ {
525
+ "data": {
526
+ "text/plain": [
527
+ "6252 0\n",
528
+ "4684 0\n",
529
+ "1731 0\n",
530
+ "4742 0\n",
531
+ "4521 0\n",
532
+ " ..\n",
533
+ "6412 1\n",
534
+ "8285 0\n",
535
+ "7853 1\n",
536
+ "1095 1\n",
537
+ "6929 1\n",
538
+ "Name: Exited, Length: 2000, dtype: int64"
539
+ ]
540
+ },
541
+ "execution_count": 15,
542
+ "metadata": {},
543
+ "output_type": "execute_result"
544
+ }
545
+ ],
546
+ "source": [
547
+ "y_test"
548
+ ]
549
+ },
550
+ {
551
+ "cell_type": "code",
552
+ "execution_count": 17,
553
+ "metadata": {},
554
+ "outputs": [],
555
+ "source": [
556
+ "# savin thhe model\n",
557
+ "ann.save(\"churn_prediction_model.keras\")"
558
+ ]
559
+ },
560
+ {
561
+ "cell_type": "code",
562
+ "execution_count": 21,
563
+ "metadata": {},
564
+ "outputs": [
565
+ {
566
+ "data": {
567
+ "text/plain": [
568
+ "['scaler.pkl']"
569
+ ]
570
+ },
571
+ "execution_count": 21,
572
+ "metadata": {},
573
+ "output_type": "execute_result"
574
+ }
575
+ ],
576
+ "source": [
577
+ "# saving the scaler \n",
578
+ "\n",
579
+ "import joblib \n",
580
+ "scaler = StandardScaler()\n",
581
+ "scaler.fit(dataset.iloc[:, :-1])\n",
582
+ "joblib.dump(scaler, \"scaler.pkl\")"
583
+ ]
584
+ }
585
+ ],
586
+ "metadata": {
587
+ "kernelspec": {
588
+ "display_name": "Python 3",
589
+ "language": "python",
590
+ "name": "python3"
591
+ },
592
+ "language_info": {
593
+ "codemirror_mode": {
594
+ "name": "ipython",
595
+ "version": 3
596
+ },
597
+ "file_extension": ".py",
598
+ "mimetype": "text/x-python",
599
+ "name": "python",
600
+ "nbconvert_exporter": "python",
601
+ "pygments_lexer": "ipython3",
602
+ "version": "3.12.0"
603
+ }
604
+ },
605
+ "nbformat": 4,
606
+ "nbformat_minor": 2
607
+ }