当前位置: 首页>>代码示例>>Python>>正文


Python AffinityPropagation.get_params方法代码示例

本文整理汇总了Python中sklearn.cluster.AffinityPropagation.get_params方法的典型用法代码示例。如果您正苦于以下问题:Python AffinityPropagation.get_params方法的具体用法?Python AffinityPropagation.get_params怎么用?Python AffinityPropagation.get_params使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sklearn.cluster.AffinityPropagation的用法示例。


在下文中一共展示了AffinityPropagation.get_params方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: AffinityPropagation

# 需要导入模块: from sklearn.cluster import AffinityPropagation [as 别名]
# 或者: from sklearn.cluster.AffinityPropagation import get_params [as 别名]
# http://pandas.pydata.org/pandas-docs/stable/computation.html#correlation
# df.corr() # Compute pairwise correlation of columns, excluding NA/null values
#matrix_corr = df_reconstituted_genesets.corr(method='pearson', min_periods=df_reconstituted_genesets.shape[0]) # --> Note that "min_periods=df_reconstituted_genesets_t.shape[0]" should not be needed, but it ensures that no "NaN" values are present to give weird results

### METHOD IN USE
print "Calculating correlation matrix between gene sets... This will be used as similarity matrix for Affinity Propagation"
#matrix_corr = np.corrcoef(df_reconstituted_genesets, rowvar=0) # NUMPY approach | slighty faster than Pandas
matrix_corr = df_reconstituted_genesets.corr(method='pearson', min_periods=df_reconstituted_genesets.shape[0]) # PANDAS approach | Note that "min_periods=df_reconstituted_genesets_t.shape[0]" should not be needed, but it ensures that no "NaN" values are present to give weird results
print "Dimension of correlation matrix: [{} x {}]".format(matrix_corr.shape[0], matrix_corr.shape[1])

################## Running AP ##################

#sklearn.cluster.AffinityPropagation(damping=0.5, max_iter=200, convergence_iter=15, copy=True, preference=None, affinity='euclidean', verbose=False)
af_obj = AffinityPropagation(affinity = 'precomputed', max_iter=10000, convergence_iter=1000) # using almost only default parameters
print "Affinity Propagation parameters:"
for param, val in af_obj.get_params().items():
	print "\t{}: {}".format(param, val)
print "Perfoming Affinity Propagation.."
af = af_obj.fit(matrix_corr)
n_iter = af.n_iter_
print "Affinity Propagation done"
print "Number of iterations used: {}".format(n_iter)

### Saving labels and centers
cluster_centers_indices = af.cluster_centers_indices_  # array, shape (n_clusters, n_features) | cluster center (boolean)s ("exemplars")
													   # cluster_centers_indices take on values in the range {0...n_samples-1}
labels = af.labels_ # array, shape (n_samples,) | Get the "labels"/assignments of each data point to a cluster index
					# labels take on values in the range: {0...n_clusters-1}


开发者ID:xhyuo,项目名称:DEPICT,代码行数:30,代码来源:network_plot.py

示例2: pairwise_distances

# 需要导入模块: from sklearn.cluster import AffinityPropagation [as 别名]
# 或者: from sklearn.cluster.AffinityPropagation import get_params [as 别名]
x = m83_data['x'][final_data]
y = m83_data['y'][final_data]
id_ = m83_data['id_'][final_data]
X = np.vstack([colour1, colour2, colour3, colour4, colour5, colour6]).T #, colour4, colour5, colour6, colour7]).T

similarity = pairwise_distances(X)
##############################################################################
# Compute Affinity Propagation
pref = -len(X)*0.1
damp = 0.95
af = AffinityPropagation(preference=pref, damping=damp).fit(similarity)
cluster_centers_indices = af.cluster_centers_indices_
labels = af.labels_
print cluster_centers_indices
print af.get_params()
n_clusters_ = len(cluster_centers_indices)

print('Estimated number of clusters: %d' % n_clusters_)
print "objects: {}".format(len(colour1))
print("Silhouette Coefficient: %0.3f"
      % metrics.silhouette_score(X, labels))

##############################################################################
# Plot result
import matplotlib.pyplot as plt
from itertools import cycle

#plt.close('all')
fig = plt.figure()
ax = fig.add_subplot(111)
开发者ID:PBarmby,项目名称:m83_clustering,代码行数:32,代码来源:affinity_propogation.py


注:本文中的sklearn.cluster.AffinityPropagation.get_params方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。