Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python ';numpy.int64';对象在使用潜在dirichlet分配时不可iterable_Python_Pandas_Numpy_Lda - Fatal编程技术网

Python ';numpy.int64';对象在使用潜在dirichlet分配时不可iterable

Python ';numpy.int64';对象在使用潜在dirichlet分配时不可iterable,python,pandas,numpy,lda,Python,Pandas,Numpy,Lda,我试图将潜在的dirichlet分配算法应用于从twitter数据检索的.csv文件 目前我遇到了以下错误: Traceback (most recent call last): File "...Python\Python39\lib\tkinter\__init__.py", line 1884, in __call__ return self.func(*args) File "...\src\project.py", line 26

我试图将潜在的dirichlet分配算法应用于从twitter数据检索的.csv文件

目前我遇到了以下错误:

Traceback (most recent call last):
  File "...Python\Python39\lib\tkinter\__init__.py", line 1884, in __call__
    return self.func(*args)
  File "...\src\project.py", line 262, in topic-modelling-lda
    for i in top_topic_words:
TypeError: 'numpy.int64' object is not iterable
我使用的库:

import pandas as pd
import numpy as np
import re, random
from nltk.corpus import stopwords
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.decomposition import LatentDirichletAllocation
这是我为该函数编写的代码

def topic-modelling-lda(self):
        df = pd.read_csv('sample_dataset.csv')

        vect = CountVectorizer(max_df=0.6, min_df=4, stop_words='english')
        matrix = vect .fit_transform(df)

        LDA = LatentDirichletAllocation(n_components=5, random_state=50)
        LDA.fit(matrix)

        first_topic = LDA.components_[0]
        top_topic_words = first_topic.argsort()[-10]
        for i in top_topic_words:
            print(count_vect.get_feature_names()[i])
第262行是第一个主题中i的
。\u单词:


我不确定该如何解决这个问题。

我相信您想选择前10个单词,但使用了错误的语法。你只选择了排名第10的单词,这是不合适的。将第261行更改为该行以选择前10行,而不是仅选择第10行:

top_topic_words = first_topic.argsort()[-10:]

我相信你想要选择前10个单词,你使用了错误的语法。你只选择了排名第10的单词,这是不合适的。将第261行更改为该行以选择前10行,而不是仅选择第10行:

top_topic_words = first_topic.argsort()[-10:]