【问题标题】:GridSearchCV giving " __init__() got an unexpected keyword argument 'n_topics'" errorGridSearchCV 给出“__init__() 得到了一个意外的关键字参数‘n_topics’”错误
【发布时间】:2020-08-28 02:08:37
【问题描述】:

我正在谷歌协作笔记本中运行以下代码。我已经研究过这种类型的错误,并确保在 0.24.dev0 之前更新我的 sklearn 版本,但错误一直在发生。有人可以帮忙吗?

search_params = {'n_components': [5, 10, 15, 20, 25], 'learning_decay': [.5, .7, .9]}

lda = LatentDirichletAllocation(max_iter=5, learning_method='online', learning_offset=50.,random_state=0)

model = GridSearchCV(lda, param_grid=search_params)

model.fit(data_vectorized)

GridSearchCV(cv=None, error_score='raise',
       estimator=LatentDirichletAllocation(batch_size=128, doc_topic_prior=None,
             evaluate_every=-1, learning_decay=0.7, learning_method=None,
             learning_offset=10.0, max_doc_update_iter=100, max_iter=10,
             mean_change_tol=0.001, n_components=10, n_jobs=1,
             n_topics=None, perp_tol=0.1, random_state=None,
             topic_word_prior=None, total_samples=1000000.0, verbose=0),
       fit_params=None, iid=True, n_jobs=1,
       param_grid={'n_topics': [5, 10, 15, 20, 25], 'learning_decay': [0.5, 0.7, 0.9]},
       pre_dispatch='2*n_jobs', refit=True, return_train_score='warn',
       scoring=None, verbose=0)

【问题讨论】:

    标签: python lda gridsearchcv


    【解决方案1】:

    来自sklearn documentation

    0.19 版更改:n_topics 重命名为 n_components

    看起来所有版本 >=0.19 都保留了这个更改(我检查了 0.23)

    【讨论】:

    • 很遗憾,这不起作用。我将 n_topics 重命名为 n_components,现在出现此错误:“__init__() got an unexpected keyword argument 'fit_params'”
    • 其实没关系。你解决了第一个问题。转到我的答案中提供的链接并检查您是否使用了正确的参数/参数名称。您将在几分钟内解决此问题!
    • 你是对的!让它工作。非常感谢您的帮助!
    猜你喜欢
    • 2015-06-08
    • 1970-01-01
    • 2017-05-10
    • 1970-01-01
    • 2021-03-17
    • 2013-05-05
    • 2016-06-05
    • 2020-08-20
    • 2021-09-20
    相关资源
    最近更新 更多