-
Notifications
You must be signed in to change notification settings - Fork 0
/
Agrupamento_Hierárquico_Base_Crédito.py
39 lines (27 loc) · 1.13 KB
/
Agrupamento_Hierárquico_Base_Crédito.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import plotly.express as px
import plotly.graph_objects as go
import numpy as np
from sklearn.preprocessing import StandardScaler
from sklearn.cluster import KMeans
import pandas as pd
base_credit= pd.read_csv(r'C:\Users\joaov\OneDrive\Área de Trabalho\python\CSV\credit_card_clients.csv', header=1)
print(base_credit)
#DIVIDA TOTAL
base_credit['bill_total']=base_credit['BILL_AMT1'] + base_credit['BILL_AMT2'] + base_credit['BILL_AMT3'] + base_credit['BILL_AMT4'] + base_credit['BILL_AMT5'] + base_credit['BILL_AMT6']
print(base_credit)
#limite e bill total
x_cartao= base_credit.iloc[:,[1, 25]].values
#padronizando
scaler=StandardScaler()
x_cartao=scaler.fit_transform(x_cartao)
print(x_cartao)
import matplotlib.pyplot as plotly
from scipy.cluster.hierarchy import dendrogram, linkage
dendograma= dendrogram(linkage(x_cartao, method='ward'))
plotly.show()
from sklearn.cluster import AgglomerativeClustering
hc_salario=AgglomerativeClustering(n_clusters=3, linkage='ward', affinity='euclidean')
rotulos=hc_salario.fit_predict(x_cartao)
print(rotulos)
grafico = px.scatter(x = x_cartao[:,0], y = x_cartao[:,1], color = rotulos)
grafico.show()