資源簡介
機器學習(10)-NLP自然語言處理大量餐館評論:數據集與源碼
機器學習(10)-NLP自然語言處理大量餐館評論:數據集與源碼
機器學習(10)-NLP自然語言處理大量餐館評論:數據集與源碼
代碼片段和文件信息
import?numpy?as?np
import?matplotlib.pyplot?as?plt
import?pandas?as?pd
dataset?=?pd.read_csv(‘R_Reviews.tsv‘?delimiter?=?‘\t‘?quoting?=?3)
######################################################################################
import?re?#清楚數字標點的標準庫
import?nltk?#下載含有所有虛詞的list
nltk.download(‘stopwords‘)?#list名字:stopwords?下載
from?nltk.corpus?import?stopwords?#下載之后?載入字典
from?nltk.stem.porter?import?PorterStemmer?#stem:詞根?PorterStemmer:?詞根函數庫
corpus?=?[]?#空list
for?i?in?range(0?1000):
????review?=?re.sub(‘[^a-zA-Z]‘?‘?‘?dataset[‘Review‘][i])?#去除標點,數字,去除之后用空格代替,只留下大小寫字母
????review?=?review.lower()?#全部轉換成小寫
????review?=?review.split()?#將句子字符串,轉換成含有不同單詞的list?
????ps?=?PorterStemmer()?#取詞根化的方程
????review?=?[ps.stem(word)?for?word?in?review?if?not?word?in?set(stopwords.words(‘english‘))]?#?用詞
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????2519??2019-01-14?17:23??10\nlp.py
?????文件???????61332??2016-11-15?10:38??10\R_Reviews.tsv
- 上一篇:機器學習8-樸素貝葉斯:數據集與
- 下一篇:28335數碼管代碼
評論
共有 條評論