Skip to main content

Fuzzy clustering algorithm toolbox

Project description

模糊聚类算法工具箱(python)

introduce

本开源项目为模糊聚类算法python代码,主要算法包括:

  • FCM(模糊C均值算法)
  • MEC (极大熵模糊聚类算法)
  • KFCM(核模糊聚类算法)
  • SFCM (半监督模糊聚类算法)
  • eSFCM (基于信息熵的半监督模糊聚类算法)
  • SMUC (基于度量学习与信息熵的半监督模糊聚类算法)

以这些算法为基础的相关论文可参考本人的谷歌学术主页:Wei Cai,Guangdong University of Technology

install

通过以下方式安装(win10用户安装好python并配置好环境变量之后,打开cmd输入以下命令):

pip install FuzzyClustering

project structure

  • dataset:数据集
  • ClusterAidedComputing.py :包括聚类常用的一些函数
  • ClusteringIteration.py :包括聚类算法迭代式
  • FuzzyClustering.py :模糊聚类算法
  • demo.py : 演示脚本(运行此程序)

算法调用

参数

(以下为所有模糊聚类算法都有的参数)

data :数据集,统一使用数组(darry)

cluster_n :类簇中心数

max_iter :最大迭代次数

e :目标函数值变化最小阈值

printOn :打印迭代情况开关(当printOn=1时打印迭代情况)

调用规则

所有的函数都需要输入data和cluster_n,其余参数可能有预设参数(若有预设参数则可以不输入,不输入则采用默认参数)

算法函数

  • FCM
U,V,obj_fcn = fcm(data,cluster_n,m = 2,max_iter = 1000,e = 0.00001,printOn = 1)

U,V,obj_fcn = fcm(data,cluster_n)

如上,m ,max_iter,e ,printOn这四个参数已有默认参数,可不设置

  • MEC
U,V,obj_fcn = mec(data,cluster_n,gamma=0.01,max_iter = 1000,e = 0.00001,printOn = 1)

gamma :惩罚系数

  • KFCM

    sigma :高斯核标准差

    lamda :惩罚系数

kfcm(data,cluster_n,sigma=2,m=2,lamda=0.1,max_iter = 1000,e = 0.00001,printOn = 1)
  • SFCM
U,V,obj_fcn = sfcm(data,cluster_n,label,m = 2,max_iter = 1000,e = 0.00001,alpha=5,printOn = 1)

label :标签(array格式)

  • eSFCM
U,V,obj_fcn = esfcm(data,cluster_n,label,max_iter = 1000,e = 0.00001,lamda=1,printOn = 1)
  • SMUC
U,V,obj_fcn = smuc(data,cluster_n,label,max_iter = 1000,e = 0.5,lamda=1,printOn = 1)

demo

import FuzzyClustering
import numpy as np
import matplotlib.pyplot as plt
from sklearn.metrics import accuracy_score


'''数据及参数设置'''
data_route = r'dataset\iris.csv'
label_route = r'dataset\irislabel.csv'

with open(data_route,encoding = 'utf-8') as f:
    data = np.loadtxt(f,delimiter = ",")
with open(label_route,encoding = 'utf-8') as f:
    label = np.loadtxt(f,delimiter = ",")

cluster_n = int(np.max(label))
data = ( data - np.min(data,axis=0)) / (np.max(data,axis=0) - np.min(data,axis=0))  #数据标准化

'''模糊聚类算法'''
U,center,fcm_obj_fcn = FuzzyClustering.smuc(data,cluster_n,label[1:20],max_iter = 100,e = 0.00001,lamda=0.5,printOn = 1)
label_pred,abaaba = np.where(U==np.max(U,axis=0)) #最大值索引

'''画图'''
plt.plot(fcm_obj_fcn)
plt.show()

'''性能评价'''
label_pred = label_pred + 1     #因为索引是从零开始,但标签是从1开始
print(U[:,1])
print("准确率:",accuracy_score(label.tolist(),label_pred.tolist()))

迭代目标函数值变化图:

Figure 1

Figure 2

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

FuzzyClustering-0.1.0.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

FuzzyClustering-0.1.0-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file FuzzyClustering-0.1.0.tar.gz.

File metadata

  • Download URL: FuzzyClustering-0.1.0.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.5

File hashes

Hashes for FuzzyClustering-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fa468e1557fe2928afe1e0a9180cfc71737c09af058147254d3a597a2f19592a
MD5 b17f2b8fdfa1ef19667151ffc5a7db83
BLAKE2b-256 000aaac0b733b911772e1aa8e2617f7b32f4f56b06f5a5b0be692626b7a31cd5

See more details on using hashes here.

File details

Details for the file FuzzyClustering-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: FuzzyClustering-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.5

File hashes

Hashes for FuzzyClustering-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ec7e5359a659b4ae66511ce532b15596673420d5374da2205093dda50b08dda1
MD5 1958ae2b4b195683c4e03120a07fc5df
BLAKE2b-256 390eb5de0e96de88ed792c8fadd491394a80c2c3bddcc486e139c2c9fe161b24

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page