Skip to main content
 首页 » 编程设计

python之非负矩阵分解之IndexError : index 4 is out of bounds for axis 1 with size 4

2025年05月04日20zengkefu

这是我将使用的数据集的一部分:

 u'tff prep normalized clean water permability ncwp result outside operating range', 
 u'technician inadvertently omitted documenting initial room \u201c cleaned sanitized field form', 
 u'sunflower seed observed floor room 1', 

这是我使用的代码:

tfidf_model = vectorizer.fit_transform(input_document_lower) 
tfidf_feature_names = vectorizer.get_feature_names() 
nmf = NMF(n_components=no_topics, random_state=1, alpha=.1, l1_ratio=.5, init='nndsvd').fit(tfidf_model) 

如标题所述,我收到以下错误:

IndexError: index 4 is out of bounds for axis 1 with size 4 

老实说,我不确定如何开始调试它。我使用相同的数据集构建了一个 LDA,没有任何问题。任何帮助将不胜感激

请您参考如下方法:

我认为 n_components 应该小于 (tfidf_model.shape[0], tfidf_model[1])。