2017年第六届数学建模国际赛小美赛
B题 电子邮件中的笔迹分析
原题再现:
笔迹分析是一种非常特殊的调查形式,用于将人们与书面证据联系起来。在法庭或刑事调查中,通常要求笔迹鉴定人确认笔迹样本是否来自特定的人。由于许多语言证据出现在电子邮件中,从广义上讲,笔迹分析还包括如何根据电子邮件的语言特征识别作者的问题。
作者归属是语言学家开始使用语言风格的可识别特征(从词频到首选句法结构)来识别有争议文本的作者的过程。电子邮件内容短小,作者语言风格明显。请构造一个有效的模型,通过捕获电子邮件的语言特征来识别作者。您可以使用安然电子邮件数据集来培训和测试您的模型。
安然电子邮件数据集链接:http://bailando.sims.berkeley.edu/enron_email.html
整体求解过程概述(摘要)
本文开发了一个工具,可以用来识别这类电子邮件的作者。作者的风格可以通过测量文本中的各种茎秆特征来简化为一种模式。电子邮件还包含可测量的宏结构特征。这些特征可与支持向量机(SVM)学习算法一起使用,以分类或将电子邮件的作者身份归属给作者,提供适当的消息样本以供比较。
首先,第3章讨论了实验过程的计划和范围,该实验过程用于确定分析电子邮件的作者特征和识别电子邮件的作者身份是否可行。概述了需要评估的特征列表,并说明了为什么要使用支持向量机(SVM)算法进行这项工作。特征集包括但不限于:基于文档的特征、基于单词的特征、虚词比率、字长频率分布、搭配频率、基于字符的特征和字母2-gram。
接下来,第4章详细介绍了为对电子邮件作者进行系统分类而进行的实验,并报告了实验结果。这是通过首先进行一系列实验来完成的,这些实验旨在揭示纯文本块(不是电子邮件)的成功SVM作者属性的基线值,从而设置特征集、文本大小和消息数量的约束。这些基线实验为该项目的核心——识别电子邮件文本中包含的有用特性的任务——设置了框架。本章报告的实验列表见表12(第25页)。第38页报告了这些结果,证实了迄今使用的方法可作为进一步研究电子邮件数据的基础。
最后,第5章讨论了电子邮件的属性和分析。第5.1节讨论了对电子邮件数据进行的初步实验。电子邮件数据用于本章中讨论的实验,因此可以首次测试电子邮件特定功能的影响。第5.2节概述了如何改进结果。第5.3节确定了电子邮件中讨论主题的影响。本研究的目的是使用加权的宏平均F1度量,在大约85%的水平上实现电子邮件数据的正确分类。本章报告的结果表明,在增加了电子邮件的结构特征之后,这一目标就实现了。本章报告的实验列表见表22(第39页)。
最后一章对本文的主要结论进行了总结。这也为今后的工作提出了一些可能的扩展。
模型假设:
•我们已经考虑的因素发挥着至关重要的作用。
•我们收集的数据是准确的。
•人们的写作习惯没有改变。
问题分析:
问题背景:
许多公司和机构已经开始依赖因特网来处理业务,随着个人使用因特网,特别是自万维网建立以来,电子邮件流量显著增加。Lyman和Varian(2000年)估计,2000年将发送5 000亿至6 000亿封电子邮件,进一步估计到2003年,每年发送的电子邮件将超过2万亿封。在GVU’s1第8次WWW用户调查中(Pitkow等人,1997年),84%的受访者表示电子邮件是不必要的。
随着电子邮件流量的增加,出于不正当的原因,电子邮件的使用量也随之增加。误用的例子包括:发送垃圾邮件或未经请求的商业电子邮件(UCE),这是垃圾邮件的广泛传播;发送威胁;发送恶作剧;以及计算机病毒和蠕虫的传播。此外,贩运毒品或儿童色情制品等犯罪活动很容易通过发送简单的电子邮件来协助和教唆。
本文讨论的问题包括:
•设置使用支持向量机进行分类实验的框架
•选择候选文体特征以解决电子邮件作者分类问题
•确定测试电子邮件作者身份分类是否成功的实验序列
模型的建立与求解整体论文缩略图
全部论文请见下方“ 只会建模 QQ名片” 点击QQ名片即可
部分程序代码:(代码和文档not free)
with open('x_C.pickle','rb') as f:
x_C = pickle.load(f)
f.close()
with open('y.pickle','rb') as f:
y = pickle.load(f)
f.close()
with open('x_W.pickle','rb') as f:
x_W = pickle.load(f)
f.close()
with open('x_F.pickle','rb') as f:
x_F = pickle.load(f)
f.close()
with open('x_L.pickle','rb') as f:
x_L = pickle.load(f)
f.close()
with open('x_C_W.pickle','rb') as f:
x_C_W = pickle.load(f)
f.close()
with open('x_C_F.pickle','rb') as f:
x_C_F = pickle.load(f)
f.close()
with open('x_W_F.pickle','rb') as f:
x_W_F = pickle.load(f)
f.close()
with open('x_F_L.pickle','rb') as f:
x_F_L = pickle.load(f)
f.close()
with open('x_F_C_W.pickle','rb') as f:
x_F_C_W = pickle.load(f)
f.close()
with open('x_F_C_L.pickle','rb') as f:
x_F_C_L = pickle.load(f)
f.close()
with open('x_F_L_W.pickle','rb') as f:
x_F_L_W = pickle.load(f)
f.close()
with open('x_F_C_L_W.pickle','rb') as f:
x_F_C_L_W = pickle.load(f)
f.close()
#test diffrent feaure effect (x_C)
x_train, x_test, y_train, y_test = train_test_split(x_C, y, test_size=0.2,
random_state=42)
svclf = SVC(kernel = 'linear')#default with 'rbf'
svclf.fit(x_train,y_train)
pred = svclf.predict(x_test);
print("x_C accuracy: ",sum(pred == y_test)/len(y_test))
#test diffrent feaure effect (x_W)
x_train, x_test, y_train, y_test = train_test_split(x_W, y, test_size=0.2,
random_state=42)
svclf = SVC(kernel = 'linear')#default with 'rbf'
svclf.fit(x_train,y_train)
pred = svclf.predict(x_test);
print("x_W accuracy: ",sum(pred == y_test)/len(y_test))
#test diffrent feaure effect (x_F)
x_train, x_test, y_train, y_test = train_test_split(x_F, y, test_size=0.2,
random_state=42)
svclf = SVC(kernel = 'linear')#default with 'rbf'
svclf.fit(x_train,y_train)
pred = svclf.predict(x_test);
print("x_F accuracy: ",sum(pred == y_test)/len(y_test))
#test diffrent feaure effect (x_L)
x_train, x_test, y_train, y_test = train_test_split(x_L, y, test_size=0.2,
random_state=42)
svclf = SVC(kernel = 'linear')#default with 'rbf'
svclf.fit(x_train,y_train)
pred = svclf.predict(x_test);
print("x_L accuracy: ",sum(pred == y_test)/len(y_test))
#test diffrent feaure effect (x_C_W)
x_train, x_test, y_train, y_test = train_test_split(x_C_W, y, test_size=0.2,
random_state=42)
svclf = SVC(kernel = 'linear')#default with 'rbf'
svclf.fit(x_train,y_train)
pred = svclf.predict(x_test);
print("x_C_W accuracy: ",sum(pred == y_test)/len(y_test))
#test diffrent feaure effect (x_C_F)
x_train, x_test, y_train, y_test = train_test_split(x_C_F, y, test_size=0.2,
random_state=42)
svclf = SVC(kernel = 'linear')#default with 'rbf'
svclf.fit(x_train,y_train)
pred = svclf.predict(x_test);
print("x_C_F accuracy: ",sum(pred == y_test)/len(y_test))
#test diffrent feaure effect (x_W_F)
x_train, x_test, y_train, y_test = train_test_split(x_W_F, y, test_size=0.2,
random_state=42)
svclf = SVC(kernel = 'linear')#default with 'rbf'
svclf.fit(x_train,y_train)
pred = svclf.predict(x_test);
print("x_W_F accuracy: ",sum(pred == y_test)/len(y_test))
#test diffrent feaure effect (x_F_L)
x_train, x_test, y_train, y_test = train_test_split(x_F_L, y, test_size=0.2,
random_state=42)
svclf = SVC(kernel = 'linear')#default with 'rbf'
svclf.fit(x_train,y_train)
pred = svclf.predict(x_test);
print("x_F_L accuracy: ",sum(pred == y_test)/len(y_test))
#test diffrent feaure effect (x_F_C_W)
x_train, x_test, y_train, y_test = train_test_split(x_F_C_W, y, test_size=0.2,
random_state=42)
svclf = SVC(kernel = 'linear')#default with 'rbf'
svclf.fit(x_train,y_train)
pred = svclf.predict(x_test);
print("x_F_C_W accuracy: ",sum(pred == y_test)/len(y_test))
#test diffrent feaure effect (x_F_C_L)
x_train, x_test, y_train, y_test = train_test_split(x_F_C_L, y, test_size=0.2,
random_state=42)
svclf = SVC(kernel = 'linear')#default with 'rbf'
svclf.fit(x_train,y_train)
pred = svclf.predict(x_test);
print("x_F_C_L accuracy: ",sum(pred == y_test)/len(y_test))
#test diffrent feaure effect (x_F_L_W)
x_train, x_test, y_train, y_test = train_test_split(x_F_L_W, y, test_size=0.2,
random_state=42)
svclf = SVC(kernel = 'linear')#default with 'rbf'
svclf.fit(x_train,y_train)
pred = svclf.predict(x_test);
print("x_F_L_W accuracy: ",sum(pred == y_test)/len(y_test))
#test diffrent feaure effect (x_F_C_L_W)
x_train, x_test, y_train, y_test = train_test_split(x_F_C_L_W, y, test_size=0.2,
random_state=42)
svclf = SVC(kernel = 'linear')#default with 'rbf'
svclf.fit(x_train,y_train)
pred = svclf.predict(x_test);
print("x_F_C_L_W accuracy: ",sum(pred == y_test)/len(y_test))
#test diffrent kernel effect
new_kernel =['Linear','Polynomial','Radial basis function','Sigmoid tanh']
x_train, x_test, y_train, y_test = train_test_split(x_F_C_L_W, y, test_size=0.2,
random_state=42)
for kernel in new_kernel:
svclf = SVC(kernel=kernel)
svclf.fit(x_train, y_train)
pred = svclf.predict(x_test);
print(kernel," accuracy: ", sum(pred == y_test)/len(y_test))
#test diffrent gama effect
gama_lst =[0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1.0, 2.0]
x_train, x_test, y_train, y_test = train_test_split(x_F_C_L_W, y, test_size=0.2,
random_state=42)
for gama in gama_lst:
svclf = SVC(kernel = 'linear',gamma=gama)
svclf.fit(x_train, y_train)
pred = svclf.predict(x_test);
print('gama=',gama," accuracy: ", sum(pred == y_test)/len(y_test))
#test diffrent degree effect
x_train, x_test, y_train, y_test = train_test_split(x_F_C_L_W, y, test_size=0.2,
random_state=42)
for degree in range(1,11):
svclf = SVC(kernel = 'linear',degree=degree)
svclf.fit(x_train, y_train)
pred = svclf.predict(x_test);
print('gama=',degree," accuracy: ", sum(pred == y_test)/len(y_test))