从社交媒体分析到风险管理和网络犯罪保护,处理文本数据已经变得前所未有的重要。
目录
(1)文本数据的基本体征提取
(1.1)词汇数量
(1.2)字符数量
(1.3)平均字长
(1.4)停用词数量
(1.5)特殊字符数量
(1.6)数字数量
(1.7)大写字母数量
(2)文本数据的基本预处理
(2.1)小写转换
(2.2)去除标点符号
(2.3)去除停用词
(2.4)去除频现词a>
(2.5) 去除稀疏词
(2.6)拼写校正
(2.7)分词(tokenization)
(2.8)词干提取(stemming)
(2.9)词形还原(lemmatization)
(3)高级文本处理
(3.1)N-grams语言模型
(3.2)词频
(3.3)逆文档频率
(3.4)TF-IDF
(3.5)词袋
(3.6)情感分析
(3.7)词嵌入
------------------------------------------------------分割线-----------------------------------------------------
(1)文本数据的基本体征提取
开始之前,我们使用pandas将数据集加载进来,以便后面其他任务的使用,数据集是Twitter情感文本数据集。
import pandas as pd
train=pd.read_csv("files/data/python46-data/train_E6oV3lV.csv")
print(train.head(10))
id label tweet
0 1 0 @user when a father is dysfunctional and is s...
1 2 0 @user @user thanks for #lyft credit i can't us...
2 3 0 bihday your majesty
3 4 0 #model i love u take with u all the time in ...
4 5 0 factsguide: society now #motivation
5 6 0 [2/2] huge fan fare and big talking before the...
6 7 0 @user camping tomorrow @user @user @user @use...
7 8 0 the next school year is the year for exams.ð��...
8 9 0 we won!!! love the land!!! #allin #cavs #champ...
9 10 0 @user @user welcome here ! i'm it's so #gr...