针对离散和有界数据优化的离散dbscan算法。

ddbscan的Python项目详细描述


https://travis-ci.org/cloudwalkio/ddbscan.svg?branch=masterhttps://img.shields.io/coveralls/cloudwalkio/ddbscan/master.svgLandscape quality scoreLatest VersionSupported Python versionsDownloads on PyPILicense

这是DBSCAN聚类算法的一个版本,针对离散 有界数据,我们称之为离散dbscan(ddbscan)的原因。基础 当前实现来自this source。算法代码在 文件ddbscan/ddbscan.py,且易于读取。主要算法本身 在方法compute()中,可以通过上面的链接理解 或者阅读描述它的文章。

这个实现的另一个特点是它设计为在线 学习。因此,当我们向ddbscan对象添加点时,必须通过 每次指向方法add_point的一个点。见下面的用法。

离散和有界数据的优化

我们对上述链接中描述的香草算法的主要优化是 基于这样一个事实,对于离散和有界的数据,我们期望看到 同一点发生的次数,以便我们可以跟踪 指出并优化我们的算法以使用这些信息。

为了加速新点的插入和簇的计算,每个ddbscan 对象为每个点保留其邻居和邻居的索引 大小(相邻点的计数之和)。所以,当我们插入一个新的 点,我们看它是不是已经存在的一对,只是增加计数器。 以及邻近地区的规模。我们用 插入新对时的点,更新其点数据 邻居。

参数

dbscan模型有两个参数:

  • min_pts:创建群集的点的最小邻居数。
  • eps:查找邻居的半径。

通过调整这两个参数,我们实际上是在设置异常值(异常值) 检测灵敏度。min_pts的较大值意味着 将一个新的模式识别为一个集群,而不是一个异常,我们必须看到 更多的点有这种模式。eps的较大值意味着 更大的星团可以更容易地形成,因此在密度较小的区域中的点可以 给定这么大的eps,将其识别为群集成员。考虑到重要性 我们有一个方法来设置这些参数,称为 set_params(),它相应地更新模型的内部状态。

安装

要安装软件包,最简单的方法是使用pip:

$ pip install ddbscan

另一个选项是克隆此回购并运行

$ python setup.py install

运行测试:

$ python setup.py test

用法

典型的例子如下:

importddbscan# Create a DDBSCAN model with eps = 2 and min_pts = 5scan=ddbscan.DDBSCAN(2,5)# Add points to modeldata=[[1,2],[2,2],[1,3],[2,3],[3,3],[8,9],[7,6],[9,7],[6,9],[6,8],[5,5],[7,8]]forpointindata:scan.add_point(point=point,count=1,desc="")# Compute clustersscan.compute()print'Clusters found and its members points index:'cluster_number=0forclusterinscan.clusters:print'=== Cluster %d ==='%cluster_numberprint'Cluster points index: %s'%list(cluster)cluster_number+=1print'\nCluster assigned to each point:'foriinxrange(len(scan.points)):print'=== Point: %s ==='%scan.points[i]print'Cluster: %2d'%scan.points_data[i].cluster,# If a point cluster is -1, it's an anomalyifscan.points_data[i].cluster==-1:print'\t <== Anomaly found!'else:print

许可证

The MIT License (MIT)

Copyright (c) 2014 CloudWalk, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java搜索大数组中的最小数   java如何将数组变量用于IF语句?   多线程如何在java中使用多核?   java实现中的数据结构单链表,无限打印输出?   java检查命令行参数是否按有效顺序传递   爪哇点火。ignite返回“网格实例未正确启动或已停止”   java如何同时使用toString()或print()等显示两个输出?   在Java中使用LinkedList列出两个多项式的加法   Java中并行流的正确使用   mac上的java Eclipse:单击Eclipse图标后崩溃,重新安装,但无法为pyDev创建视图   java如何在sqlite4java中禁用自动提交?   java这样行吗?Synchronized(线程),然后synch块中的thread=null   java方法。调用它可以接受的参数?