欺诈主题建模

Python 中的欺诈检测

Charlotte Werger

Data Scientist

主题建模:发现文本中的隐藏模式

  1. 在文本中发现主题
  2. "这段文本讲什么"
  3. 概念上类似于聚类
  4. 比较欺诈与非欺诈案例的主题,用作特征或标记
  5. 或者:数据中是否有指向欺诈的特定主题?
Python 中的欺诈检测

潜在狄利克雷分配(LDA)

使用 LDA 可得到:

  1. "每个文本的主题"模型(即概率)
  2. "每个主题的词"模型

自建主题模型:

  1. 清洗数据
  2. 用词典与语料创建词袋
  3. 将词典和语料输入 LDA 模型
Python 中的欺诈检测

潜在狄利克雷分配(LDA)

Python 中的欺诈检测

词袋:词典与语料

from gensim import corpora
# 创建词典:统计词出现次数
dictionary = corpora.Dictionary(cleaned_emails)
# 过滤(不)常见词 
dictionary.filter_extremes(no_below=5, keep_n=50000)
# 创建语料
corpus = [dictionary.doc2bow(text) for text in cleaned_emails]
Python 中的欺诈检测

使用 gensim 的潜在狄利克雷分配(LDA)

import gensim
# 定义 LDA 模型
ldamodel = gensim.models.ldamodel.LdaModel(corpus, num_topics = 3, 
id2word=dictionary, passes=15)
# 打印三个主题及其高频词
topics = ldamodel.print_topics(num_words=4)
for topic in topics:
    print(topic)
(0, 0.029*"email" + 0.016*"send" + 0.016*"results" + 0.016*"invoice")
(1, 0.026*"price" + 0.026*"work" + 0.026*"management" + 0.026*"sell")
(2, 0.029*"distribute" + 0.029*"contact" + 0.016*"supply" + 0.016*"fast")
Python 中的欺诈检测

让我们来练习!

Python 中的欺诈检测

Preparing Video For Download...