text_plain_output_1.png
from keras.layers import Dense, LeakyReLU

from keras.models import Sequential

from scipy.stats import f_oneway

from sklearn.compose import ColumnTransformer

from sklearn.metrics import confusion_matrix, accuracy_score

from sklearn.preprocessing import OneHotEncoder

from sklearn.preprocessing import StandardScaler

import numpy as np #to perform arithmetic operation

import pandas as pd #to handle the dataframe

data = pd.read_csv('/kaggle/input/churn-predictions-personal/Churn_Predictions.csv')

data.isnull().sum()
' It\'s alaways necessary to check for the missing values. "Nan" is not always missing values. Missing values can be present in other format also.\nFeature can also have 0\'s which can also be treated as missing values for some particular dataset. Here in this case we dont have any missing value present \nin the dataset which saves a lot of time'

"""We can also check the top N customers based on their current account balance. Here 1 means left 0 means still with the bank"""
top_N = data.nlargest(20, 'Balance')
bottom_N = data.nsmallest(20, 'Balance')

from scipy.stats import f_oneway
grouped_data = data.groupby('Exited')['Age'].apply(list)
f_statistic, p_value = f_oneway(*grouped_data)

data.corr()

X = data.iloc[:, 3:-1].values
y = data.iloc[:, -1].values

"""Here 001 represent spain
100 represent france
010 represent germany"""
from sklearn.compose import ColumnTransformer
from sklearn.preprocessing import OneHotEncoder
ct = ColumnTransformer(transformers=[('encoder', OneHotEncoder(), [1])], remainder='passthrough')
X = np.array(ct.fit_transform(X))
X = np.delete(X, 0, axis=1)

from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)

classifier = Sequential()

classifier.add(Dense(units=6, kernel_initializer='uniform'))
classifier.add(LeakyReLU(alpha=0.1))

classifier.add(Dense(units=6, kernel_initializer='uniform'))
classifier.add(LeakyReLU(alpha=0.1))

classifier.add(Dense(units=1, kernel_initializer='uniform', activation='sigmoid'))
'as it is a binary classification problem thats why using 1 as number of neuron\nand using sigmoid as we have only 2 categories. If we would have more than 2 categories\nthen we might have used softmax activation function'

classifier.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
' Here optimizer is used as Adam a special type of Stochastic gradient descent(SGD), \nbinary_crossentropy loss function is used and accuracy metrics is considered'

classifier.fit(X_train, y_train, batch_size=10, epochs=100)

y_pred = classifier.predict(X_test)
y_pred = y_pred > 0.5
from sklearn.metrics import confusion_matrix, accuracy_score
con_matrix = confusion_matrix(y_pred, y_test)
accuracy = accuracy_score(y_pred, y_test)

print(X[0])
type(X)
X_new = np.array([[1, 0, 0, 600, 1, 40, 3, 60000, 2, 1, 1, 50000]])
print(X_new)
X_new = X_new[:, 1:]
print(X_new)
X_new = sc.transform(X_new)
print(len(X_new[0]))
y_pred_one = classifier.predict(X_new)
print(y_pred_one > 0.5)