-
大小: 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+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
- python疫情卡UN管控
- python 连连看小游戏源码
- 基于PyQt5的视频播放器设计
- 一个简单的python爬虫
- csv文件行列转换python实现代码
- Python操作Mysql教程手册
- Python Machine Learning Case Studies
- python获取硬件信息
- 量化交易(附python常见函数的使用方
- python 名字用字排行
评论
共有 条评论