

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

# 調整 LightGBM 模型
<a name="lightgbm-tuning"></a>

*自動模型調校*，又稱為超參數調校，會透過在您的訓練和驗證資料集上，執行許多測試超參數範圍的任務，來尋找最佳版本的模型。模型調整著重於以下超參數：

**注意**  
學習目標函式會基於分類任務的類型自動指派，該類型由標籤欄中的唯一整數數量決定。如需詳細資訊，請參閱[LightGBM 超參數](lightgbm-hyperparameters.md)。
+ 要在模型訓練期間最佳化的學習目標函式
+ 用於在驗證期間評估模型效能的評估指標
+ 自動調整模型時要使用的一組超參數和一系列值

自動模型調整會搜尋您指定的超參數，以找到產生可最佳化所選評估指標之模型的值組合。

**注意**  
您僅能從 Amazon SageMaker SDK 使用 LightGBM 的自動模型調整功能，而不能從 SageMaker AI 主控台使用。

如需模型調校的詳細資訊，請參閱[使用 SageMaker AI 執行自動模型調校](automatic-model-tuning.md)。

## 由 LightGBM 演算法運算的評估指標
<a name="lightgbm-metrics"></a>

SageMaker AI LightGBM 演算法會運算下列指標，以用於模型驗證。評估指標會根據分類任務的類型自動指派，該類型由標籤欄中的唯一整數數目決定。


| 指標名稱 | Description | 最佳化方向 | 正則表達式 | 
| --- | --- | --- | --- | 
| rmse | 均方根誤差 | 最小化 | "rmse: ([0-9\$1\$1.]\$1)" | 
| l1 | 平均值絕對誤差。 | 最小化 | "l1: ([0-9\$1\$1.]\$1)" | 
| l2 | 均方誤差 | 最小化 | "l2: ([0-9\$1\$1.]\$1)" | 
| huber | Huber 損失 | 最小化 | "huber: ([0-9\$1\$1.]\$1)" | 
| fair | Fair 損失 | 最小化 | "fair: ([0-9\$1\$1.]\$1)" | 
| binary\$1logloss | 二進位交叉熵 | 最大化 | "binary\$1logloss: ([0-9\$1\$1.]\$1)" | 
| binary\$1error | 二進位錯誤 | 最小化 | "binary\$1error: ([0-9\$1\$1.]\$1)" | 
| auc | AUC | 最大化 | "auc: ([0-9\$1\$1.]\$1)" | 
| average\$1precision | 平均精確度分數 | 最大化 | "average\$1precision: ([0-9\$1\$1.]\$1)" | 
| multi\$1logloss | 多類交叉熵 | 最大化 | "multi\$1logloss: ([0-9\$1\$1.]\$1)" | 
| multi\$1error | 多類別錯誤分數 | 最小化 | "multi\$1error: ([0-9\$1\$1.]\$1)" | 
| auc\$1mu | AUC-mu | 最大化 | "auc\$1mu: ([0-9\$1\$1.]\$1)" | 
| cross\$1entropy | 交叉熵 | 最小化 | "cross\$1entropy: ([0-9\$1\$1.]\$1)" | 

## 可調整 LightGBM 超參數
<a name="lightgbm-tunable-hyperparameters"></a>

使用下列超參數調整 LightGBM 模型。對於最佳化 LightGBM 評估指標具有最大影響的超參數為： `learning_rate`、`num_leaves`、`feature_fraction`、`bagging_fraction`、`bagging_freq`、`max_depth` 和 `min_data_in_leaf`。如需所有 LightGBM 超參數的清單，請參閱[LightGBM 超參數](lightgbm-hyperparameters.md)。


| 參數名稱 | 參數類型 | 建議範圍 | 
| --- | --- | --- | 
| learning\$1rate | ContinuousParameterRanges | MinValue：0.001、MaxValue：0.01 | 
| num\$1leaves | IntegerParameterRanges | MinValue：10、MaxValue：100 | 
| feature\$1fraction | ContinuousParameterRanges | MinValue：0.1、MaxValue：1.0 | 
| bagging\$1fraction | ContinuousParameterRanges | MinValue：0.1、MaxValue：1.0 | 
| bagging\$1freq | IntegerParameterRanges | MinValue：0、MaxValue：10 | 
| max\$1depth | IntegerParameterRanges | MinValue：15、MaxValue：100 | 
| min\$1data\$1in\$1leaf | IntegerParameterRanges | MinValue: 10、MaxValue: 200 | 