本页介绍了如何创建和管理 AML AI 回测预测结果。回测预测会使用针对现有历史数据训练的模型。在这些月份内,数据集必须包含存在可疑活动或调查开始日期(导致 AML_EXIT
事件)的相关方。如需详细了解 AML AI 如何为各种相关方分配标签,请参阅风险案例的生命周期。
相同的数据集可用于训练和回测,前提是训练 结束日期早于回测日期。
准备工作
-
如需获得创建和管理回测结果所需的权限,请让您的管理员为您授予项目的 Financial Services Admin (
financialservices.admin
) IAM 角色。 如需详细了解如何授予角色,请参阅管理对项目、文件夹和组织的访问权限。 - 创建实例
- 创建模型
- 创建数据集
创建回测结果
某些 API 方法会返回长时间运行的操作 (LRO)。这些方法是异步的,并返回 Operation 对象;有关详情,请参阅 REST 参考文档。当方法返回响应时,操作可能尚未完成。对于这些方法,请将 然后查看结果一般来说,所有 POST、PUT、UPDATE 和 DELETE 操作 长期运行
发送请求
如需创建回测结果,请使用 projects.locations.instances.backtestResults.create
方法。
在使用任何请求数据之前,请先进行以下替换:
PROJECT_ID
:IAM 设置中列出的 Google Cloud 项目 IDLOCATION
:实例的位置;请使用某个受支持的地区显示营业地点us-central1
us-east1
asia-south1
europe-west1
europe-west2
europe-west4
northamerica-northeast1
southamerica-east1
australia-southeast1
INSTANCE_ID
:实例的用户定义标识符BACKTEST_RESULTS_ID
:回测结果的用户定义标识符MODEL_ID
:用户定义的模型标识符BACKTEST_DATASET_ID
:用于回测的数据集的用户定义标识符;表不应包含训练标签列BACKTEST_END_DATE
:最近一个时间 数据用于为回测生成特征。此日期不能早于 数据集的结束时间。使用 RFC3339 UTC“Zulu”格式(例如2014-10-02T15:01:23Z
)。PARTY_INVESTIGATIONS_PER_PERIOD_HINT
: 一个数字,用于提示调谐器根据此数据要调查的派对数 每期(每月)。这用于控制模型的评估方式。例如,首次尝试使用 AML AI 时,我们建议您根据现有自动提醒系统发出的提醒,将此值设置为平均每月调查的相关方数量。
请求 JSON 正文:
{ "model": "projects/PROJECT_ID/locations/LOCATION/instances/INSTANCE_ID/models/MODEL_ID", "dataset": "projects/PROJECT_ID/locations/LOCATION/instances/INSTANCE_ID/datasets/BACKTEST_DATASET_ID", "endTime": "BACKTEST_END_DATE", "backtestPeriods": 5, "performanceTarget": { "partyInvestigationsPerPeriodHint": "PARTY_INVESTIGATIONS_PER_PERIOD_HINT" } }
如需发送请求,请选择以下方式之一:
curl
将请求正文保存在名为 request.json
的文件中。在终端中运行以下命令,在当前目录中创建或覆盖此文件:
cat > request.json << 'EOF' { "model": "projects/PROJECT_ID/locations/LOCATION/instances/INSTANCE_ID/models/MODEL_ID", "dataset": "projects/PROJECT_ID/locations/LOCATION/instances/INSTANCE_ID/datasets/BACKTEST_DATASET_ID", "endTime": "BACKTEST_END_DATE", "backtestPeriods": 5, "performanceTarget": { "partyInvestigationsPerPeriodHint": "PARTY_INVESTIGATIONS_PER_PERIOD_HINT" } } EOF
然后,执行以下命令以发送 REST 请求:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://financialservices.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/instances/INSTANCE_ID/backtestResults?backtest_result_id=BACKTEST_RESULTS_ID"
PowerShell
将请求正文保存在名为 request.json
的文件中。在终端中运行以下命令,在当前目录中创建或覆盖此文件:
@' { "model": "projects/PROJECT_ID/locations/LOCATION/instances/INSTANCE_ID/models/MODEL_ID", "dataset": "projects/PROJECT_ID/locations/LOCATION/instances/INSTANCE_ID/datasets/BACKTEST_DATASET_ID", "endTime": "BACKTEST_END_DATE", "backtestPeriods": 5, "performanceTarget": { "partyInvestigationsPerPeriodHint": "PARTY_INVESTIGATIONS_PER_PERIOD_HINT" } } '@ | Out-File -FilePath request.json -Encoding utf8
然后,执行以下命令以发送 REST 请求:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://financialservices.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/instances/INSTANCE_ID/backtestResults?backtest_result_id=BACKTEST_RESULTS_ID" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
{ "name": "projects/PROJECT_ID/locations/LOCATION/operations/OPERATION_ID", "metadata": { "@type": "type.googleapis.com/google.cloud.financialservices.v1.OperationMetadata", "createTime": CREATE_TIME, "target": "projects/PROJECT_ID/locations/LOCATION/instances/INSTANCE_ID/backtestResults/BACKTEST_RESULTS_ID", "verb": "create", "requestedCancellation": false, "apiVersion": "v1" }, "done": false }
检查结果
如需检查是否已创建回测结果,请使用 projects.locations.operations.get
方法。如果响应中包含 "done": false
,请重复该命令,直到出现
响应包含 "done": true
。这些操作可能需要几分钟时间
需要几个小时才能完成。
在使用任何请求数据之前,请先进行以下替换:
PROJECT_ID
:列出的 Google Cloud 项目 ID 在 IAM 设置中LOCATION
:实例的位置; 请使用 支持的区域显示位置us-central1
us-east1
asia-south1
europe-west1
europe-west2
europe-west4
northamerica-northeast1
southamerica-east1
australia-southeast1
OPERATION_ID
:操作的标识符
如需发送请求,请选择以下方式之一:
curl
执行以下命令:
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://financialservices.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/operations/OPERATION_ID"
PowerShell
执行以下命令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://financialservices.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/operations/OPERATION_ID" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
{ "name": "projects/PROJECT_ID/locations/LOCATION/operations/OPERATION_ID", "metadata": { "@type": "type.googleapis.com/google.cloud.financialservices.v1.OperationMetadata", "createTime": "2023-03-14T15:52:55.358979323Z", "endTime": "2023-03-14T16:52:55.358979323Z", "target": "projects/PROJECT_ID/locations/LOCATION/instances/INSTANCE_ID/backtestResults/BACKTEST_RESULTS_ID", "verb": "create", "requestedCancellation": false, "apiVersion": "v1" }, "done": true, "response": { "@type": "type.googleapis.com/dataresidency.monitoring.DataResidencyAugmentedView", "tpIds": [ "i608e8cf4abb2a7d9-tp" ] } }
导出元数据
如需从回测结果中导出元数据,请使用 projects.locations.instances.backtestResults.exportMetadata
方法。
如需了解详情,请参阅 AML 输出数据模型中导出的元数据。
在使用任何请求数据之前,请先进行以下替换:
PROJECT_ID
:IAM 设置中列出的 Google Cloud 项目 IDLOCATION
:实例的位置;请使用某个受支持的地区显示营业地点us-central1
us-east1
asia-south1
europe-west1
europe-west2
europe-west4
northamerica-northeast1
southamerica-east1
australia-southeast1
INSTANCE_ID
:用户定义的实例标识符BACKTEST_RESULTS_ID
:回测结果的用户定义标识符BQ_OUTPUT_DATASET_NAME
:a BigQuery 数据集,用于导出描述回测结果的结构化元数据的表STRUCTURED_METADATA_TABLE
:要 将结构化元数据写入WRITE_DISPOSITION
:如果目标表已存在,则发生的操作;请使用以下值之一:-
WRITE_EMPTY
:仅在 BigQuery 表为空时导出数据。 -
WRITE_TRUNCATE
:清空 BigQuery 表中的所有现有数据 然后再写入表中。
-
请求 JSON 正文:
{ "structuredMetadataDestination": { "tableUri": "bq://PROJECT_ID.BQ_OUTPUT_DATASET_NAME.STRUCTURED_METADATA_TABLE", "writeDisposition": "WRITE_DISPOSITION" } }
如需发送请求,请选择以下方式之一:
curl
将请求正文保存在名为 request.json
的文件中。在终端中运行以下命令,在当前目录中创建或覆盖此文件:
cat > request.json << 'EOF' { "structuredMetadataDestination": { "tableUri": "bq://PROJECT_ID.BQ_OUTPUT_DATASET_NAME.STRUCTURED_METADATA_TABLE", "writeDisposition": "WRITE_DISPOSITION" } } EOF
然后,执行以下命令以发送 REST 请求:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://financialservices.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/instances/INSTANCE_ID/backtestResults/BACKTEST_RESULTS_ID:exportMetadata"
PowerShell
将请求正文保存在名为 request.json
的文件中。在终端中运行以下命令,在当前目录中创建或覆盖此文件:
@' { "structuredMetadataDestination": { "tableUri": "bq://PROJECT_ID.BQ_OUTPUT_DATASET_NAME.STRUCTURED_METADATA_TABLE", "writeDisposition": "WRITE_DISPOSITION" } } '@ | Out-File -FilePath request.json -Encoding utf8
然后,执行以下命令以发送 REST 请求:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://financialservices.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/instances/INSTANCE_ID/backtestResults/BACKTEST_RESULTS_ID:exportMetadata" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
{ "name": "projects/PROJECT_ID/locations/LOCATION/operations/OPERATION_ID", "metadata": { "@type": "type.googleapis.com/google.cloud.financialservices.v1.OperationMetadata", "createTime": CREATE_TIME, "target": "projects/PROJECT_ID/locations/LOCATION/instances/INSTANCE_ID/backtestResults/BACKTEST_RESULTS_ID", "verb": "exportMetadata", "requestedCancellation": false, "apiVersion": "v1" }, "done": false }
如需详细了解如何获取长时间运行的操作 (LRO) 的结果,请参阅 检查结果。
获取回测结果
如需获取回测结果,请使用 projects.locations.instances.backtestResults.get
方法。
在使用任何请求数据之前,请先进行以下替换:
PROJECT_ID
:IAM 设置中列出的 Google Cloud 项目 IDLOCATION
:实例的位置; 请使用 支持的区域显示位置us-central1
us-east1
asia-south1
europe-west1
europe-west2
europe-west4
northamerica-northeast1
southamerica-east1
australia-southeast1
INSTANCE_ID
:用户定义的实例标识符BACKTEST_RESULTS_ID
:回测结果的用户定义标识符
如需发送请求,请选择以下方式之一:
curl
执行以下命令:
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://financialservices.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/instances/INSTANCE_ID/backtestResults/BACKTEST_RESULTS_ID"
PowerShell
执行以下命令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://financialservices.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/instances/INSTANCE_ID/backtestResults/BACKTEST_RESULTS_ID" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
{ "name": "projects/PROJECT_ID/locations/LOCATION/instances/INSTANCE_ID/backtestResults/BACKTEST_RESULTS_ID", "createTime": CREATE_TIME, "updateTime": UPDATE_TIME, "state": "ACTIVE", "dataset": "projects/PROJECT_ID/locations/LOCATION/instances/INSTANCE_ID/datasets/BACKTEST_DATASET_ID", "model": "projects/PROJECT_ID/locations/LOCATION/instances/INSTANCE_ID/models/MODEL_ID", "endTime": "BACKTEST_END_DATE", "performanceTarget": { "partyInvestigationsPerPeriodHint": "PARTY_INVESTIGATIONS_PER_PERIOD_HINT" }, "lineOfBusiness": "RETAIL" }
更新回测结果
如需更新回测结果,请使用 projects.locations.instances.backtestResults.patch
方法。
只能更新回测结果中的 labels
字段。以下
更新键值对的示例
用户标签
与回测结果相关联。
在使用任何请求数据之前,请先进行以下替换:
PROJECT_ID
:IAM 设置中列出的 Google Cloud 项目 IDLOCATION
:实例的位置;请使用某个受支持的地区显示位置us-central1
us-east1
asia-south1
europe-west1
europe-west2
europe-west4
northamerica-northeast1
southamerica-east1
australia-southeast1
INSTANCE_ID
:用户定义的实例标识符BACKTEST_RESULTS_ID
:回测结果的用户定义标识符KEY
:键值对中用于整理的键 回测结果。如需了解详情,请参阅labels
。VALUE
:键值对中用于整理的值 回测结果。如需了解详情,请参阅labels
。
请求 JSON 正文:
{ "labels": { "KEY": "VALUE" } }
如需发送请求,请选择以下方式之一:
curl
将请求正文保存在名为 request.json
的文件中。在终端中运行以下命令,在当前目录中创建或覆盖此文件:
cat > request.json << 'EOF' { "labels": { "KEY": "VALUE" } } EOF
然后,执行以下命令以发送 REST 请求:
curl -X PATCH \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://financialservices.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/instances/INSTANCE_ID/backtestResults/BACKTEST_RESULTS_ID?updateMask=labels"
PowerShell
将请求正文保存在名为 request.json
的文件中。在终端中运行以下命令,在当前目录中创建或覆盖此文件:
@' { "labels": { "KEY": "VALUE" } } '@ | Out-File -FilePath request.json -Encoding utf8
然后,执行以下命令以发送 REST 请求:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method PATCH `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://financialservices.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/instances/INSTANCE_ID/backtestResults/BACKTEST_RESULTS_ID?updateMask=labels" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
{ "name": "projects/PROJECT_ID/locations/LOCATION/operations/OPERATION_ID", "metadata": { "@type": "type.googleapis.com/google.cloud.financialservices.v1.OperationMetadata", "createTime": CREATE_TIME, "target": "projects/PROJECT_ID/locations/LOCATION/instances/INSTANCE_ID/backtestResults/BACKTEST_RESULTS_ID", "verb": "update", "requestedCancellation": false, "apiVersion": "v1" }, "done": false }
如需详细了解如何获取长时间运行的操作 (LRO) 的结果,请参阅检查结果。
列出回测结果
要列出给定实例的回测结果,请使用
projects.locations.instances.backtestResults.list
方法。
在使用任何请求数据之前,请先进行以下替换:
PROJECT_ID
:IAM 设置中列出的 Google Cloud 项目 IDLOCATION
:实例的位置; 请使用 支持的区域显示位置us-central1
us-east1
asia-south1
europe-west1
europe-west2
europe-west4
northamerica-northeast1
southamerica-east1
australia-southeast1
INSTANCE_ID
:实例的用户定义标识符
如需发送请求,请选择以下方式之一:
curl
执行以下命令:
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://financialservices.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/instances/INSTANCE_ID/backtestResults"
PowerShell
执行以下命令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://financialservices.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/instances/INSTANCE_ID/backtestResults" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
{ "backtestResults": [ { "name": "projects/PROJECT_ID/locations/LOCATION/instances/INSTANCE_ID/backtestResults/BACKTEST_RESULTS_ID", "createTime": CREATE_TIME, "updateTime": UPDATE_TIME, "state": "ACTIVE", "dataset": "projects/PROJECT_ID/locations/LOCATION/instances/INSTANCE_ID/datasets/BACKTEST_DATASET_ID", "model": "projects/PROJECT_ID/locations/LOCATION/instances/INSTANCE_ID/models/MODEL_ID", "endTime": "BACKTEST_END_DATE", "performanceTarget": { "partyInvestigationsPerPeriodHint": "PARTY_INVESTIGATIONS_PER_PERIOD_HINT" }, "lineOfBusiness": "RETAIL" } ] }
删除回测结果
要删除回测结果,请使用
projects.locations.instances.backtestResults.delete
方法。
在使用任何请求数据之前,请先进行以下替换:
PROJECT_ID
:IAM 设置中列出的 Google Cloud 项目 IDLOCATION
:实例的位置;使用以下任一 该 支持的区域显示位置us-central1
us-east1
asia-south1
europe-west1
europe-west2
europe-west4
northamerica-northeast1
southamerica-east1
australia-southeast1
INSTANCE_ID
:用户定义的实例标识符BACKTEST_RESULTS_ID
:回测结果的用户定义标识符
如需发送请求,请选择以下方式之一:
curl
执行以下命令:
curl -X DELETE \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://financialservices.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/instances/INSTANCE_ID/backtestResults/BACKTEST_RESULTS_ID"
PowerShell
执行以下命令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method DELETE `
-Headers $headers `
-Uri "https://financialservices.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/instances/INSTANCE_ID/backtestResults/BACKTEST_RESULTS_ID" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
{ "name": "projects/PROJECT_ID/locations/LOCATION/operations/OPERATION_ID", "metadata": { "@type": "type.googleapis.com/google.cloud.financialservices.v1.OperationMetadata", "createTime": CREATE_TIME, "target": "projects/PROJECT_ID/locations/LOCATION/instances/INSTANCE_ID/backtestResults/BACKTEST_RESULTS_ID", "verb": "delete", "requestedCancellation": false, "apiVersion": "v1" }, "done": false }
如需详细了解如何获取长时间运行的操作 (LRO) 的结果,请参阅 检查结果。