本文整理汇总了Python中scipy.cluster.hierarchy.maxdists函数的典型用法代码示例。如果您正苦于以下问题:Python maxdists函数的具体用法?Python maxdists怎么用?Python maxdists使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了maxdists函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_maxdists_Q_linkage
def check_maxdists_Q_linkage(self, method):
# Tests maxdists(Z) on the Q data set
X = hierarchy_test_data.Q_X
Z = linkage(X, method)
MD = maxdists(Z)
expectedMD = calculate_maximum_distances(Z)
assert_allclose(MD, expectedMD, atol=1e-15)
示例2: check_maxdists_Q_linkage
def check_maxdists_Q_linkage(self, method):
# Tests maxdists(Z) on the Q data set
X = eo['Q-X']
Y = pdist(X)
Z = linkage(X, method)
MD = maxdists(Z)
expectedMD = calculate_maximum_distances(Z)
assert_allclose(MD, expectedMD, atol=1e-15)
示例3: check_fcluster_monocrit
def check_fcluster_monocrit(self, t, criterion):
# Tests fcluster(Z, criterion='monocrit'/'maxclust_monocrit', t=t,
# monicrit=maxdists(Z)) on a random 3-cluster data set.
expectedT = np.int_(eo['fcluster-%s-%d' % (criterion, t)])
X = eo['Q-X']
Y = pdist(X)
Z = linkage(Y)
T = fcluster(Z, criterion=criterion, t=t, monocrit=maxdists(Z))
assert_(is_isomorphic(T, expectedT))
示例4: test_maxdists_one_cluster_linkage
def test_maxdists_one_cluster_linkage(self):
# Tests maxdists(Z) on linkage with one cluster.
Z = np.asarray([[0, 1, 0.3, 4]], dtype=np.double)
MD = maxdists(Z)
expectedMD = calculate_maximum_distances(Z)
assert_allclose(MD, expectedMD, atol=1e-15)
示例5: check_fcluster_maxclust_monocrit
def check_fcluster_maxclust_monocrit(self, t):
expectedT = hierarchy_test_data.fcluster_maxclust[t]
Z = single(hierarchy_test_data.Q_X)
T = fcluster(Z, t, criterion='maxclust_monocrit', monocrit=maxdists(Z))
assert_(is_isomorphic(T, expectedT))
示例6: pdist
ax.set_aspect(1./ax.get_data_ratio())
#### figure 2 #####
uniqueLabels = np.sort(np.unique(case1Labels))
centroids = np.array([case1[np.where(case1Labels == i)[0],:].mean(axis=0) for i in uniqueLabels])
fig = plt.figure()
ax = fig.add_subplot(111)
ncluster = 27
y = pdist(centroids)
method = 'centroid'#'average'
z = hierarchy.linkage(y,'average')
#t = hierarchy.fcluster(27,criterion='maxclust')
## computes the max distance between any cluster and ea non singleton cluster
print 'max dists', hierarchy.maxdists(z)
## inconsistancy
r = hierarchy.inconsistent(z)
print 'r',r
#print 'max inconsts', hierarchy.maxinconsts(z,r,i)
print 'z',z
#print 'blah', z[:,2] - np.array(z[1:,2].tolist()+[0])
print z[:,2]
print np.hstack([z[1:,2],[0]])
levelDiffs = np.abs(z[:,2] - np.hstack([z[1:,2],[0]]))
levelDiffMeans = z[:,2]# - 0.001 #np.hstack([z[1:,2],[0]]) / 2.0#z[:,2] + np.hstack([z[1:,2],[0]]) / 2.0
print 'diffs',levelDiffs*100
diffInds = np.argsort(levelDiffs)
示例7: plot_corr_cluster
def plot_corr_cluster(m, method=1, **kargs):
sns.set_style('white')
l = fst.linkage(m, method='average')
if method == 1:
# Threshold 1: MATLAB-like behavior
t = 0.7*max(l[:, 2])
elif method == 2:
t = np.median(hierarchy.maxdists(l))
elif method == 3:
t= mquantiles(hierarchy.maxdists(l), prob=0.75)[0]
else:
raise RuntimeError('no such method')
# Plot the clustermap
# Save the returned object for further plotting
mclust = sns.clustermap(m,
linewidths=0,
cmap=plt.get_cmap('RdBu'),
vmax=1,
vmin=-1,
row_linkage=l,
col_linkage=l,
**kargs)
# Draw the threshold lines
mclust.ax_col_dendrogram.hlines(t,
0,
m.shape[0]*10,
colors='g',
linewidths=2,
zorder=1)
mclust.ax_row_dendrogram.vlines(t,
0,
m.shape[0]*10,
colors='g',
linewidths=2,
zorder=1)
# Extract the clusters
clusters = hierarchy.fcluster(l, t, 'distance')
for c in set(clusters):
# Retrieve the position in the clustered matrix
index = [x for x in range(m.shape[0])
if mclust.data2d.columns[x] in m.index[clusters == c]]
# No singletons, please
if len(index) == 1:
continue
# Draw a rectangle around the cluster
mclust.ax_heatmap.add_patch(
patches.Rectangle(
(min(index),
m.shape[0] - max(index) - 1),
len(index),
len(index),
facecolor='none',
edgecolor='g',
lw=3)
)
plt.title('Cluster matrix')