• 大小: 177KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-09-10
  • 语言: Python
  • 标签: optics  

资源简介

本资源中包括聚类分析OPTICS算法python实现,optics算法是基于DBSCAN聚类算法的改进算法。

资源截图

代码片段和文件信息

‘‘‘
Automatic Clustering of Hierarchical Clustering Representations
 
Library Dependencies: numpy if graphing is desired - matplotlib
OPTICS implementation used has dependencies include numpy scipy and hcluster

An implementation of the following algorithm with some minor add-ons:
J. Sander X. Qin Z. Lu N. Niu A. Kovarsky K. Whang J. Jeon K. Shim J. Srivastava Automatic extraction of clusters from hierarchical clustering representations. Advances in Knowledge Discovery and Data Mining (2003) Springer Berlin / Heidelberg. 567-567
available from http://dx.doi.org/10.1007/3-540-36175-8_8

Implemented in Python by Amy X. Zhang Cambridge Computer Laboratory.
March 2012
axz@mit.edu
http://people.csail.mit.edu/axz
‘‘‘


import numpy as NP
import matplotlib.pyplot as plt
from operator import itemgetter
import sys


def isLocalMaxima(indexRPlotRPointsnghsize):
    # 0 = point at index is not local maxima
    # 1 = point at index is local maxima
    
    for i in range(1nghsize+1):
        #process objects to the right of index 
        if index + i < len(RPlot):
            if (RPlot[index] < RPlot[index+i]):
                return 0
            
        #process objects to the left of index 
        if index - i >= 0:
            if (RPlot[index] < RPlot[index-i]):
                return 0
    
    return 1

def findLocalMaxima(RPlot RPoints nghsize):
    
    localMaximaPoints = {}
    
    #1st and last points on Reachability Plot are not taken as local maxima points
    for i in range(1len(RPoints)-1):
        #if the point is a local maxima on the reachability plot with 
        #regard to nghsize insert it into priority queue and maxima list
        if RPlot[i] > RPlot[i-1] and RPlot[i] >= RPlot[i+1] and isLocalMaxima(iRPlotRPointsnghsize) == 1:
            localMaximaPoints[i] = RPlot[i]
    
    return sorted(localMaximaPoints key=localMaximaPoints.__getitem__  reverse=True)
    


def clusterTree(node parentNode localMaximaPoints RPlot RPoints min_cluster_size):
    #node is a node or the root of the tree in the first call
    #parentNode is parent node of N or None if node is root of the tree
    #localMaximaPoints is list of local maxima points sorted in descending order of reachability
    if len(localMaximaPoints) == 0:
        return #parentNode is a leaf
    
    #take largest local maximum as possible separation between clusters
    s = localMaximaPoints[0]
    node.assignSplitPoint(s)
    localMaximaPoints = localMaximaPoints[1:]

    #create two new nodes and add to list of nodes
    Node1 = TreeNode(RPoints[node.start:s]node.starts node)
    Node2 = TreeNode(RPoints[s+1:node.end]s+1 node.end node)
    LocalMax1 = []
    LocalMax2 = []

    for i in localMaximaPoints:
        if i < s:
            LocalMax1.append(i)
        if i > s:
            LocalMax2.append(i)
    
    Nodelist = []
    Nodelist.append((Node1LocalMax1))
    Nodelist.append((Node2LocalMax2))
    
    #set a lower threshold on 

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2015-11-23 09:24  OPTICS-Automatic-Clustering-master\
     文件        9944  2015-11-23 09:24  OPTICS-Automatic-Clustering-master\AutomaticClustering.py
     文件        2552  2015-11-23 09:24  OPTICS-Automatic-Clustering-master\README
     目录           0  2015-11-23 09:24  OPTICS-Automatic-Clustering-master\demo\
     文件       10019  2015-11-23 09:24  OPTICS-Automatic-Clustering-master\demo\AutomaticClustering.py
     文件       64933  2015-11-23 09:24  OPTICS-Automatic-Clustering-master\demo\Example2.png
     文件       20514  2015-11-23 09:24  OPTICS-Automatic-Clustering-master\demo\Example2RPlot.png
     文件       26507  2015-11-23 09:24  OPTICS-Automatic-Clustering-master\demo\Graph.png
     文件       44622  2015-11-23 09:24  OPTICS-Automatic-Clustering-master\demo\Graph2.png
     文件        3528  2015-11-23 09:24  OPTICS-Automatic-Clustering-master\demo\OpticsClusterArea.py
     文件       26100  2015-11-23 09:24  OPTICS-Automatic-Clustering-master\demo\RPlot.png
     文件        2463  2015-11-23 09:24  OPTICS-Automatic-Clustering-master\demo\demo.py

评论

共有 条评论

相关资源