0

## K-means &C-means 疑問python

python都是K-means 我有找到python的
https://pythonhosted.org/scikit-fuzzy/auto_examples/plot_cmeans.html

pip install -U scikit-fuzzy
import skfuzzy as fuzz

froce iT邦大師 1 級 ‧ 2018-06-23 20:18:49 檢舉
K-means和C-means會相同嗎？

hoolada iT邦新手 5 級 ‧ 2018-06-23 22:52:50 檢舉

### 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]]
``````

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]