作者:落幕YL他 | 来源:互联网 | 2023-07-28 17:43
Problems pic
我正在尝试使用LDA,但是当我运行LDA时在python中发生了一些问题.LDA.fit(doc_term_matrix)问题
import numpy as np
import pandas as pd
import os
reviews_datasets = pd.read_csv("Reviews.csv")
reviews_datasets = reviews_datasets.head(20000)
reviews_datasets.dropna()
from sklearn.feature_extraction.text import CountVectorizer
count_vect = CountVectorizer(max_df=0.8,min_df=2,stop_words='english')
doc_term_matrix = count_vect.fit_transform(reviews_datasets['Text'].values.astype('U'))
from sklearn.decomposition import LatentDirichletallocation
LDA = LatentDirichletallocation(n_compOnents=5,random_state=42)
LDA.fit(doc_term_matrix)
我的错误提示
File "",line 1,in
runfile('C:/Users/PC/.spyder-py3/temp.py',wdir='C:/Users/PC/.spyder-py3')
File "C:\Users\PC\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py",line 827,in runfile
execfile(filename,namespace)
File "C:\Users\PC\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py",line 110,in execfile
exec(compile(f.read(),filename,'exec'),namespace)
File "C:/Users/PC/.spyder-py3/temp.py",line 8,in
reviews_datasets = pd.read_csv("Reviews.csv")
File "C:\Users\PC\Anaconda3\lib\site-packages\pandas\io\parsers.py",line 702,in parser_f
return _read(filepath_or_buffer,kwds)
File "C:\Users\PC\Anaconda3\lib\site-packages\pandas\io\parsers.py",line 435,in _read
data = parser.read(nrows)
File "C:\Users\PC\Anaconda3\lib\site-packages\pandas\io\parsers.py",line 1154,in read
df = DataFrame(col_dict,columns=columns,index=index)
File "C:\Users\PC\Anaconda3\lib\site-packages\pandas\core\frame.py",line 392,in __init__
mgr = init_dict(data,index,columns,dtype=dtype)
File "C:\Users\PC\Anaconda3\lib\site-packages\pandas\core\internals\construction.py",line 212,in init_dict
return arrays_to_mgr(arrays,data_names,line 61,in arrays_to_mgr
return create_block_manager_from_arrays(arrays,arr_names,axes)
File "C:\Users\PC\Anaconda3\lib\site-packages\pandas\core\internals\managers.py",line 1666,in create_block_manager_from_arrays
blocks = form_blocks(arrays,names,line 1754,in form_blocks
object_blocks = _simple_blockify(items_dict['ObjectBlock'],np.object_)
File "C:\Users\PC\Anaconda3\lib\site-packages\pandas\core\internals\managers.py",line 1800,in _simple_blockify
values,placement = _stack_arrays(tuples,dtype)
File "C:\Users\PC\Anaconda3\lib\site-packages\pandas\core\internals\managers.py",line 1863,in _stack_arrays
stacked[i] = _asarray_compat(arr)