[英]How should I use mode.predict_generator to evaluate model performance in a Confusion Matrix?
[英]How to evaluate NMF Topic Modeling by using Confusion Matrix?
我正在使用 NMF model 进行主题建模。 我想通过混淆矩阵来评估它的性能,或者如果有其他更好的方法来评估 NMF,我也可以。 我试图在互联网上查找教程或其他资源,但找不到任何可以帮助我解决问题的东西。 下面是我用于 NMF 主题建模的完整代码。
import pandas as pd
import numpy as np
dataset = pd.read_csv(r'Preprocess_Data.csv')
dataset = reviews_datasets.head(20000)
dataset.dropna()
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn import metrics
tfidf_vect = TfidfVectorizer(max_df=0.8, min_df=2, stop_words='english')
doc_term_matrix = tfidf_vect.fit_transform(dataset['Text'].values.astype('U'))
from sklearn.decomposition import NMF
nmf = NMF(n_components=5, random_state=42)
nmf.fit(doc_term_matrix)
import random
for i in range(10):
random_id = random.randint(0,len(tfidf_vect.get_feature_names()))
print(tfidf_vect.get_feature_names()[random_id])
first_topic = nmf.components_[0]
top_topic_words = first_topic.argsort()[-10:]
for i in top_topic_words:
print(tfidf_vect.get_feature_names()[I])
for i,topic in enumerate(nmf.components_):
print(f'Top 10 words for topic #{i}:')
print([tfidf_vect.get_feature_names()[i] for i in topic.argsort()[-10:]])
print('\n')
提前感谢您的建议和意见。
如果您有与文档关联的标签,那么您可以使用主题-文档表示作为文档特征来训练分类器,并在测试集的主题-文档表示上进行测试。
否则,您需要坚持无监督的指标,例如最著名的是主题连贯性,它衡量主题的前 N 个单词的相关程度。
您可以在这里找到所有这些措施和许多其他措施: https://github.com/mind-Lab/octis#available-metrics
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.