【问题标题】:Non-Negative Matrix Factorization - IndexError: index 4 is out of bounds for axis 1 with size 4非负矩阵分解 - IndexError:索引 4 超出轴 1 的范围,大小为 4
【发布时间】:2017-11-01 03:41:00
【问题描述】:

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

 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,没有任何问题。任何帮助将不胜感激

【问题讨论】:

  • 请提供完整的代码,明确定义了 input_document_lower、vectorizer 和 no_topics。这个 (pastebin.com/JUM0dquy) 代码对我有用。

标签: python machine-learning topic-modeling nmf


【解决方案1】:

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

【讨论】:

【解决方案2】:

正如 Yotaro 所说,n_components 必须等于或小于 no_topics

no_topics, words = tfidf_model.shape

nmf = NMF(n_components=no_topics, random_state=1, alpha=.1, l1_ratio=.5,init='nndsvd').fit(tfidf_model)

【讨论】:

    【解决方案3】:

    您必须将 no_topics 变量设置为 tfidf_model.shape 的 x 坐标

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-18
      • 2020-10-28
      • 2015-08-06
      • 2021-05-16
      • 1970-01-01
      • 1970-01-01
      • 2018-04-10
      • 2018-05-09
      相关资源
      最近更新 更多