python 地址相似性判断

一、概述

地址相似性判断在金融反欺诈中有重要的应用,通过相似的地址判断,构建知识图谱,可以获取申请客户是否属于同公司的欺诈申请。

二、关键步骤

(1)地址分词

(2)制作地址语料库

(3)相似性判断

三、python实现

1.依赖包:jieba,gensim

2.地址历史数据

3.测试地址

“北京市朝阳区建国门外大街5号院”

4.代码

# 1 分词
# 1.1 历史比较文档的分词
all_doc_list = []
for doc in all_doc:
doc_list = [word for word in jieba.cut_for_search(doc)]
# doc_list = [word for word in jieba.cut(doc)]
all_doc_list.append(doc_list)

# 1.2 测试文档的分词
doc_test="北京市朝阳区建国门外大街5号院"
doc_test_list = [word for word in jieba.cut_for_search(doc_test)]
# doc_test_list = [word for word in jieba.cut(doc_test)]
# 2 制作语料库
# 2.1 获取词袋
dictionary = corpora.Dictionary(all_doc_list)

# 2.2 制作语料库
# 历史文档的二元组向量转换
corpus = [dictionary.doc2bow(doc) for doc in all_doc_list]
# 测试文档的二元组向量转换
doc_test_vec = dictionary.doc2bow(doc_test_list)

# 3 相似度分析
# 3.1 使用TF-IDF模型对语料库建模
tfidf = models.TfidfModel(corpus)
# 获取测试文档中,每个词的TF-IDF值
tfidf[doc_test_vec]

# 3.2 对每个目标文档,分析测试文档的相似度
index = similarities.SparseMatrixSimilarity(tfidf[corpus], num_features=len(dictionary.keys()))
sim = index[tfidf[doc_test_vec]]

# 根3.3 据相似度排序
sorted(enumerate(sim), key=lambda item: -item[1])

结果

[(3, 0.7674924), (7, 0.73630047), (4, 0.7342692), (10, 0.7111159), (0, 0.70615286), (11, 0.42776945), (6, 0.3859625), (2, 0.3746654), (8, 0.36219177), (1, 0.35470122), (9, 0.30778316), (5, 0.29451278), (12, 0.08421353), (13, 0.0), (14, 0.0), (15, 0.0), (16, 0.0), (17, 0.0)]

5.优化方向

1.是否需要加停用词过滤?

2.是否需要提取地址关键词?

 

猜你喜欢

转载自www.cnblogs.com/Byron-ourLove/p/9274263.html
今日推荐