没有合适的资源?快使用搜索试试~ 我知道了~
16337233王凯祺1
需积分: 0 0 下载量 44 浏览量
2022-08-03
17:43:53
上传
评论
收藏 615KB PDF 举报
温馨提示
试读
20页
机器学习 Quora Question Pairs 实验报告数据科学与计算机学院 计算机科学与技术 2016 级王凯祺 163372332019 年 6 月 1
资源详情
资源评论
资源推荐
机器学习 Quora Question Pairs 实验报告
数据科学与计算机学院 计算机科学与技术 2016 级
王凯祺 16337233
2019 年 6 月 12 日
1 使用的系统 + 编码语言 + 环境说明
操作系统:macOS Mojave 10.14.5
代码语言:Python 3
环境说明:
1 pip3 freeze
1 boto==2.49.0
2 boto3==1.9.162
3 botocore==1.12.162
4 certifi==2019.3.9
5 chardet==3.0.4
6 cycler==0.10.0
7 docutils==0.14
8 gensim==3.7.3
9 idna==2.8
10 jmespath==0.9.4
11 joblib==0.13.2
12 kiwisolver==1.1.0
13 matplotlib==3.1.0
14 nltk==3.4.1
15 numpy==1.16.4
16 pandas==0.24.2
17 pyparsing==2.4.0
18 python-dateutil==2.8.0
19 python-Levenshtein==0.12.0
20 pytz==2019.1
21 requests==2.22.0
22 s3transfer==0.2.1
23 scikit-learn==0.21.2
24 scipy==1.3.0
25 seaborn==0.9.0
26 six==1.12.0
27 sklearn==0.0
28 smart-open==1.8.4
29 urllib3==1.25.3
1
30 xgboost==0.90
2 简单的流程图
2.1 数据处理方法
2.1.1 观察数据特征
训练集共
404
,
290
行、
6
列,每行包含
id
、问题
1 id
、问题
2 id
、问题
1
、问题
2
、是否重复
(标签)。
测试集共 2, 345, 796 行、3 列,每行包含 id 、问题 1、问题 2。
大致看了几个问题,就觉得处理起来挺棘手的。比如“What is the step by step guide to invest in
share market in india?”和“What is the step by step guide to invest in share market?”是不重复的两
个问题,但它们之间只差了一个“in India”。这直接导致一个问题,如果我们只根据两个句子的相似
度来判定是否重复,这样的问题组合就会被判为重复。再比如,“How can I be a good geologist?”和
“What should I do to be a great geologist?”是重复的,我们要让机器自己学到“How”和”What shoud
I do” 是同一个意思。这必须要有相当数量的同类样本才能学到的。
在如此大量的测试集面前,却只有这么点训练集。我觉得很难从训练集中提取到太多有用的东
西,然后应用到测试集中。
2.1.2 数据清洗
我参考了一个名为 The Importance of Cleaning Text 的 Kernel(https://www.kaggle.com/currie32/the-
importance-of-cleaning-text),对输入数据进行清洗。
清洗主要做的任务是:
• 将非 ascii 字符全部删去,规范化单词,如将“’re”替换为“are”。
• 删除标点符号。
• 删除停词,如 is、the、a 。
• 将单词处理成原型。
主要代码:
1 def text_to_wordlist(text, remove_stop_words=True, stem_words=False):
2 # Clean the text, with the option to remove stop_words and to stem words.
3 global stops
4 text = re.sub(r"[^A-Za-z0-9]", " ", text)
5 text = re.sub(r"what’s", "", text)
6 text = re.sub(r"What’s", "", text)
7 text = re.sub(r"\’s", " ", text)
8 text = re.sub(r"\’ve", " have ", text)
9 text = re.sub(r"can’t", "cannot ", text)
10 text = re.sub(r"n’t", " not ", text)
11 text = re.sub(r"I’m", "I am", text)
12 text = re.sub(r" m ", " am ", text)
2
13 text = re.sub(r"\’re", " are ", text)
14 text = re.sub(r"\’d", " would ", text)
15 text = re.sub(r"\’ll", " will ", text)
16 text = re.sub(r"60k", " 60000 ", text)
17
text = re.sub(r"
e g ", " eg ", text)
18 text = re.sub(r" b g ", " bg ", text)
19 text = re.sub(r"\0s", "0", text)
20 text = re.sub(r" 9 11 ", "911", text)
21 text = re.sub(r"e-mail", "email", text)
22 text = re.sub(r"\s{2,}", " ", text)
23 text = re.sub(r"quikly", "quickly", text)
24 text = re.sub(r" usa ", " America ", text)
25 text = re.sub(r" USA ", " America ", text)
26 text = re.sub(r" u s ", " America ", text)
27 text = re.sub(r" uk ", " England ", text)
28 text = re.sub(r" UK ", " England ", text)
29 text = re.sub(r"india", "India", text)
30 text = re.sub(r"switzerland", "Switzerland", text)
31 text = re.sub(r"china", "China", text)
32 text = re.sub(r"chinese", "Chinese", text)
33 text = re.sub(r"imrovement", "improvement", text)
34 text = re.sub(r"intially", "initially", text)
35 text = re.sub(r"quora", "Quora", text)
36 text = re.sub(r" dms ", "direct messages ", text)
37 text = re.sub(r"demonitization", "demonetization", text)
38 text = re.sub(r"actived", "active", text)
39 text = re.sub(r"kms", " kilometers ", text)
40 text = re.sub(r"KMs", " kilometers ", text)
41 text = re.sub(r" cs ", " computer science ", text)
42 text = re.sub(r" upvotes ", " up votes ", text)
43 text = re.sub(r" iPhone ", " phone ", text)
44 text = re.sub(r"\0rs ", " rs ", text)
45 text = re.sub(r"calender", "calendar", text)
46 text = re.sub(r"ios", "operating system", text)
47 text = re.sub(r"gps", "GPS", text)
48 text = re.sub(r"gst", "GST", text)
49 text = re.sub(r"programing", "programming", text)
50 text = re.sub(r"bestfriend", "best friend", text)
51 text = re.sub(r"dna", "DNA", text)
52 text = re.sub(r"III", "3", text)
53 text = re.sub(r"the US", "America", text)
54 text = re.sub(r"Astrology", "astrology", text)
55 text = re.sub(r"Method", "method", text)
56 text = re.sub(r"Find", "find", text)
57 text = re.sub(r"banglore", "Banglore", text)
58 text = re.sub(r" J K ", " JK ", text)
59
60 # Remove punctuation from text
61 text = ’’.join([c for c in text if c not in punctuation])
62
3
剩余19页未读,继续阅读
whph
- 粉丝: 23
- 资源: 305
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0