Neo4j 欺诈演示
简介
欺诈是一个日益严重的问题,每年给企业造成数十亿美元的资金和时间损失。使用传统方法检测和调查欺诈很困难;欺诈者使用日益复杂的技术来隐藏其活动,而他们的活动模式很难或根本不可能通过关系模型发现。即使在可以通过 SQL 指定模式的情况下,由于需要大量的连接操作,生成的查询也编写复杂且性能不佳。
借助 Neo4j,您可以使用灵活的、原生的图数据库以及算法来构建应用程序,以发现和调查复杂的欺诈行为,帮助快速准确地识别可疑活动,从而提高评分模型的效用。您可以快速匹配数据和关系中的复杂模式,使用高级算法揭露欺诈行为者的路径和中间人,并使用实体解析找到重复和可疑的配置文件。
本演示将展示如何使用 Neo4j 图数据库查找可疑活动模式;您将学到:
-
如何使用示例数据设置 Neo4j AuraDB 实例
-
了解用于在数据中查找潜在欺诈指示模式的入门图数据模型
-
查找可疑模式的示例查询,包括欺诈团伙、可能表明欺诈账户的共享标识符,以及流向高风险账户的结构化交易
先决条件
要运行这些示例,您需要以下内容:
-
Web 浏览器和互联网访问。
-
一个 Neo4j AuraDB 数据库实例。这些示例可以在任何层级运行,包括免费和专业层级(包括免费试用)。您可以在此处注册 AuraDB。按照本演示中的说明操作将替换数据库实例中的数据,因此请务必备份您不想丢失的任何数据;或者,您可以创建一个新的实例来使用。
-
(可选,但推荐)Git 客户端软件以下载演示资产。
-
可选:如果想尝试编辑数据模型的工具,请本地安装 Cypher Workbench。
设置
-
确保您的 Neo4j AuraDB 实例正在运行。如果您是 AuraDB 新用户,请在此处创建账户,然后点击“创建实例”。您可以选择任何实例类型:image::create_aura_instance.png[align="center"] 请务必保存凭据以登录您的数据库实例。在继续下一步之前,请等待实例状态达到“运行中”(RUNNING)。
-
从 https://github.com/neo4j-product-examples/demo-fraud 克隆 Git 仓库
git clone https://github.com/neo4j-product-examples/demo-fraud.git
或者,您可以使用 GitHub 上的“下载 ZIP”选项下载一份副本。
-
在 Aura 控制台中,使用“三个点”菜单选择“备份与恢复”

-
使用“浏览”按钮或拖放方式,在您在第 2 步中克隆的 Git 仓库的 dump 目录中找到 dump 文件。

-
请仔细阅读关于替换实例数据的警告,并在准备好后继续。

-
当您的数据库实例达到“运行中”(RUNNING)状态时,您就可以运行示例了。
图数据模型
下图展示了用于说明欺诈概念的数据模型

此图中的实体(也称为*标签*)主要类型包括:
-
客户 - 在金融机构拥有一或多个账户的实体,例如个人或企业
-
账户 - 金融机构中的账户。如果该账户位于“我们”的机构(即构建欺诈检测图的机构),则可称之为“内部”账户。其他机构的账户可称之为“外部”账户。如果一个外部账户位于指定的高风险司法管辖区,则该账户节点也将具有高风险司法管辖区(HighRiskJurisdiction)标签。
-
交易发生在两个账户之间,其中至少一个必须是内部账户(毕竟,除非交易的一方在我们的机构,否则我们无法了解其他机构账户之间的交易)。
-
电子邮件、电话号码、地址 - 这些节点存储客户的人口统计信息
如果您想在 Cypher Workbench 中试用数据模型,可以在您复制的仓库的 model/Neo4j_cypher_workbench_model.json 中找到数据模型导出的副本
欺诈模式
本演示使用 NeoDash 展示示例数据集中的欺诈模式。我们将调查的模式包括:
-
欺诈团伙
-
共享 PII 的客户
-
追踪发送到高风险司法管辖区的资金来源
仪表板已保存在您在上一步恢复的数据库备份中,因此要运行仪表板,只需访问 https://neodash.graphapp.io/,点击“现有仪表板”(Existing Dashboard),然后提供您的数据库凭据和连接详细信息。

仪表板已保存在您在上一步恢复的数据库备份中,因此要运行仪表板,只需访问 https://neodash.graphapp.io/,点击“现有仪表板”(Existing Dashboard),然后提供您的数据库凭据和连接详细信息。

导航仪表板
仪表板有三个页面,每个页面对应一种模式。每个页面还有两个名为“*报告*”(Reports)的窗格;每个报告都显示 Cypher 查询的结果。您可以通过点击报告右上角的设置按钮(三个点)查看底层查询。
每个页面上的第一个报告会显示该模式出现的列表,并为每个示例提供一个可点击的按钮。如果您点击一个按钮,该页面上的另一个报告将更新以显示该出现项的详细图谱。
欺诈团伙
交易欺诈团伙指的是一群人合谋从事欺诈活动,例如通过多个账户转移资金。这些团伙在不同地点运作,并采用各种策略来逃避检测。在本演示的这一部分中,我们将使用 Cypher 的模式匹配功能来查找具有以下特征的可疑团伙:
-
团伙交易始于并终于同一账户
-
构成团伙的交易按时间顺序发生
-
团伙中的账户是唯一的(同一账户不会出现多次)
-
团伙中的每个账户保留最多 20% 的转移资金
-
该团伙由 3 到 16 个账户组成
查找此模式的 Cypher 查询如下所示:
MATCH (a:Account)-[f:SENT]->(first_tx:Transaction)
MATCH path=(a)-[f]->(first_tx)
(
(tx_i:Transaction)-[:RECEIVED]->(a_i:Account)-[:SENT]->(tx_j:Transaction)
WHERE tx_i.date < tx_j.date
AND tx_i.amount >= tx_j.amount >= 0.80 * tx_i.amount
){2,15}
(last_tx:Transaction)-[:RECEIVED]->(a)
WHERE COUNT {WITH a, a_i UNWIND [a] + a_i AS b RETURN DISTINCT b} =
size([a] + a_i)
RETURN COUNT {WITH a, a_i UNWIND [a] + a_i AS b RETURN DISTINCT b} as ringSize, a.accountNumber as EntryAccount, path as ring
此查询使用 Cypher 的量化路径模式(QPP)功能,以确保找到的团伙具备所有所述特征。如果规则发生变化,它简洁且易于更新。您可以在此处阅读有关 QPP 查询工作原理的更多信息。如果尝试使用 SQL 和关系数据库创建相同的查询,结果将如下所示:
select a1.account_id, a1.account_number,
t1.*,
a2.account_id, a2.account_number,
t2.*,
a3.account_id, a3.account_number,
t3.*,
3 as ring_size
from account a1, account a2, account a3,
transfer_transaction t1, transfer_transaction t2, transfer_transaction t3
where a1.account_id = t1.source_account_id
and t1.recipient_account_id = a2.account_id
and a2.account_id = t2.source_account_id
and t2.recipient_account_id = a3.account_id
and a3.account_id = t3.source_account_id
and t3.recipient_account_id = a1.account_id
and a1.account_id <> a2.account_id
and a1.account_id <> a3.account_id
and a2.account_id <> a3.account_id
and t2.transaction_date > t1.transaction_date
and t3.transaction_date > t2.transaction_date
and t2.transaction_amount >= .8 * t1.transaction_amount
and t3.transaction_amount >= .8 * t2.transaction_amount
FOR JSON
UNION ALL
select a1.account_id, a1.account_number,
t1.*,
a2.account_id, a2.account_number,
t2.*,
a3.account_id, a3.account_number,
t3.*
a4.account_id, a4.account_number,,
t4.*,
4 as ring_size
from account a1, account a2, account a3,
account a4,
transfer_transaction t1, transfer_transaction t2, transfer_transaction t3,
transfer_transaction t4
where a1.account_id = t1.source_account_id
and t1.recipient_account_id = a2.account_id
and a2.account_id = t2.source_account_id
and t2.recipient_account_id = a3.account_id
and a3.account_id = t3.source_account_id
and t3.recipient_account_id = a4.account_id
and a4.account_id = t4.source_account_id
and t4.recipient_account_id = a1.account_id
and a1.account_id <> a2.account_id
and a1.account_id <> a3.account_id
and a1.account_id <> a4.account_id
and a2.account_id <> a3.account_id
and a2.account_id <> a4.account_id
and a3.account_id <> a4.account_id
and t2.transaction_date > t1.transaction_date
and t3.transaction_date > t2.transaction_date
and t4.transaction_date > t3.transaction_date
and t2.transaction_amount >= .8 * t1.transaction_amount
and t3.transaction_amount >= .8 * t2.transaction_amount
and t4.transaction_amount >= .8 * t3.transaction_amount
FOR JSON
UNION ALL
select a1.account_id, a1.account_number,
t1.*,
a2.account_id, a2.account_number,
t2.*,
a3.account_id, a3.account_number,
t3.*
a4.account_id, a4.account_number,
t4.*,
a5.account_id, a5.account_number,
t5.*,
5 as ring_size
from account a1, account a2, account a3,
account a4, account a5,
transfer_transaction t1, transfer_transaction t2, transfer_transaction t3,
transfer_transaction t4, transfer_transaction t5
where a1.account_id = t1.source_account_id
and t1.recipient_account_id = a2.account_id
and a2.account_id = t2.source_account_id
and t2.recipient_account_id = a3.account_id
and a3.account_id = t3.source_account_id
and t3.recipient_account_id = a4.account_id
and a4.account_id = t4.source_account_id
and t4.recipient_account_id = a5.account_id
and a5.account_id = t5.source_account_id
and t5.recipient_account_id = a1.account_id
and a1.account_id <> a2.account_id
and a1.account_id <> a3.account_id
and a1.account_id <> a4.account_id
and a1.account_id <> a5.account_id
and a2.account_id <> a3.account_id
and a2.account_id <> a4.account_id
and a2.account_id <> a5.account_id
and a3.account_id <> a4.account_id
and a3.account_id <> a5.account_id
and a4.account_id <> a5.account_id
and t2.transaction_date > t1.transaction_date
and t3.transaction_date > t2.transaction_date
and t4.transaction_date > t3.transaction_date
and t5.transaction_date > t4.transaction_date
and t2.transaction_amount >= .8 * t1.transaction_amount
and t3.transaction_amount >= .8 * t2.transaction_amount
and t4.transaction_amount >= .8 * t3.transaction_amount
and t5.transaction_amount >= .8 * t4.transaction_amount
FOR JSON
这个示例已经超过 100 行代码、24 个等值连接和 37 个筛选条件。眼尖的读者可能还会注意到,它只涵盖包含 3 到 5 个账户的团伙。使用关系数据库等传统技术,与图示例相比,编写代码/调试/维护所需时间更长,并且运行速度慢得多(因为存在大量连接)。
您可以在仪表板的“交易团伙”(Transaction Ring)页面查看欺诈团伙。*“团伙”*(Rings)报告列出了所有找到的团伙——包括团伙的规模以及团伙中第一个账户的账户号码

您可以点击任何“入口账户”(Entry Account)号码以显示所选团伙的详细信息。

共享 PII
第二种可能表明可疑活动的模式是查找共享相同 PII(例如电话号码、电子邮件账户、地址、设备标识符等)的多个客户。这可能表明不良行为者正在创建合成身份来隐藏其欺诈活动。Cypher 查询如下所示:
MATCH (c1:Customer)-[r1:USES_PHONE|USES_EMAIL|RESIDES_AT]->(item:PhoneNumber|Email|Address)<-[r2:USES_PHONE|USES_EMAIL|RESIDES_AT]-(c2:Customer)
WHERE elementId(c1) < elementId(c2)
WITH item, count(distinct c1)+1 AS nbSharedIdentifierRelationships
RETURN elementId(item) AS itemId, case labels(item)[0]
when "Address" then item.street
when "PhoneNumber" then item.number
when "Email" then item.emailAddress
else "u" end as identity, labels(item)[0] AS itemType, nbSharedIdentifierRelationships
ORDER BY nbSharedIdentifierRelationships DESC LIMIT 10
它查找由多个客户共享的 PII、共享 PII 的客户数量,以及共享 PII 的类型和详细信息。查询结果显示在“*共享 PII 的客户*”(Customers Sharing PII)报告中

点击任何项目 ID 将显示 PII 的详细信息和关联客户。

向高风险司法管辖区付款
我们将调查的最后一个模式是我们的客户向高风险司法管辖区的账户转账。当我们检测到此模式时,我们希望看到相关转账,以及其他转入此客户账户的交易,并且转入账户的金额大约(定义为“向高风险司法管辖区总转账的 90% 到 110% 之间”)。这将使我们能够看到潜在的非法交易以及可能涉及的其他账户。我们还将在演示中使用特定的日期范围——通常,金融机构会在当前日期附近查找此模式。
WITH datetime('2024-08-22') as dt
MATCH (l:Account)-[:SENT]->(last_t:Transaction)-[:RECEIVED]->(hrj:HighRiskJurisdiction)
WHERE last_t.date >= dt
WITH l, hrj, SUM(last_t.amount) AS total_hrj_transctions, dt
MATCH path=(first)((a1)-[:SENT]->(t)-[:RECEIVED]->(a2)
WHERE COLLECT {
WITH a1, a2
MATCH (a1)-[:SENT]->(some_t)-[:RECEIVED]->(a2)
WHERE some_t.date >= dt
WITH SUM(some_t.amount) AS s
RETURN 0.9 * total_hrj_transctions <= s <= 1.1 * total_hrj_transctions
} = [TRUE]
)*(l)-[:SENT]->(tx:Transaction)-[:RECEIVED]->(hrj)
WHERE NOT EXISTS {
WITH first
MATCH (before)-[:SENT]->(tx)-[:RECEIVED]->(first)
WHERE tx.date >= dt
WITH SUM(tx.amount) AS sx, before
WHERE 0.9 * total_hrj_transctions <= sx <= 1.1 * total_hrj_transctions
RETURN before
} AND
tx.date >= dt
RETURN path
仪表板显示了直接向外部高风险司法管辖区账户发送资金的账户列表

点击账户号码将显示相关转账以及可能涉及的其他账户和交易。

后续步骤
现在您已经了解如何使用 Neo4j 图数据库查找银行活动中的可疑模式,您可能希望进一步探索。一些想法包括:
-
将您自己的数据加载到相同的图数据模型中,并运行本演示中的相同查询。一个简单的方法是创建与仓库数据目录中文件格式匹配的关系表或 CSV 文件,然后使用 model/neo4j_importer_model.json 通过 AuraDB 的数据导入服务加载数据。

可以通过在导入服务中创建新的数据模型,然后从“三个点”菜单中打开 neo4j_importer_model.json 文件来加载它。

-
探索其他可能表明欺诈的可疑模式
-
向观察列表中的账户持有人转账
-
向现金密集型企业转入和转出资金(由于难以追踪实体现金,这些企业常被洗钱者利用)
-
-
阅读更多关于 Neo4j 为何是构建欺诈检测和调查应用程序的优秀数据库的原因。