image_output_1.png
from scipy.cluster.hierarchy import dendrogram, linkage

from sklearn.preprocessing import StandardScaler

import matplotlib.pyplot as plt

import numpy as np # linear algebra

import os

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import seaborn as sns

import warnings

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_style('darkgrid')
from sklearn.preprocessing import StandardScaler
from sklearn.cluster import KMeans
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
from sklearn.decomposition import PCA, FactorAnalysis
from scipy.cluster.hierarchy import dendrogram, linkage
import os
import warnings
warnings.filterwarnings('ignore')

PATH = '/kaggle/input/ccdata/'
df = pd.read_csv(PATH + 'CC GENERAL.csv')
data = df.copy()
data.columns = data.columns.str.lower()

data.shape

data.isnull().sum().sort_values(ascending=False)

plt.figure(figsize=(40, 20))
mask = np.triu(np.ones_like(data.corr(), dtype=np.bool))
heatmap = sns.heatmap(data.corr(), annot=True, mask=mask)
heatmap.set_title('Triangle Correlation Heatmap', fontdict={'fontsize':18}, pad=16);

plt.figure(figsize=(9,6))
ax = plt.axes() 
ax.set_facecolor('darkgrey') 
g = sns.scatterplot(x='balance_frequency', y='balance', data=data)
g.set_title('Balance Frequency vs. Balance')
plt.show()

plt.figure(figsize=(9,6))
ax = plt.axes() 
ax.set_facecolor('darkgrey') 
g = sns.scatterplot(x='credit_limit', y='balance', data=data)
g.set_title('Credit Limit vs. Balance')
plt.show()

o_cols = data.select_dtypes(include=['object']).columns.tolist()
num_cols = data.select_dtypes(exclude=['object']).columns.tolist()

ax = plt.axes()
ax.set_facecolor('darkgrey')

data.drop(columns='cust_id', inplace=True)

data.dropna(axis='index', inplace=True)

scaler = StandardScaler()
data_scaled = scaler.fit_transform(data)

hier_cluster = linkage(data_scaled, method='ward')

plt.figure(figsize=(10, 9))
plt.title('Hierarchical Clustering Dendrogram')
plt.xlabel('Observations')
plt.ylabel('Distance')
dendrogram(hier_cluster, truncate_mode='level', p=5, show_leaf_counts=False, no_labels=True)
plt.show()