線形回帰モデルの評価に使用されるモデルパフォーマンスメトリックは、決定係数です。通称「R二乗」で、「R2」[ 1, 2 ] と表記される。
R2は基本的に、独立変数から予測可能な応答変数の変化の割合です。つまり、R2 の値が大きいほど、モデルによって説明されます。
通常、R2 は 0 から 1 まで異なりますが、負の値を取得できる場合もあります。詳細については、[1] を参照してください。
この場合、R2 スコア '0.75' が達成されます。
123456#Computes the R2 score
R2=hgr.score( test_hdf, key='ID',
features=['MedInc', 'HouseAge', 'AveRooms', 'AveBedrms', 'Population', 'AveOccup', 'Latitude', 'Longitude'],
label='Target')
R2出力:
0.7535287346593224
参照
①決定係数
最適なパラメータ検索による HGBT モデルの改善
HGBT モデルを改善するために、線形回帰オブジェクトの最適パラメータ値の検索が開始されます。ParamSearchCV では、クロスオーバーチェック (CV) を使用した指定されたパラメータ値の完全検索またはランダム検索が実行されます [1]
参照
[1] SAP アルゴリズム hana_ml.algorithms.pal パッケージ: ParamSearchCV
123456789101112131415161718from hana_ml.algorithms.pal.model_selection import ParamSearchCV
hgbr=HybridGradientBoostingRegressor(n_estimators=50, subsample = 0.8, col_subsample_tree=0.7)
ps_hgr3=ParamSearchCV(estimator=hgbr, search_strategy='grid',
param_grid={ 'learning_rate': [0.05, 0.1, 0.025, 0.04, 0.01],
'max_depth': [4, 5, 6, 7, 8, 10],
'split_threshold': [0.1, 0.4, 0.7, 1],
'min_samples_leaf': [2,3,4,5,6],
'col_subsample_split': [0.2,0.4,0.6, 0.8] },
train_control={"fold_num": 10, "evaluation_metric": 'rmse'},
scoring='mae'
)
ps_hgr3.set_scoring_metric('mae')
ps_hgr3.set_resampling_method('cv')
ps_hgr3.fit(data=train_hdf, features=['MedInc', 'HouseAge', 'AveRooms', 'AveBedrms', 'Population', 'AveOccup', 'Latitude', 'Longitude'],
label='Target', key='ID')最適化されたパラメータの検査
最適化されたパラメータ名 (左側に表示) と HybridGradientBoostingRegressor パラメータ名 (右側に表示) 間のマッピングを以下に示します。
- MAX_DEPTH = max_depth
- ETA = learning_rate
- COL_SAMPLE_RATE_BYSPLIT = col_subsample_split
- NODE_SIZE = min_samples_leaf
- GAMMA = split_threshold
1ps_hgr3.estimator.selected_param_.collect()| PARAM_NAME | INT_VALUE | DOUBLE_VALUE | STRING_VALUE | |
|---|---|---|---|---|
| 0 | MAX_DEPTH | 10.0 | NaN | なし |
| 1 | ETA | NaN | 0.1 | なし |
| 2 | COL_SAMPLE_RATE_BYSPLIT | NaN | 0.6 | なし |
| 3 | NODE_SIZE | 6.0 | NaN | なし |
| 4 | ガンマ | NaN | 0.1 | なし |
12# Optimal parameter values selected
hgbt_params = dict(n_estimators = 50, subsample = 0.8, col_subsample_tree=0.7, split_method = 'exact', fold_num=10, resampling_method = 'cv', evaluation_metric = 'rmse', ref_metric=['mae'], max_depth=10, learning_rate=0.1, col_subsample_split=0.6, min_samples_leaf=6, split_threshold=0.1)