Fuzzy Clustering
Pengertian Fuzzy Clustering
Fuzzy C-Means (FCM) merupakan teknik meengelompokan data yang keberadaan data dalam suatu kelompok ditentukan oleh nilai atau derajat keanggotaan tertentu.
berikut adalah algoritma dari FCM:
<pre> https://docs.google.com/spreadsheets/d/1evBtIV5M6rlFC9bljB9d0laFhv3qqoo4/edit#gid=1325169538 </pre> berikut contoh code program fuzzy C-Means: ```python 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'] centers = [[4, 2], [1, 7], [5, 6]] sigmas = [[0.8, 0.3], [0.3, 0.5], [1.1, 0.7]] np.random.seed(42) xpts = np.zeros(1) ypts = np.zeros(1) labels = np.zeros(1) for i, ((xmu, ymu), (xsigma, ysigma)) in enumerate(zip(centers, sigmas)): xpts = np.hstack((xpts, np.random.standard_normal(200) * xsigma + xmu)) ypts = np.hstack((ypts, np.random.standard_normal(200) * ysigma + ymu)) labels = np.hstack((labels, np.ones(200) * i)) fig0, ax0 = plt.subplots() for label in range(3): ax0.plot(xpts[labels == label], ypts[labels == label], '.', color=colors[label]) ax0.set_title('Test data: 200 points x3 clusters.')
fig2, ax2 = plt.subplots() ax2.plot(np.r_[2:11], fpcs) ax2.set_xlabel("Number of centers") ax2.set_ylabel("Fuzzy partition coefficient")
cntr, u_orig, _, _, _, _, _ = fuzz.cluster.cmeans( alldata, 3, 2, error=0.005, maxiter=1000) # Show 3-cluster model fig2, ax2 = plt.subplots() ax2.set_title('Trained model') for j in range(3): ax2.plot(alldata[0, u_orig.argmax(axis=0) == j], alldata[1, u_orig.argmax(axis=0) == j], 'o', label='series ' + str(j)) ax2.legend()
newdata = np.random.uniform(0, 1, (1100, 2)) * 10 u, u0, d, jm, p, fpc = fuzz.cluster.cmeans_predict( newdata.T, cntr, 2, error=0.005, maxiter=1000) cluster_membership = np.argmax(u, axis=0) fig3, ax3 = plt.subplots() ax3.set_title('Random points classifed according to known centers') for j in range(3): ax3.plot(newdata[cluster_membership == j, 0], newdata[cluster_membership == j, 1], 'o', label='series ' + str(j)) ax3.legend() plt.show()