我尝试使用 nltk.download( "stopwords" ) 下载 nltk 'stopwords' 用于 NLP 模型。显示错误



我正在学习机器学习,NLP-自然语言处理,在其中,我尝试下载NLTK停止词。我有一个错误,如下所示,代码&错误就像...没有定义Sklearn ...我也没有在代码中使用它。

我尝试使用PIP&使用命令的conda,PIP安装 - 升级NLTK(下载但未安装(conda install -c anaconda nltk(已下载但不起作用(

    # importing libraries
    import numpy as np
    import pandas as pd
    import matplotlib.pyplot as plt
    # importing dataset
    dataset = pd.read_csv('Restaurant_Reviews.tsv', delimiter='t', quoting= 3)
    # Cleaning the texts
    import re
    import nltk
    nltk.download("stopwords")
    review = re.sub('[^a-zA-Z]', ' ', dataset['Review'][0])
    review = review.lower()
#Error! is:
NameError: name 'sklearn' is not defined
Expected is to get nltk downloaded, now the error is,
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-16-12f820b60d6b> in <module>()
     14 
     15 import re
---> 16 import nltk
     17 nltk.download("stopwords")
     18 review = re.sub('[^a-zA-Z]', ' ', dataset['Review'][0])
~Anaconda4libsite-packagesnltk__init__.py in <module>()
    126 ###########################################################
    127 
--> 128 from nltk.chunk import *
    129 from nltk.classify import *
    130 from nltk.inference import *
~Anaconda4libsite-packagesnltkchunk__init__.py in <module>()
    155 from nltk.data import load
    156 
--> 157 from nltk.chunk.api import ChunkParserI
    158 from nltk.chunk.util import (ChunkScore, accuracy, tagstr2tree, conllstr2tree,
    159                              conlltags2tree, tree2conlltags, tree2conllstr, tree2conlltags,
~Anaconda4libsite-packagesnltkchunkapi.py in <module>()
     11 ##//////////////////////////////////////////////////////
     12 
---> 13 from nltk.parse import ParserI
     14 
     15 from nltk.chunk.util import ChunkScore
~Anaconda4libsite-packagesnltkparse__init__.py in <module>()
     77 from nltk.parse.malt import MaltParser
     78 from nltk.parse.evaluate import DependencyEvaluator
---> 79 from nltk.parse.transitionparser import TransitionParser
     80 from nltk.parse.bllip import BllipParser
     81 from nltk.parse.corenlp import CoreNLPParser, CoreNLPDependencyParser
~Anaconda4libsite-packagesnltkparsetransitionparser.py in <module>()
     19     from numpy import array
     20     from scipy import sparse
---> 21     from sklearn.datasets import load_svmlight_file
     22     from sklearn import svm
     23 except ImportError:
D:My DataData ScienceCurrentFocusML Python WorkspacePart 0 - Python All Codes & PrintsCodes_Selfsklearn.py in <module>()
      9 # =============================================================================
     10 #Preprocessing Imputer
---> 11 sklearn.preprocessing.Imputer(missing_values='NaN', strategy='mean', axis=0, verbose=0, copy=True)
     12 #Imputation transformer for completing missing values.
     13 
NameError: name 'sklearn' is not defined

我无法复制错误,但是如果您已经安装了Scikit-Learn,请卸载或更新它,然后重试。您也可以尝试升级numpy。请参阅此问题,导入NLTK不起作用

最新更新