我尝试使用nltk.download(“ stopwords”)为NLP模型下载nltk'停用词'。显示错误

时间:2019-05-03 11:07:43

标签: python jupyter-notebook nltk

我正在学习机器学习,自然语言处理(NLP),在那里,我尝试下载nltk停用词。我收到如下错误,并且代码和错误就像... sklearn未定义...我也没有在代码中使用它。.

我尝试通过命令使用pip&conda安装, pip install --upgrade 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])

~\Anaconda4\lib\site-packages\nltk\__init__.py in <module>()
    126 ###########################################################
    127 
--> 128 from nltk.chunk import *
    129 from nltk.classify import *
    130 from nltk.inference import *

~\Anaconda4\lib\site-packages\nltk\chunk\__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,

~\Anaconda4\lib\site-packages\nltk\chunk\api.py in <module>()
     11 ##//////////////////////////////////////////////////////
     12 
---> 13 from nltk.parse import ParserI
     14 
     15 from nltk.chunk.util import ChunkScore

~\Anaconda4\lib\site-packages\nltk\parse\__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

~\Anaconda4\lib\site-packages\nltk\parse\transitionparser.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 Data\Data Science\CurrentFocus\ML Python Workspace\Part 0 - Python All Codes & Prints\Codes_Self\sklearn.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

1 个答案:

答案 0 :(得分:0)

我无法重现该错误,但如果您已经安装了scikit-learn,请卸载或更新它,然后重试。您也可以尝试升级numpy。 请参考这个问题,import nltk does not work