Python机器学习及实践——进阶篇:流行库/模型实践
1.自然语言处理包(NLTK)
使用词袋法(Bag-of-Words)对示例文本进行特征向量化
# 使用词袋法对示例文本进行特征向量化
sent1 = 'The cat is walking in the bedroom.'
sent2 = 'A dog was running across the kinchen.'
from sklearn.feature_extraction.text import CountVectorizer
count_vec = CountVectorizer()
sentences = [sent1, sent2]
# 输出特征向量化后的表示
print(count_vec.fit_transform(sentences).toarray())
# 输出向量各个维度的特征含义
print(count_vec.get_feature_names())
使用NLTK对示例文本进行语言学分析
# 使用NLTK对示例文本进行语言学分析
import nltk
nltk.download()
# 对句子进行词汇分割和正规化,有些