def agglomerative_clustering(X, k=10):
""" Run an agglomerative clustering on X.
Args:
X: the TF-IDF matrix where each line represents a document and each
column represents a word, typically obtained by running
transform_text() from the TP2.
k: the number of clusters we want (default: 10).
Returns:
An AgglomerativeClustering model trained on X.
"""
model = AgglomerativeClustering(n_clusters=k)
model.fit(X)
# Note all the other functions are the same except we use
# 'AgglomerativeClustering' instead of 'KMeans'.
return model
# Ex4.1
评论列表
文章目录