如何垂直显示分层聚类方法?

puruo6ea  于 2021-08-20  发布在  Java
关注(0)|答案(0)|浏览(131)

我为分层聚类方法编写了以下代码。有人能帮我垂直显示图表吗?

dataset = pd.read_csv("https://raw.githubusercontent.com/akbarhusnoo/Chronic-Kidney-Disease- 
Prediction/main/chronic_kidney_disease.csv", na_values=["?"])
dataset = data.dropna(how='any')

catCols = dataset.select_dtypes("object").columns
catCols = list(set(catCols))
for i in catCols:
 dataset.replace({i: {'?': np.nan}}, regex=False,inplace=True)

X = dataset.iloc[:, [3,4]].values

# Using the dendrogram to find the optimal number of clusters

import scipy.cluster.hierarchy as sch
dendrogram = sch.dendrogram(sch.linkage(X, method='ward' ))
plt.title('Dendrogram')
plt.xlabel('Features')
plt.ylabel('Euclidean distances')
plt.show()

# Fitting the hierarchical clustering to the mall dataset

from sklearn.cluster import AgglomerativeClustering
hc = AgglomerativeClustering(n_clusters=5, affinity = 'euclidean', linkage = 'ward')
Y_hc = hc.fit_predict(X)

# Visualising the clusters

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题