You can use scikit-learn K-Means Clustering的时候,如何提取原始数据域中的质心?

huangapple go评论86阅读模式
英文:

When using scikit-learn K-Means Clustering, how can you extract the centroids in original data domain?

问题

我正在使用sklearn KMeans k均值聚类算法。在进行聚类之前,我使用以下代码将我的数据归一化到[0,1]范围内:

scaler = MinMaxScaler()
scaled_features = scaler.fit_transform(data)

现在,我可以运行K均值算法:

kmeans = KMeans(
    init="random",
    n_clusters=3,
    n_init=10,
    max_iter=3000,
)
kmeans.fit(scaled_features)

然后,我可以使用kmeans.cluster_centers_提取3个聚类中心。然而,这些中心位于归一化的范围[0,1]内。如何将它们重新转换为原始数据范围

英文:

I am using the sklearn KMeans k-means clustering algorithm. Before clustering, I normalize my data from [0,1] using

scaler = MinMaxScaler()
scaled_features = scaler.fit_transform(data)

Now, I can run the K-means algorithm.

kmeans = KMeans(
        init="random",
        n_clusters=3,
        n_init=10,
        max_iter=3000,
    )
    kmeans.fit(scaled_features)

Then, I can extract the 3 cluster centroids using kmeans.cluster_centers_. However, these centroids are in the normalized domain [0,1]. How can I re-transform these to the original data domain?

答案1

得分: 1

将坐标缩放到[0,1]范围内,然后使用scaler.inverse_transform将它们转换回原始坐标。

英文:

Get the corrdinates in [0,1] scale , then use scaler.inverse_tranform to convert them to the original coordinates.

huangapple
  • 本文由 发表于 2023年6月8日 03:00:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/76426328.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定