iT邦幫忙

0

K-means &C-means 疑問python

https://ithelp.ithome.com.tw/upload/images/20180623/20110175dnIYFGiHZ8.png
我想得到的是像這樣這樣從第一個分群的值 例如他這樣從第一個開始111122312... 但這是R 的C-means

python都是K-means 我有找到python的
https://pythonhosted.org/scikit-fuzzy/auto_examples/plot_cmeans.html
有比較簡單的範例教學可以懂嗎 我看得懂k-means但這的範例雖可執行但我卻看不太懂?
pip install -U scikit-fuzzy
import skfuzzy as fuzz
這個這樣做的作法跟c-means是一樣的嗎或者k-means也能做出這樣的效果?
還是各位有什麼建議可以跟我講一下嗎?

froce iT邦大師 1 級 ‧ 2018-06-23 20:18:49 檢舉
K-means和C-means會相同嗎?
你丟這網頁就是做C-means。

你會R就用R去寫,語言只是工具,不用太拘泥於工具。
hoolada iT邦新手 5 級 ‧ 2018-06-23 22:52:50 檢舉
大大 不好意思 我不會R 因為我前半都是用Python寫的 那C-means的code我看不太懂 centers sigmas 我不懂那邊為什麼他要那樣設定 可以給我提點一下嗎?
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

0
froce
iT邦大師 1 級 ‧ 2018-06-24 12:15:09
最佳解答
from __future__ import division, print_function
import numpy as np
import matplotlib.pyplot as plt
import skfuzzy as fuzz

colors = ['b', 'orange', 'g', 'r', 'c', 'm', 'y', 'k', 'Brown', 'ForestGreen']

# Define three cluster centers
centers = [[4, 2],
           [1, 7],
           [5, 6]]

# Define three cluster sigmas in x and y, respectively
sigmas = [[0.8, 0.3],
          [0.3, 0.5],
          [1.1, 0.7]]

你是說這邊嗎?這邊只是測試資料集,先設定中心點(centers)和離散程度(sigmas),利用random,產生200個點。

做研究要學著看英文,人家註釋寫得很清楚。

hoolada iT邦新手 5 級 ‧ 2018-06-28 16:03:59 檢舉

我成功執行了 感謝
//k-means
kmeans_fit = cluster.KMeans(n_clusters = 6).fit(newData)
cluster_labels = kmeans_fit.labels_
ppt=kmeans_fit.labels_

//印出績效
silhouette_avg = metrics.silhouette_score(newData, cluster_labels)
print(silhouette_avg)
print(ppt[:120])
0.4639289840822076
[2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 0 0 0 1 4 4 4 2 0 0 2 2 0 0 2 2 1 1 1 2 2 0 0 0 0 5 1 1 1 1 1 1 1 1 1 1 1 5 5 5 5 5 5 5 5 5 5 5 1 1 1 1 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3]
我想請問 我k-means可以印出每個值得群是多少
我執行雖然成功 但我常是要讓他印出每個值得群是多少 該怎麼下手呢?

我要發表回答

立即登入回答