Tôi đã viết một tập lệnh đơn giản nhằm phân cụm theo cấp bậc trên một tập dữ liệu thử nghiệm đơn giản. Không thể lấy nhóm phân cấp scipy để làm việc
Tôi đã tìm thấy hàm fclusterdata làm ứng cử viên để nhóm dữ liệu của tôi thành hai cụm. Phải mất hai tham số cuộc gọi bắt buộc: tập dữ liệu và ngưỡng. Vấn đề là, tôi không thể tìm thấy ngưỡng có thể mang lại hai cụm dự kiến.
Tôi rất vui nếu có ai đó có thể cho tôi biết tôi đang làm gì sai. Tôi cũng muốn được hạnh phúc nếu có ai có thể chỉ trên phương pháp tiếp cận khác mà sẽ phù hợp hơn cho clustering của tôi (tôi rõ ràng muốn tránh để xác định số lượng các cụm trước.)
Đây là mã của tôi:
import time
import scipy.cluster.hierarchy as hcluster
import numpy.random as random
import numpy
import pylab
pylab.ion()
data = random.randn(2,200)
data[:100,:100] += 10
for i in range(5,15):
thresh = i/10.
clusters = hcluster.fclusterdata(numpy.transpose(data), thresh)
pylab.scatter(*data[:,:], c=clusters)
pylab.axis("equal")
title = "threshold: %f, number of clusters: %d" % (thresh, len(set(clusters)))
print title
pylab.title(title)
pylab.draw()
time.sleep(0.5)
pylab.clf()
đây là kết quả:
threshold: 0.500000, number of clusters: 129
threshold: 0.600000, number of clusters: 129
threshold: 0.700000, number of clusters: 129
threshold: 0.800000, number of clusters: 75
threshold: 0.900000, number of clusters: 75
threshold: 1.000000, number of clusters: 73
threshold: 1.100000, number of clusters: 58
threshold: 1.200000, number of clusters: 1
threshold: 1.300000, number of clusters: 1
threshold: 1.400000, number of clusters: 1
qua 'tiêu chí = "khoảng cách" 'cố định nó. Không nhận ra rằng các thông số này có liên quan. Cảm ơn! – moooeeeep