Mercurial > hg > nsaunier > traffic-intelligence
comparison python/ml.py @ 1025:6ba30b259525
minor
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Mon, 11 Jun 2018 17:07:53 -0400 |
| parents | 933670761a57 |
| children |
comparison
equal
deleted
inserted
replaced
| 1024:acb4f6f6545d | 1025:6ba30b259525 |
|---|---|
| 147 # k-means | 147 # k-means |
| 148 features = whiten(features) | 148 features = whiten(features) |
| 149 centroids,distortion = kmeans(features,k, iter) | 149 centroids,distortion = kmeans(features,k, iter) |
| 150 code,distance = vq(features,centroids) # code starting from 0 (represent first cluster) to k-1 (last cluster) | 150 code,distance = vq(features,centroids) # code starting from 0 (represent first cluster) to k-1 (last cluster) |
| 151 return code,sigma | 151 return code,sigma |
| 152 | |
| 153 class Cluster: | |
| 154 'Represents a cluster, with a prototype id and the list of instances in cluster' | |
| 155 def __init__(prototypeId, memberIndices = []): | |
| 156 self.prototypeId = prototypeId | |
| 157 self.memberIndices = memberIndices | |
| 158 | 152 |
| 159 def assignToPrototypeClusters(instances, prototypeIndices, similarities, minSimilarity, similarityFunc = None, minClusterSize = 0): | 153 def assignToPrototypeClusters(instances, prototypeIndices, similarities, minSimilarity, similarityFunc = None, minClusterSize = 0): |
| 160 '''Assigns instances to prototypes | 154 '''Assigns instances to prototypes |
| 161 if minClusterSize is not 0, the clusters will be refined by removing iteratively the smallest clusters | 155 if minClusterSize is not 0, the clusters will be refined by removing iteratively the smallest clusters |
| 162 and reassigning all elements in the cluster until no cluster is smaller than minClusterSize | 156 and reassigning all elements in the cluster until no cluster is smaller than minClusterSize |
