

如需與 Amazon Timestream for LiveAnalytics 類似的功能，請考慮使用 Amazon Timestream for InfluxDB。它提供簡化的資料擷取和單一位數毫秒查詢回應時間，以進行即時分析。[在這裡](https://docs.aws.amazon.com//timestream/latest/developerguide/timestream-for-influxdb.html)進一步了解。

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

# Amazon SageMaker AI
<a name="Sagemaker"></a>

 您可以使用 Amazon SageMaker Notebooks 將機器學習模型與 Amazon Timestream 整合。為了協助您開始使用，我們建立了一個 SageMaker 筆記本範例，用於處理來自 Timestream 的資料。資料會從多執行緒 Python 應用程式持續傳送資料，插入 Timestream。範例 SageMaker 筆記本的原始程式碼和範例 Python 應用程式可在 GitHub 中使用。

1. 依照 和 中所述的指示建立資料庫[建立 資料庫](console_timestream.md#console_timestream.db.using-console)和資料表[建立資料表](console_timestream.md#console_timestream.table.using-console)。

1. 依照 GitHub 的指示複製[多執行緒 Python 範例應用程式的](https://github.com/awslabs/amazon-timestream-tools/tree/mainline/tools/python/continuous-ingestor) [ GitHub](https://docs.github.com/en/free-pro-team@latest/github/creating-cloning-and-archiving-repositories/cloning-a-repository) 儲存庫。

1. 依照 GitHub 的指示複製[範例 Timestream SageMaker 筆記本](https://github.com/awslabs/amazon-timestream-tools/blob/master/integrations/sagemaker)的 [ GitHub](https://docs.github.com/en/free-pro-team@latest/github/creating-cloning-and-archiving-repositories/cloning-a-repository) 儲存庫。

1. 依照 [README](https://github.com/awslabs/amazon-timestream-tools/blob/mainline/tools/python/continuous-ingestor/README.md) 中的指示執行應用程式，以持續將資料擷取至 Timestream。

1. 依照[此處](https://docs.aws.amazon.com/sagemaker/latest/dg/gs-config-permissions.html)說明的指示為 Amazon SageMaker 建立 Amazon S3 儲存貯體。 Amazon SageMaker 

1. 建立已安裝最新 boto3 的 Amazon SageMaker 執行個體：除了[此處](https://docs.aws.amazon.com/sagemaker/latest/dg/gs-setup-working-env.html)說明之外，請依照下列步驟操作：

   1. 在**建立筆記本**執行個體頁面上，按一下**其他組態**

   1. 按一下**生命週期組態 - *選用***，然後選取**建立新的生命週期組態**

   1. 在*建立生命週期組態*精靈方塊中，執行下列動作：

      1. 將所需的名稱填入組態，例如 `on-start`

      1. 在啟動筆記本指令碼中，從 [ Github](https://github.com/aws-samples/amazon-sagemaker-notebook-instance-lifecycle-config-samples/blob/master/scripts/install-pip-package-single-environment/on-start.sh) 複製貼上指令碼內容 

      1. 在貼上的指令碼`PACKAGE=boto3`中`PACKAGE=scipy`將 取代為 。

1. 按一下**建立組態**

1. 前往 AWS 管理主控台中的 IAM 服務，並尋找筆記本執行個體新建立的 SageMaker 執行角色。

1. 將 的 IAM 政策`AmazonTimestreamFullAccess`連接至執行角色。
**注意**  
IAM `AmazonTimestreamFullAccess` 政策不限於特定資源，不適合用於生產。對於生產系統，請考慮使用限制存取特定資源的政策。

1. 當筆記本執行個體的狀態為 **InService** 時，選擇**開啟 Jupyter** 以啟動執行個體的 SageMaker 筆記本

1.  選取上傳按鈕，將檔案 `timestreamquery.py`和 **上傳至**`Timestream_SageMaker_Demo.ipynb`筆記本

1. 選擇 `Timestream_SageMaker_Demo.ipynb`
**注意**  
如果您看到**找不到核心**的快顯視窗，請選擇 **conda\$1python3**，然後按一下**設定核心**。

1. 修改 `DB_NAME`、`TABLE_NAME`、 `bucket`和 `ENDPOINT`，以符合訓練模型的資料庫名稱、資料表名稱、S3 儲存貯體名稱和區域。

1. 選擇**播放**圖示以執行個別儲存格

1. 當您到達儲存格 時`Leverage Timestream to find hosts with average CPU utilization across the fleet`，請確定輸出至少傳回 2 個主機名稱。
**注意**  
如果輸出中有少於 2 個主機名稱，您可能需要使用更多執行緒和主機規模，將範例 Python 應用程式擷取資料重新執行到 Timestream。

1. 當您到達儲存格 時`Train a Random Cut Forest (RCF) model using the CPU utilization history`，`train_instance_type`請根據訓練任務的資源需求來變更

1. 當您到達儲存格 時`Deploy the model for inference`，`instance_type`請根據推論任務的資源需求來變更
**注意**  
可能需要幾分鐘的時間來訓練模型。訓練完成後，您會在儲存格的輸出中看到**已完成 - 訓練任務**的訊息。

1. 執行儲存格`Stop and delete the endpoint`以清除資源。您也可以從 SageMaker 主控台停止和刪除執行個體