Validasi Model di Python
Kasey Jones
Data Scientist
Parameter adalah:
Parameter dibuat saat model di-fit:
from sklearn.linear_model import LinearRegression
lr = LinearRegression()
lr.fit(X, y)
print(lr.coef_, lr.intercept_)
[[0.798, 0.452]] [1.786]
Parameter belum ada sebelum model di-fit:
lr = LinearRegression()
print(lr.coef_, lr.intercept_)
AttributeError: 'LinearRegression' object has no attribute 'coef_'
Hyperparameter:
| Hyperparameter | Deskripsi | Nilai yang Mungkin (default) |
|---|---|---|
| n_estimators | Jumlah pohon keputusan dalam hutan | 2+ (10) |
| max_depth | Kedalaman maksimum pohon keputusan | 2+ (None) |
| max_features | Jumlah fitur yang dipertimbangkan saat split | Lihat dokumentasi |
| min_samples_split | Minimum sampel yang dibutuhkan untuk melakukan split | 2+ (2) |
Hyperparameter tuning:
depth = [4, 6, 8, 10, 12] samples = [2, 4, 6, 8] features = [2, 4, 6, 8, 10]# Tentukan hyperparameter 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,
...
}
Validasi Model di Python