xxxx18一60岁hd中国/日韩女同互慰一区二区/西西人体扒开双腿无遮挡/日韩欧美黄色一级片 - 色护士精品影院www

  • 大小: 6KB
    文件類型: .rar
    金幣: 2
    下載: 1 次
    發(fā)布日期: 2021-05-12
  • 語言: Python
  • 標(biāo)簽: 模糊聚類??

資源簡介

該資源包括兩部分代碼,都是python實(shí)現(xiàn),使用兩種方式實(shí)現(xiàn)了模糊聚類,使用的數(shù)據(jù)集也在壓縮包內(nèi),配置好環(huán)境可直接運(yùn)行。

資源截圖

代碼片段和文件信息

#!/usr/bin/env?python3
#?-*-?coding:?utf-8?-*-
#?author:1111
#?datetime:2019/2/22?11:17
#?software:?PyCharm

from?pylab?import?*
from?numpy?import?*
import?copy
import?random
import??time
import?math
import?matplotlib.pyplot?as?plt

import?matplotlib.animation?as?animation
import?decimal
#



#初始化隸屬度矩陣U
global?MAX
MAX?=?10000.0
#用于結(jié)束條件
global?Epsilon
Epsilon?=?0.00000001

def?import_data(file):
????“““
????格式化數(shù)據(jù),前四列為data最后一列為cluster_location
????“““
????data?=?[]
????cluster_location?=?[]
????with?open(str(file)‘r‘)?as?f?:
????????for?line?in?f:
????????????current?=?line.strip().split(““)
????????????current_dummy?=?[]
????????????#只讀取數(shù)據(jù)庫中除去最后一列之外的其他數(shù)據(jù)
????????????for?j?in?range(0len(current)-1):
????????????????current_dummy.append(float(current[j]))
????????????j?+=?1#將指針位移到表示類別的列?j=4
????????????#對原始數(shù)據(jù)每一行的數(shù)據(jù)進(jìn)行分類,分為三類,用012表示
????????????if??current[j]?==?“Iris-setosa“:
?????????????????cluster_location.append(0)

????????????elif?current[j]?==?“Iris-versicolor“:
?????????????????cluster_location.append(1)

????????????elif?current[j]?==?“Iris-virginica“:
?????????????????cluster_location.append(2)
????????????#創(chuàng)建只剩屬性的新數(shù)據(jù)集
????????????data.append(current_dummy)
????print(“data?lode?over“)
????return?data??cluster_location

def?randomise_data(data):
????“““
????將數(shù)據(jù)隨機(jī)化并保持隨機(jī)化順序的記錄
????:param?data:
????:return:
????“““
????order?=?list(range(0len(data)))#數(shù)據(jù)的條目數(shù)

????random.shuffle(order)#隨機(jī)排序列表

????new_data?=?[[]?for?i?in?range(0len(data))]
????for?index?in?range(0len(order)):
????????new_data[index]?=?data[order[index]]?#隨機(jī)化數(shù)據(jù)順序之后所對應(yīng)的數(shù)據(jù)進(jìn)行重新賦值,相當(dāng)于隨機(jī)化原始數(shù)據(jù)
????return??new_dataorder

def?de_randomise_data(dataorder):
????“““
????將返回?cái)?shù)據(jù)的原始順序,將randomise_data()返回的order列表作為參數(shù)
????:param?data:
????:param?order:
????:return:
????“““
????new_data?=?[[]?for?i?in?range(0?len(data))]
????for?index?in?range(len(order)):
????????new_data[order[index]]?=?data[index]
????return?new_data

def?print_matrix(list):
????“““
以可重復(fù)的方式打印矩陣
“““
????for?i?in?range(0?len(list)):
????????print?(list[i])

def?initialise_U(data?cluster_number):
????“““
????隸屬度矩陣U的每行加起來為1
????:param?data:
????:param?cluster_number:
????:return:
????“““
????global?MAX
????U?=?[]
????for?i?in?range(0len(data)):
????????current?=?[]
????????rand_sum?=?0.0
????????for?j?in?range(0cluster_number):
????????????dummy?=?random.randint(1int(MAX))
????????????current.append(dummy)
????????????rand_sum?+=?dummy

????????for?j?in?range(0cluster_number):
????????????current[j]?=?current[j]/?rand_sum
????????U.append(current)
????return?U


def?distance(point?center):
????“““
????該函數(shù)計(jì)算2點(diǎn)之間的距離(作為列表)。我們指歐幾里德距離。????????閔可夫斯基距離
????“““
????if?len(point)?!=?len(center):
????????return?-1
????dummy?=?0.0
????for?i?in?range(0?len(point)):
????????dummy?+=?abs(point[i]?-?center[i])?**?2
????return?math.sqrt(dummy)


def?end_conditon(U?U_old):
????“““
結(jié)束條件。當(dāng)U矩陣隨著連續(xù)迭代停止變化時(shí)

?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----

?????文件???????4700??2019-03-09?22:13??模糊聚類\iris.txt

?????文件???????8560??2019-03-14?15:35??模糊聚類\KCM.py

?????文件???????3716??2019-03-13?22:40??模糊聚類\result.csv

?????文件???????4431??2019-03-14?15:20??模糊聚類\tst.py

?????目錄??????????0??2019-03-15?20:51??模糊聚類

-----------?---------??----------?-----??----

????????????????21407????????????????????5


評論

共有 條評論

相關(guān)資源