예제 #1
0
#transform item_user matrix to item_topic and topic_user matrix
iu_lda = LatentDirichletAllocation(n_topics=n_topics,
                                   max_iter=iters,
                                   learning_method='online',
                                   learning_offset=50.,
                                   random_state=0).fit(iu_matrix_tfidf)

tu_matrix = iu_lda.components_
it_matrix = iu_lda.fit_transform(iu_matrix_tfidf)

user_sim = hf.LDASim(ut_matrix)
item_sim = hf.LDASim(it_matrix)

user_div = hf.LDADiversity(ut_matrix)

hf.LDAClustering(item_sim, ui_matrix)

hf.draw_graph(graph)

#Clustering bipartite graph
#forming bipartite graph W
m, n = ui_matrix.shape
axis_label = np.concatenate((ui_matrix.index, ui_matrix.columns))
W = np.block([[np.zeros((m, m)), ui_matrix], [ui_matrix.T, np.zeros((n, n))]])
D = np.diag(W.sum(axis=0))
W_scaled = np.linalg.inv(D)**(1 / 2) @ W @ np.linalg.inv(D)**(1 / 2)

u, s, v = np.linalg.svd(W_scaled)
x = np.linalg.inv(D)**(1 / 2) @ u[:, 1]
예제 #2
0
def track_clustering(window_data):
    clustering = hf.LDAClustering(window_data["artist_sim"], window_data["ui"])
    clustering_labeled = dict(zip(window_data["users"], clustering))
    return (clustering_labeled)