簡體   English   中英

對於NLP模型,我嘗試使用nltk.download(“stopwords”)下載nltk'stopwords'。 哪個顯示錯誤

[英]I tried downloading nltk 'stopwords' using nltk.download(“stopwords”), for NLP model. Which shows an error

我正在學習機器學習,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

我無法重現錯誤,但如果您已經安裝了scikit-learn,請卸載或更新它,然后重試。 您也可以嘗試升級numpy。 請參考這個問題, 導入nltk不起作用

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM