

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

# 手動建立解決方案版本
<a name="creating-a-solution-version"></a>

完成 後[在 Amazon Personalize 中設定自訂解決方案](customizing-solution-config.md)，您就可以開始訓練：
+  如果您的解決方案使用自動訓練，解決方案會依照您指定的訓練頻率為您建立解決方案版本。根據預設，所有新解決方案都會每 7 天使用自動訓練來建立新的解決方案版本。您仍然可以手動建立解決方案版本。如需詳細資訊，請參閱[設定自動訓練](solution-config-auto-training.md)。
+ 如果您關閉解決方案的自動訓練，或想要手動訓練，您可以手動建立解決方案版本。*解決方案版本*是指經過訓練的機器學習模型。您可以使用 主控台、 AWS Command Line Interface (AWS CLI) 或 AWS SDKs建立解決方案版本。如果您的解決方案版本狀態為 CREATE\_PENDING 或 CREATE\_IN\_PROGRESS，您可以使用 [StopSolutionVersionCreation](API_StopSolutionVersionCreation.md)操作來停止解決方案版本建立程序。請參閱 [停止建立解決方案版本](stop-solution-version.md)。

如果訓練因錯誤而未完成，您不需要支付訓練費用。如果您的解決方案版本狀態為 CREATE\_PENDING 或 CREATE\_IN\_PROGRESS，您可以停止解決方案版本建立程序。若要停止建立解決方案版本，請導覽至解決方案版本詳細資訊頁面，然後選擇**停止**。如需詳細資訊，請參閱[停止建立解決方案版本](stop-solution-version.md)。

**Topics**
+ [建立解決方案版本 （主控台）](#create-solution-version-console)
+ [建立解決方案版本 (AWS CLI)](#create-solution-version-cli)
+ [建立解決方案版本AWS SDKs)](#create-solution-version-sdk)

## 建立解決方案版本 （主控台）
<a name="create-solution-version-console"></a>

若要使用 Amazon Personalize 主控台手動建立新的解決方案版本，您可以從解決方案的詳細資訊頁面開始訓練。

**建立新的解決方案版本**

1. 在 [https://console.aws.amazon.com/personalize/home](https://console.aws.amazon.com/personalize/home)：// 開啟 Amazon Personalize 主控台並登入您的帳戶。

1. 導覽至資料集群組頁面，然後使用您的新解決方案選擇資料集群組。

1. 在導覽窗格的**自訂資源**下，選擇**解決方案和配方**。

1. 在**解決方案和配方**頁面上，選擇您要為其建立解決方案版本的解決方案。

1. 在解決方案概觀頁面上，選擇**建立解決方案版本**以開始訓練新的模型。

在解決方案詳細資訊頁面上，您可以在**解決方案版本**區段中追蹤訓練進度。訓練完成時，狀態為**作用中**，您可以使用 Amazon Personalize 提供的指標進行評估。如需詳細資訊，請參閱[使用指標評估 Amazon Personalize 解決方案版本](working-with-training-metrics.md)。

 當解決方案版本為 ACTIVE 時，您就可以使用它來取得建議。如何使用作用中解決方案版本取決於如何取得建議：
+  如需即時建議，您可以使用 Amazon Personalize 行銷活動部署 ACTIVE 解決方案版本。您可以使用行銷活動來取得使用者的建議。請參閱 [使用行銷活動部署 Amazon Personalize 解決方案版本建立行銷活動](campaigns.md)。
+ 對於批次建議，您可以在建立批次推論任務或批次區段任務時指定 ACTIVE 解決方案版本。請參閱 [取得批次項目建議](getting-batch-recommendations.md) 或 [取得批次使用者區段](getting-user-segments.md)。

## 建立解決方案版本 (AWS CLI)
<a name="create-solution-version-cli"></a>

當您的解決方案為 ACTIVE 時，請執行下列命令來訓練模型。將 取代`solution arn`為 的 Amazon Resource Name (ARN) 解決方案[在 Amazon Personalize 中設定自訂解決方案](customizing-solution-config.md)。

```
aws personalize create-solution-version \
  --solution-arn {{solution arn}}
```

這時會顯示解決方案版本 ARN，例如：

```
{
  "solutionVersionArn": "arn:aws:personalize:us-west-2:acct-id:solution/SolutionName/<version-id>"
}
```

使用 `describe-solution-version`命令檢查解決方案版本的訓練狀態。提供在前一個步驟中傳回的解決方案版本 ARN。如需 API (匯入 API) 的詳細資訊，請參閱「[DescribeSolutionVersion](API_DescribeSolutionVersion.md)」。

```
aws personalize describe-solution-version \
  --solution-version-arn {{solution version arn}}
```

這時會顯示解決方案版本的屬性和訓練 `status`。此狀態一開始會顯示為 CREATE PENDING，例如：

```
{
  "solutionVersion": {
      "solutionVersionArn": "arn:aws:personalize:us-west-2:acct-id:solution/solutionName/<version-id>",
      ...,
      "status": "CREATE PENDING"
  }
}
```

當 `status`為 時，訓練即完成，`ACTIVE`您可以使用 Amazon Personalize 提供的指標進行評估。如需詳細資訊，請參閱[使用指標評估 Amazon Personalize 解決方案版本](working-with-training-metrics.md)。如果訓練因錯誤而未完成，您不需要支付訓練費用。

如果您的解決方案版本狀態為 CREATE\_PENDING 或 CREATE\_IN\_PROGRESS，您可以使用 [StopSolutionVersionCreation](API_StopSolutionVersionCreation.md)操作來停止解決方案版本建立程序。請參閱 [停止建立解決方案版本](stop-solution-version.md)。

 當解決方案版本為 ACTIVE 時，您就可以使用它來取得建議。如何使用作用中解決方案版本取決於如何取得建議：
+  如需即時建議，您可以使用 Amazon Personalize 行銷活動部署 ACTIVE 解決方案版本。您可以使用行銷活動來取得使用者的建議。請參閱 [使用行銷活動部署 Amazon Personalize 解決方案版本建立行銷活動](campaigns.md)。
+ 對於批次建議，您可以在建立批次推論任務或批次區段任務時指定 ACTIVE 解決方案版本。請參閱 [取得批次項目建議](getting-batch-recommendations.md) 或 [取得批次使用者區段](getting-user-segments.md)。

## 建立解決方案版本AWS SDKs)
<a name="create-solution-version-sdk"></a>

當您的解決方案為 ACTIVE 時，請使用下列程式碼來建立解決方案版本。從 指定 Amazon Resource Name (ARN)[在 Amazon Personalize 中設定自訂解決方案](customizing-solution-config.md)。使用 [DescribeSolutionVersion](API_DescribeSolutionVersion.md)操作來擷取解決方案版本的狀態。

------
#### [ SDK for Python (Boto3) ]

```
import boto3

personalize = boto3.client('personalize')
# Store the solution ARN
solution_arn = '{{solution arn}}'
        
# Use the solution ARN to get the solution status.
solution_description = personalize.describe_solution(solutionArn = 'solution_arn')['solution']
print('Solution status: ' + solution_description['status'])

# Use the solution ARN to create a solution version.
print ('Creating solution version')
response = personalize.create_solution_version(solutionArn = solution_arn)
solution_version_arn = response['solutionVersionArn']
print('Solution version ARN: ' + solution_version_arn)

# Use the solution version ARN to get the solution version status.
solution_version_description = personalize.describe_solution_version(
    solutionVersionArn = solution_version_arn)['solutionVersion']
print('Solution version status: ' + solution_version_description['status'])
```

------
#### [ SDK for Java 2.x ]

```
public static String createPersonalizeSolutionVersion(PersonalizeClient personalizeClient, String solutionArn) {
        long maxTime = 0;
        long waitInMilliseconds = 30 * 1000; // 30 seconds
        String solutionStatus = "";
        String solutionVersionStatus = "";
        String solutionVersionArn = "";

        try {
            DescribeSolutionRequest describeSolutionRequest = DescribeSolutionRequest.builder()
                .solutionArn(solutionArn)
                .build();
            
            maxTime = Instant.now().getEpochSecond() + 3 * 60 * 60;

            // Wait until solution is active. 
            while (Instant.now().getEpochSecond() < maxTime) {

                solutionStatus = personalizeClient.describeSolution(describeSolutionRequest).solution().status();
                System.out.println("Solution status: " + solutionStatus);

                if (solutionStatus.equals("ACTIVE") || solutionStatus.equals("CREATE FAILED")) {
                    break;
                }
                try {
                    Thread.sleep(waitInMilliseconds);
                } catch (InterruptedException e) {
                    System.out.println(e.getMessage());
                }
            }
            
            // Once the solution is active, start creating a solution version.
            
            if (solutionStatus.equals("ACTIVE")) {

                CreateSolutionVersionRequest createSolutionVersionRequest = CreateSolutionVersionRequest.builder()
                    .solutionArn(solutionArn)
                    .build();
                
                CreateSolutionVersionResponse createSolutionVersionResponse = personalizeClient.createSolutionVersion(createSolutionVersionRequest);
                solutionVersionArn = createSolutionVersionResponse.solutionVersionArn();

                System.out.println("Solution version ARN: " + solutionVersionArn);

                DescribeSolutionVersionRequest describeSolutionVersionRequest = DescribeSolutionVersionRequest.builder() 
                    .solutionVersionArn(solutionVersionArn)
                    .build();
                
                maxTime = Instant.now().getEpochSecond() + 3 * 60 * 60;
                
                while (Instant.now().getEpochSecond() < maxTime) {

                    // Use the solution version ARN to get the solution version status.
                    solutionVersionStatus = personalizeClient.describeSolutionVersion(describeSolutionVersionRequest).solutionVersion().status();
                    System.out.println("Solution version status: " + solutionVersionStatus);
    
                    if (solutionVersionStatus.equals("ACTIVE") || solutionVersionStatus.equals("CREATE FAILED")) {
                        break;
                    }
                    try {
                        Thread.sleep(waitInMilliseconds);
                    } catch (InterruptedException e) {
                        System.out.println(e.getMessage());
                    }
                }
                return solutionVersionArn;
            }
        } catch(PersonalizeException e) {
            System.err.println(e.awsErrorDetails().errorMessage());
            System.exit(1);
        }
        return "";
    }
```

------
#### [ SDK for JavaScript v3 ]

```
// Get service clients module and commands using ES6 syntax.
import { CreateSolutionVersionCommand } from "@aws-sdk/client-personalize";
import { personalizeClient } from "./libs/personalizeClients.js";
// Or, create the client here.
// const personalizeClient = new PersonalizeClient({ region: "REGION"});

// Set the solution version parameters.
export const solutionVersionParam = {
  solutionArn: "SOLUTION_ARN" /* required */,
};

export const run = async () => {
  try {
    const response = await personalizeClient.send(
      new CreateSolutionVersionCommand(solutionVersionParam),
    );
    console.log("Success", response);
    return response; // For unit tests.
  } catch (err) {
    console.log("Error", err);
  }
};
run();
```

------



若要檢查解決方案版本目前的狀態，請呼叫 [DescribeSolutionVersion](API_DescribeSolutionVersion.md) 操作，並傳遞 `CreateSolutionVersion` 操作傳回的解決方案版本 ARN。當 `status`為 時，訓練即完成，`ACTIVE`您可以使用 Amazon Personalize 提供的指標進行評估。如需詳細資訊，請參閱[使用指標評估 Amazon Personalize 解決方案版本](working-with-training-metrics.md)。如果訓練因錯誤而未完成，您不需要支付訓練費用。

如果您的解決方案版本狀態為 CREATE\_PENDING 或 CREATE\_IN\_PROGRESS，您可以使用 [StopSolutionVersionCreation](API_StopSolutionVersionCreation.md)操作來停止解決方案版本建立程序。請參閱 [停止建立解決方案版本](stop-solution-version.md)。

 當解決方案版本為 ACTIVE 時，您就可以使用它來取得建議。如何使用作用中解決方案版本取決於如何取得建議：
+  如需即時建議，您可以使用 Amazon Personalize 行銷活動部署 ACTIVE 解決方案版本。您可以使用行銷活動來取得使用者的建議。請參閱 [使用行銷活動部署 Amazon Personalize 解決方案版本建立行銷活動](campaigns.md)。
+ 對於批次建議，您可以在建立批次推論任務或批次區段任務時指定 ACTIVE 解決方案版本。請參閱 [取得批次項目建議](getting-batch-recommendations.md) 或 [取得批次使用者區段](getting-user-segments.md)。