Это код для создания модели:
import gensim
NUM_TOPICS = 4
ldamodel = gensim.models.ldamodel.LdaModel(corpus,num_topics =
NUM_TOPICS,id2word=dictionary,passes=100)
ldamodel.save('model5.gensim')
topics = ldamodel.print_topics(num_words=4)
print(topics)
Это код для GridSearchCV:
search_params = {'n_components': [4, 6, 8, 10, 20], 'learning_decay': [.5, .7, .9]}
# Init Grid Search Class
model = GridSearchCV(ldamodel, param_grid=search_params)
# Do the Grid Search
model.fit(data_vectorized)
Это вывод:
*---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-108-1a35c49ac19e> in <module>
9
10 # Do the Grid Search
---> 11 model.fit(data_vectorized)
~\AppData\Local\Continuum\anaconda3\lib\site-packages\sklearn\model_selection\_search.py in fit(self, X, y, groups, **fit_params)
627
628 scorers, self.multimetric_ = _check_multimetric_scoring(
--> 629 self.estimator, scoring=self.scoring)
630
631 if self.multimetric_:
~\AppData\Local\Continuum\anaconda3\lib\site-packages\sklearn\metrics\_scorer.py in _check_multimetric_scoring(estimator, scoring)
471 if callable(scoring) or scoring is None or isinstance(scoring,
472 str):
--> 473 scorers = {"score": check_scoring(estimator, scoring=scoring)}
474 return scorers, False
475 else:
~\AppData\Local\Continuum\anaconda3\lib\site-packages\sklearn\metrics\_scorer.py in check_scoring(estimator, scoring, allow_none)
399 if not hasattr(estimator, 'fit'):
400 raise TypeError("estimator should be an estimator implementing "
--> 401 "'fit' method, %r was passed" % estimator)
402 if isinstance(scoring, str):
403 return get_scorer(scoring)
TypeError: estimator should be an estimator implementing 'fit' method, <gensim.models.ldamodel.LdaModel object at 0x000002121E55D3C8> was passed*