-
大小: 4KB文件类型: .py金币: 1下载: 0 次发布日期: 2021-05-09
- 语言: Python
- 标签: Clustering Python Methodology
资源简介
Rodriguez A, Laio A. Clustering by fast search and find of density peaks[J]. Science, 2014, 344(6191): 1492-1496.基于这篇文章实现的最基本的密度聚类的算法,具体请看我博客中的相关文章http://blog.csdn.net/kryolith/article/details/39832573
代码片段和文件信息
import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets import make_blobs
def distanceNorm(NormD_value):
# initialization
# Norm for distance
if Norm == ‘1‘:
counter = np.absolute(D_value);
counter = np.sum(counter);
elif Norm == ‘2‘:
counter = np.power(D_value2);
counter = np.sum(counter);
counter = np.sqrt(counter);
elif Norm == ‘Infinity‘:
counter = np.absolute(D_value);
counter = np.max(counter);
else:
raise Exception(‘We will program this later......‘);
return counter;
def chi(x):
if x < 0:
return 1;
else:
return 0;
def fit(featureslabelstdistanceMethod = ‘2‘):
# initialization
distance = np.zeros((len(labels)len(labels)));
distance_sort = list();
density = np.zeros(len(labels));
distance_higherDensity = np.zeros(len(labels));
# compute distance
for index_i in xrange(len(labels)):
for index_j in xrange(index_i+1len(labels)):
D_value = features[index_i] - features[index_j];
distance[index_iindex_j] = distanceNorm(distanceMethodD_value);
distance_sort.append(distance[index_iindex_j]);
distance += distance.T;
# compute optimal cutoff
distance_sort = np.array(distance_sort);
cutoff = int(np.round(distance_sort[len(distance_sort) * t]));
# computer density
for index_i in xrange(len(labels)):
distance_cutoff_i = distance[index_i] - cutoff;
for index_j in xrange(1len(labels)):
density[index_i] += chi(distance_cutoff_i[index_j]);
# search for the max density
Max = np.max(density);
MaxIndexList = list();
for index_i in xrange(len(labels)):
if density[index_i] == Max:
MaxIndexList.extend([index_i]);
# computer distance_higherDensity
Min = 0;
for index_i in xrange(len(labels)):
if index_i in MaxIndexList:
distance_higherDensity[index_i] = np.max(distance[index_i]);
continue;
else:
Min = np.max(distance[index_i]);
for index_j in xrange(1len(labels)):
if density[index_i] < density[index_j] and distance[index_iindex_j] < Min:
Min = distance[index_iindex_j];
else:
continue;
distance_high
相关资源
- Python爬虫源码—爬取猫途鹰官方旅游
- python摄像头视频显示到TK窗口
- 国际麻将AI-根据向听数计算最优操作
- 爬取瓜子二手车.py
- 人脸识别UI Pythone+pyq5+opencv 多线程模式
- pcap-1.1.win32-py2.7.exe
- Python制作的汉诺塔演示小脚本
- python django+bootstrap实现用户管理系统
- python+MySQL+bootstrap+ajax项目
- 基于Python的双路视频传输及双显示系
- python模型restful接口
- Python3—EM&GMM;
- python+numpy实现自适应阈值分割函数O
- python+numpy实现均值滤波
- python代码实现录音
- 初学者练习python编程的100个小程序
- python入门到实践 外星人入侵项目代码
- 合并BN层的python脚本
- 语音读邮件的小程序python实现
- python入账管理系统源码
- python调用opencv实现人脸识别的简单D
- python界面GUI实现k-means聚类算法
- python版flappybird源码
- 简明Python教程.pdf
- Python的入门代码银行管理系统
- Python科学计算 张若愚 第二版-书及全
- Python实现Word批注转成脚注
- 商品管理系统python
- Honeywell树莓派读取扫枪扫码数据
- Tkinter
评论
共有 条评论