Lab3.ipynb - Colaboratory
Lab3.ipynb - Colaboratory
ipynb - Colaboratory
IMPORT LIBRARIES
1 import pandas as pd
2 import numpy as np
3 import seaborn as sns
4 import matplotlib.pyplot as plt
1 df=pd.read_csv("Churn_Modelling.csv")
1 df.head()
account_circle RowNumber CustomerId Surname CreditScore Geography Gender Age Tenure Bala
1 df.shape
(10000, 14)
1 df.describe()
1 df.columns
1 df
https://colab.research.google.com/drive/1Zx8TMXeq4zEzr_v6XR1zI1RWcex3zgBh#printMode=true 1/7
10/29/23, 11:00 PM lab3.ipynb - Colaboratory
1 df.head()
1 df.tail()
1 df.head
<bound method NDFrame.head of RowNumber CustomerId Surname CreditScore Geography Gender Age \
0 1 15634602 Hargrave 619 France Female 42
1 2 15647311 Hill 608 Spain Female 41
2 3 15619304 Onio 502 France Female 42
3 4 15701354 Boni 699 France Female 39
4 5 15737888 Mitchell 850 Spain Female 43
... ... ... ... ... ... ... ...
9995 9996 15606229 Obijiaku 771 France Male 39
9996 9997 15569892 Johnstone 516 France Male 35
9997 9998 15584532 Liu 709 France Female 36
9998 9999 15682355 Sabbatini 772 Germany Male 42
9999 10000 15628319 Walker 792 France Female 28
EstimatedSalary Exited
0 101348.88 1
1 112542.58 0
2 113931.57 1
3 93826.63 0
4 79084.10 0
... ... ...
9995 96270.64 0
9996 101699.77 0
9997 42085.58 1
9998 92888.52 1
9999 38190.78 0
1 df.tail
<bound method NDFrame.tail of RowNumber CustomerId Surname CreditScore Geography Gender Age \
0 1 15634602 Hargrave 619 France Female 42
1 2 15647311 Hill 608 Spain Female 41
2 3 15619304 Onio 502 France Female 42
3 4 15701354 Boni 699 France Female 39
4 5 15737888 Mitchell 850 Spain Female 43
... ... ... ... ... ... ... ...
9995 9996 15606229 Obijiaku 771 France Male 39
9996 9997 15569892 Johnstone 516 France Male 35
9997 9998 15584532 Liu 709 France Female 36
9998 9999 15682355 Sabbatini 772 Germany Male 42
9999 10000 15628319 Walker 792 France Female 28
https://colab.research.google.com/drive/1Zx8TMXeq4zEzr_v6XR1zI1RWcex3zgBh#printMode=true 2/7
10/29/23, 11:00 PM lab3.ipynb - Colaboratory
0 2 0.00 1 1 1
1 1 83807.86 1 0 1
2 8 159660.80 3 1 0
3 1 0.00 2 0 0
4 2 125510.82 1 1 1
... ... ... ... ... ...
9995 5 0.00 2 1 0
9996 10 57369.61 1 1 1
9997 7 0.00 1 0 1
9998 3 75075.31 2 1 0
9999 4 130142.79 1 1 0
EstimatedSalary Exited
0 101348.88 1
1 112542.58 0
2 113931.57 1
3 93826.63 0
4 79084.10 0
... ... ...
9995 96270.64 0
9996 101699.77 0
9997 42085.58 1
9998 92888.52 1
9999 38190.78 0
1 df.head()
1 y=df["Exited"]
2
1 y
0 1
1 0
2 1
3 0
4 0
..
9995 0
9996 0
9997 1
9998 1
9999 0
Name: Exited, Length: 10000, dtype: int64
https://colab.research.google.com/drive/1Zx8TMXeq4zEzr_v6XR1zI1RWcex3zgBh#printMode=true 3/7
10/29/23, 11:00 PM lab3.ipynb - Colaboratory
1 sns.countplot(x=y)
Feature Scaling
1 X_scale=o.fit_transform(x)
2 X_scale
Cross Validation
1 X_train.shape
(7500, 9)
1 X_test.shape
(2500, 9)
1 ann.fit(X_train,Y_train)
https://colab.research.google.com/drive/1Zx8TMXeq4zEzr_v6XR1zI1RWcex3zgBh#printMode=true 4/7
10/29/23, 11:00 PM lab3.ipynb - Colaboratory
C:\ProgramData\anaconda3\lib\site-packages\sklearn\neural_network\_multilayer_percept
warnings.warn(
▾ MLPClassifier
MLPClassifier(hidden_layer_sizes=(100, 100, 100), max_iter=100, random_state=2)
1 y_pred=ann.predict(X_test)
1 y_pred
1 accuracy_score(Y_test,y_pred)
0.8424
1 print(classification_report(Y_test,y_pred))
1 ConfusionMatrixDisplay.from_predictions(Y_test,y_pred)
<sklearn.metrics._plot.confusion_matrix.ConfusionMatrixDisplay at 0x2201a10c6d0>
1 x_bal,y_bal = ros.fit_resample(x,y)
1 sns.countplot(x=y_bal)
https://colab.research.google.com/drive/1Zx8TMXeq4zEzr_v6XR1zI1RWcex3zgBh#printMode=true 5/7
10/29/23, 11:00 PM lab3.ipynb - Colaboratory
1 X_train.shape
2
(11944, 9)
1 X_test.shape
(3982, 9)
1 ann.fit(X_train,Y_train)
▾ MLPClassifier
MLPClassifier(hidden_layer_sizes=(100, 100, 100), max_iter=100, random_state=2)
1 y_pred=ann.predict(X_test)
1 y_pred
2
1 accuracy_score(Y_test,y_pred)
0.5012556504269211
https://colab.research.google.com/drive/1Zx8TMXeq4zEzr_v6XR1zI1RWcex3zgBh#printMode=true 6/7
10/29/23, 11:00 PM lab3.ipynb - Colaboratory
https://colab.research.google.com/drive/1Zx8TMXeq4zEzr_v6XR1zI1RWcex3zgBh#printMode=true 7/7