當前位置: 首頁>>代碼示例>>Python>>正文


Python SpectralCoclustering.get_shape方法代碼示例

本文整理匯總了Python中sklearn.cluster.bicluster.SpectralCoclustering.get_shape方法的典型用法代碼示例。如果您正苦於以下問題:Python SpectralCoclustering.get_shape方法的具體用法?Python SpectralCoclustering.get_shape怎麽用?Python SpectralCoclustering.get_shape使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在sklearn.cluster.bicluster.SpectralCoclustering的用法示例。


在下文中一共展示了SpectralCoclustering.get_shape方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: list

# 需要導入模塊: from sklearn.cluster.bicluster import SpectralCoclustering [as 別名]
# 或者: from sklearn.cluster.bicluster.SpectralCoclustering import get_shape [as 別名]
    col_complement = np.nonzero(np.logical_not(cocluster.columns_[i]))[0]
    weight = X[rows[:, np.newaxis], cols].sum()
    cut = (X[row_complement[:, np.newaxis], cols].sum() +
           X[rows[:, np.newaxis], col_complement].sum())
    return cut / weight


bicluster_ncuts = list(bicluster_ncut(i)
                       for i in xrange(len(newsgroups.target_names)))
best_idx = np.argsort(bicluster_ncuts)[:5]

print()
print("Best biclusters:")
print("----------------")
for idx, cluster in enumerate(best_idx):
    n_rows, n_cols = cocluster.get_shape(cluster)
    cluster_docs, cluster_words = cocluster.get_indices(cluster)
    if not len(cluster_docs) or not len(cluster_words):
        continue

    # categories
    cluster_categories = list(document_names[i] for i in cluster_docs)
    counter = Counter(cluster_categories)
    cat_string = ", ".join("{:.0f}% {}".format(float(c) / n_rows * 100,
                                               name)
                           for name, c in counter.most_common()[:3])

    # words
    out_of_cluster_docs = cocluster.row_labels_ != cluster
    out_of_cluster_docs = np.where(out_of_cluster_docs)[0]
    word_col = X[:, cluster_words]
開發者ID:Comy,項目名稱:scikit-learn,代碼行數:33,代碼來源:bicluster_newsgroups.py

示例2: range

# 需要導入模塊: from sklearn.cluster.bicluster import SpectralCoclustering [as 別名]
# 或者: from sklearn.cluster.bicluster.SpectralCoclustering import get_shape [as 別名]
           
        avg_data[row_sel, col_sel] = np.average(data[row_sel, col_sel])

avg_data = avg_data[np.argsort(model.row_labels_)]
avg_data = avg_data[:, np.argsort(model.column_labels_)]

plt.matshow(avg_data, cmap=plt.cm.Blues)
plt.title("Average cluster intensity")

plt.savefig('%s_averaged.png' % (identifier), bbox_inches='tight')

if args.write:
    print "Writing clusters to database."
    # No need to clean up here, just overwrite by _id.
    for c in range(n_clusters):
        (nr, nc) = model.get_shape(c)
        (row_ind, col_ind) = model.get_indices(c)
        
        cluster_val = None
        if nr > 25 or nc > 50:
            print "Nulling cluster %d: shape (%d, %d)" % (c, nr, nc)
        else:
            cluster_val = c
            
        for ri in row_ind:
            data_list[ri]['cluster'] = cluster_val
            datastream.save(data_list[ri])
        for ci in col_ind:
            events_list[ci]['cluster'] = cluster_val
            events.save(events_list[ci])            
開發者ID:TurkServer,項目名稱:CrowdMapper,代碼行數:32,代碼來源:tagging_biclustering.py


注:本文中的sklearn.cluster.bicluster.SpectralCoclustering.get_shape方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。