Python によるモデル検証
Kasey Jones
Data Scientist
パラメータとは:
パラメータはモデルをフィットして生成される:
from sklearn.linear_model import LinearRegression
lr = LinearRegression()
lr.fit(X, y)
print(lr.coef_, lr.intercept_)
[[0.798, 0.452]] [1.786]
モデルをフィットする前はパラメータは存在しない:
lr = LinearRegression()
print(lr.coef_, lr.intercept_)
AttributeError: 'LinearRegression' object has no attribute 'coef_'
ハイパーパラメータ:
| ハイパーパラメータ | 説明 | 取りうる値(既定) |
|---|---|---|
| n_estimators | 森の決定木の本数 | 2以上(10) |
| max_depth | 決定木の最大深さ | 2以上(None) |
| max_features | 分割時に考慮する特徴量数 | ドキュメント参照 |
| min_samples_split | 分割に必要な最小サンプル数 | 2以上(2) |
ハイパーパラメータの調整:
depth = [4, 6, 8, 10, 12] samples = [2, 4, 6, 8] features = [2, 4, 6, 8, 10]# Specify hyperparameters rfc = RandomForestRegressor( n_estimators=100, max_depth=depth[0], min_samples_split=samples[3], max_features=features[1])rfr.get_params()
{'bootstrap': True,
'criterion': 'mse'
...
}
rfr.get_params()
{'bootstrap': True,
'criterion': 'mse',
'max_depth': 4,
'max_features': 4,
'max_leaf_nodes': None,
'min_impurity_decrease': 0.0,
'min_impurity_split': None,
'min_samples_leaf': 1,
'min_samples_split': 8,
...
}
Python によるモデル検証