人口初始化(虹膜数据集)||模糊C均值

时间:2019-11-25 14:38:34

标签: python

此处显示pop_int的代码

import math
import random

def POP_INITIALIZATION():
    LIST1=[]
    for i in file:
        ar=[float(y) for y in i.split(",")]
        LIST1.append(ar)

    len1=math.ceil(math.sqrt(len(LIST1)))

    templist=[]
    for i in range(2, len1):
        templist.append(i)

    out=[]
    for i in range(2, len1):
        size=random.choice(templist)
        templist.remove(size)
        templist2=[]
        for k in range(size):
            y=random.randint(0, len(LIST1)-1)
            templist2.append(LIST1[y])
        out.append(templist2)

    i=0
    for x in out:
        print(len(x))
        for y in x:
            print(y)
        print("\n")
        o_file.write("pop_"+str(i)+"   :   ")
        i=i+1
        o_file.write(str(x)+"\n")

    file.close()
    o_file.close()


file=open("dataset_data.txt", "r")
o_file=open("output.csv", "w")

POP_INITIALIZATION()

我已经初始化了人口...输出就像:

6
[7.7, 3.0, 6.1, 2.3]
[4.6, 3.1, 1.5, 0.2]
[6.1, 3.0, 4.9, 1.8]
[5.8, 2.8, 5.1, 2.4]
[7.0, 3.2, 4.7, 1.4]
[5.2, 4.1, 1.5, 0.1]


3
[4.6, 3.2, 1.4, 0.2]
[6.5, 3.2, 5.1, 2.0]
[6.9, 3.2, 5.7, 2.3]

以此类推。...如何使用此输出实现模糊C均值

输出如我所示... irisdataset是输入..初始化pop,然后实现模糊c均值聚类算法

0 个答案:

没有答案