可以尝试将tfidf_matrix转换成稠密矩阵再传入LdaModel中:

da_model = gensim.models.ldamodel.LdaModel(tfidf_matrix.todense(), num_topics=8, id2word=dict(enumerate(feature_names)), passes=10)

或者直接在构造tfidf_matrix时指定dtype为float32:

tfidf_matrix = TfidfVectorizer(max_df=0.95, min_df=2, max_features=n_features, stop_words='english', dtype=np.float32).fit_transform(docs_clean)
da_model = gensim.models.ldamodel.LdaModel(tfidf_matrix, num_topics=8, id2word=dict(enumerate(feature_names)), passes=10)
da_model = gensimmodelsldamodelLdaModeltfidf_matrix num_topics=8 id2word=dictenumeratefeature_names passes=10报错:TypeError sparse matrix length is ambiguous; use getnnz or shape0怎么修改

原文地址: http://www.cveoy.top/t/topic/dx6n 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录