

自 2025 年 11 月 7 日起，Amazon Fraud Detector 不再向新客戶開放。對於類似 Amazon Fraud Detector 的功能，請探索 Amazon SageMaker、AutoGluon 和 AWS WAF。

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 即時預測
<a name="real-time-fraud-prediction"></a>

您可以透過呼叫 `GetEventPrediction` API 即時評估線上活動是否有詐騙。您可以提供每個請求中單一事件的相關資訊，並根據與指定偵測器相關聯的詐騙預測邏輯，同步接收模型分數和結果。

## 即時詐騙預測的運作方式
<a name="how-real-time-prediction-works"></a>

`GetEventPrediction` API 使用指定的偵測器版本來評估為事件提供的事件中繼資料。在評估期間，Amazon Fraud Detector 會先為新增至偵測器版本的模型產生模型分數，然後將結果傳遞至規則進行評估。規則會依規則執行模式指定執行 （請參閱[建立偵測器版本](https://docs.aws.amazon.com/frauddetector/latest/ug/create-a-detector-version.html))。在回應中，Amazon Fraud Detector 會提供模型分數，以及與相符規則相關聯的任何結果。

## 取得即時詐騙預測
<a name="gettting-real-time-prediction"></a>

若要取得即時詐騙預測，請確定您已建立並發佈包含詐騙預測模型和規則的偵測器，或只是規則集。

您可以使用 AWS 命令列界面 (AWS CLI) 或其中一個 Amazon Fraud Detector SDKs 呼叫 [GetEventPrediction](https://docs.aws.amazon.com/frauddetector/latest/api/API_GetEventPrediction.html) API 操作，即時取得事件的詐騙預測。

若要使用 API，請在每個請求中提供單一事件的資訊。作為請求的一部分，您必須指定 `detectorId` Amazon Fraud Detector 將使用 來評估事件。您可以選擇性地指定 `detectorVersionId`。如果`detectorVersionId`未指定 ，Amazon Fraud Detector 將使用偵測器的 `ACTIVE `版本。

您可以選擇性地傳送資料，透過在 欄位中傳遞資料來叫用 SageMaker AI 模型`externalModelEndpointBlobs`。

### 使用 取得詐騙預測 適用於 Python (Boto3) 的 AWS SDK
<a name="get-a-fraud-prediction-using-the-aws-python-sdk"></a>

若要產生詐騙預測，請呼叫 `GetEventPrediction` API。以下範例假設您已完成 [B 部分：產生詐騙預測](part-b.md)。作為回應的一部分，您將收到模型分數，以及任何相符的規則和對應的結果。您可以在 [aws-fraud-detector-samples GitHub 儲存庫](https://github.com/aws-samples/aws-fraud-detector-samples)上找到`GetEventPrediction`請求的其他範例。

```
import boto3
fraudDetector = boto3.client('frauddetector')

fraudDetector.get_event_prediction(
detectorId = 'sample_detector',
eventId = '802454d3-f7d8-482d-97e8-c4b6db9a0428',
eventTypeName = 'sample_registration',
eventTimestamp = '2020-07-13T23:18:21Z',
entities = [{'entityType':'sample_customer', 'entityId':'12345'}],
eventVariables = {
    'email_address' : 'johndoe@exampledomain.com',
    'ip_address' : '1.2.3.4'
}
)
```