类型错误:__init__() 得到了一个意外的关键字参数“n_components”

4 python lda scikit-learn

我正在尝试应用LatentDirichletAllocation数据集。当我尝试为n_componentLDA的参数赋值时。我收到以下错误。

TypeError                                 Traceback (most recent call last)
<ipython-input-25-6f5cf163fcaf> in <module>()
     23 # tfidf = vectorizer.fit_transform(line)
     24 # print(tfidf)
---> 25 lda = LatentDirichletAllocation(n_components = 100)
     26 lda.fit(bag_of_words)
     27 tf_feature_names = vector.get_feature_names()

TypeError: __init__() got an unexpected keyword argument 'n_components'
Run Code Online (Sandbox Code Playgroud)

Grr*_*Grr 6

如果您使用的是旧版本的 sklearn (< 0.19),则应使用n_topicsarg 代替n_components

lda = LatentDirichletAllocation(n_topics=100)
Run Code Online (Sandbox Code Playgroud)

旧界面的文档在0.18 版中可用sklearn.LatentDirichletAllocation