DBSCAN简介:

1.简介
  DBSCAN 算法是一种基于密度的空间聚类算法。该算法利用基于密度的聚类的概念,即要求聚类空间中的一定区域内所包含对象(点或其它空间对象)的数目不小于某一给定阀值。DBSCAN 算法的显著优点是聚类速度快且能够有效处理噪声点和发现任意形状的空间聚类。但是由于它直接对整个数据库进行操作且进行聚类时使用了一个全局性的表征密度的参数,因此也具有两个比较明显的弱点:

        1. 当数据量增大时,要求较大的内存支持 I/0 消耗也很大;

        2. 当空间聚类的密度不均匀、聚类间距离相差很大时,聚类质量较差。

2.DBSCAN算法的聚类过程
  DBSCAN算法基于一个事实:一个聚类可以由其中的任何核心对象唯一确定。等价可以表述为: 任一满足核心对象条件的数据对象p,数据库D中所有从p密度可达的数据对象所组成的集合构成了一个完整的聚类C,且p属于C。

3.DBSCAN中的几个定义
  密度可达是直接密度可达的传递闭包,非对称性关系;密度相连是对称性关系。DBSCA目的是找到密度相连对象的最大集合。

  E领域:给定对象p半径为E内的区域称为该对象的E领域;

  核心对象:p的E领域内样本数大于MinPts(算法输入值),则该对象p为核心对象;

  直接密度可达:对于样本集合D,如果样本点q在p的E领域内,且p为核心对象,则p直接密度可达q;

  密度可达:对于样本集合D,存在一串样本点p1,p2,p3,...pn,其中连续两个点直接密度可达,则 p=p1,q=qn,则p密度可达q;

  密度相连:对于样本集合D中任意一点o,存在p到o密度可达,并且q到o密度可达,那么q从p密度相连;

from matplotlib.pyplot import *
from collections import defaultdict
import random #function to calculate distance
def dist(p1, p2):
return ((p1[0]-p2[0])**2+ (p1[1]-p2[1])**2)**(0.5) #randomly generate around 100 cartesian coordinates
all_points=[] for i in range(100):
randCoord = [random.randint(1,50), random.randint(1,50)]
if not randCoord in all_points:
all_points.append(randCoord) #take radius = 8 and min. points = 8
E = 8
minPts = 8 #find out the core points
other_points =[]
core_points=[]
plotted_points=[]
for point in all_points:
point.append(0) # assign initial level 0
total = 0
for otherPoint in all_points:
distance = dist(otherPoint,point)
if distance<=E:
total+=1 if total > minPts:
core_points.append(point)
plotted_points.append(point)
else:
other_points.append(point) #find border points
border_points=[]
for core in core_points:
for other in other_points:
if dist(core,other)<=E:
border_points.append(other)
plotted_points.append(other) #implement the algorithm
cluster_label=0 for point in core_points:
if point[2]==0:
cluster_label+=1
point[2]=cluster_label for point2 in plotted_points:
distance = dist(point2,point)
if point2[2] ==0 and distance<=E:
print point, point2
point2[2] =point[2] #after the points are asssigned correnponding labels, we group them
cluster_list = defaultdict(lambda: [[],[]])
for point in plotted_points:
cluster_list[point[2]][0].append(point[0])
cluster_list[point[2]][1].append(point[1]) markers = ['+','*','.','d','^','v','>','<','p'] #plotting the clusters
i=0
print cluster_list
for value in cluster_list:
cluster= cluster_list[value]
plot(cluster[0], cluster[1],markers[i])
i = i%10+1 #plot the noise points as well
noise_points=[]
for point in all_points:
if not point in core_points and not point in border_points:
noise_points.append(point)
noisex=[]
noisey=[]
for point in noise_points:
noisex.append(point[0])
noisey.append(point[1])
plot(noisex, noisey, "x") title(str(len(cluster_list))+" clusters created with E ="+str(E)+" Min Points="+str(minPts)+" total points="+str(len(all_points))+" noise Points = "+ str(len(noise_points)))
axis((0,60,0,60))
show()

参考地址:http://www.cnblogs.com/sungyouyu/p/3636708.html#undefined

DBscan算法及其Python实现的更多相关文章

  1. 挑子学习笔记:DBSCAN算法的python实现

    转载请标明出处:https://www.cnblogs.com/tiaozistudy/p/dbscan_algorithm.html DBSCAN(Density-Based Spatial Clu ...

  2. Python机器学习笔记:K-Means算法,DBSCAN算法

    K-Means算法 K-Means 算法是无监督的聚类算法,它实现起来比较简单,聚类效果也不错,因此应用很广泛.K-Means 算法有大量的变体,本文就从最传统的K-Means算法学起,在其基础上学习 ...

  3. 【转】常用聚类算法(一) DBSCAN算法

    原文链接:http://www.cnblogs.com/chaosimple/p/3164775.html#undefined 1.DBSCAN简介 DBSCAN(Density-Based Spat ...

  4. 常用聚类算法(一) DBSCAN算法

    1.DBSCAN简介 DBSCAN(Density-Based Spatial Clustering of Applications with Noise,具有噪声的基于密度的聚类方法)是一种基于密度 ...

  5. 八大排序算法的 Python 实现

    转载: 八大排序算法的 Python 实现 本文用Python实现了插入排序.希尔排序.冒泡排序.快速排序.直接选择排序.堆排序.归并排序.基数排序. 1.插入排序 描述 插入排序的基本操作就是将一个 ...

  6. 基于密度的聚类之Dbscan算法

    一.算法概述 DBSCAN(Density-Based Spatial Clustering of Applications with Noise)是一个比较有代表性的基于密度的聚类算法.与划分和层次 ...

  7. DBSCAN算法

    简单的说就是根据一个根据对象的密度不断扩展的过程的算法.一个对象O的密度可以用靠近O的对象数来判断.学习DBSCAN算法,需要弄清楚几个概念: 一:基本概念 1.:对象O的是与O为中心,为半径的空间, ...

  8. 数据关联分析 association analysis (Aprior算法,python代码)

    1基本概念 购物篮事务(market basket transaction),如下表,表中每一行对应一个事务,包含唯一标识TID,和购买的商品集合.本文介绍一种成为关联分析(association a ...

  9. 机器学习算法与Python实践之(四)支持向量机(SVM)实现

    机器学习算法与Python实践之(四)支持向量机(SVM)实现 机器学习算法与Python实践之(四)支持向量机(SVM)实现 zouxy09@qq.com http://blog.csdn.net/ ...

随机推荐

  1. N皇后递归

    问题: n皇后问题:输入整数n, 要求n个国际象棋的皇后,摆在 n*n的棋盘上,互相不能攻击,输出全部方案. #include <iostream> using namespace std ...

  2. HTML5新增的主体元素article、section、nav、aside、time元素和pubdate属性

    article artticle元素代表文档.页面或应用程序中独立的.完整的.可以独自被外部引用的内容.它可以是一篇博客或者报刊中的文章,一篇论坛帖子,一段用户评论或者独立的插件或其他任何独立的内容. ...

  3. Python之微信-微信好友头像合成

    仔细看下图,你的头像就藏在里面哦!!! 有没有犯密集恐惧症?这并不震撼,如果你有 5000 位好友的话,做出来的图看着会更刺激些. 看完了图,你可能想知道这个图咋做出来的,不会是我闲着无聊把把好友头像 ...

  4. Python中的函数(5)

    一.向函数中传递任意数量的实参 有时候,你预先不知道函数需要接受多少个实参,Python中函数可以收集任意数量的实参. 栗子:来看一个打印好友列表功能的函数,它需要接收任意数量的好友名.如下: def ...

  5. 【HDU 5934】Bomb(强连通缩点)

    Problem Description There are N bombs needing exploding. Each bomb has three attributes: exploding r ...

  6. 算法导论 第六章 2 优先队列(python)

    优先队列:     物理结构: 顺序表(典型的是数组){python用到list}     逻辑结构:似完全二叉树 使用的特点是:动态的排序..排序的元素会增加,减少#和快速排序对比 快速一次排完 增 ...

  7. Cannot delete or update a parent row: a foreign key constraint fails....

    在操作”小弟“这张表时候报错 想在“小弟”上面加入数据或者更新数据,就要听老大的, 这句话后面跟着的表就是“老大”,必须老大有数据索引,“小弟“才可以加入或者更新 查看“小弟”表的外键,会发现有对“老 ...

  8. mac 终端path配置出错,命令无法使用

    mac 命令行中修改path的时候,不小心把path修改错了,而且还 source 了,然后发现只能使用 cd 命令,ls vi 命令都不能使用了. 解决办法,执行下面的语句 export PATH= ...

  9. python接口自动化-有token的接口项目使用unittest框架设计

    获取token 在做接口自动化的时候,经常会遇到多个用例需要用同一个参数token,并且这些测试用例跨.py脚本了. 一般token只需要获取一次就行了,然后其它使用unittest框架的测试用例全部 ...

  10. hexo干货系列:(七)hexo安装统计插件

    前言 前面介绍了如何让百度和谷歌收录我们的博客,那如何查看自己的博客每天被多少人访问呢~ 这里我介绍下hexo中如何使用统计插件,每天看到自己的博客访问量越来越高也是一种享受. 正文 开启统计功能 我 ...