π©π» μ»΄ν¨ν° ꡬ쑰/etc
λμ€μ μ°Έκ³ ν μ½λ μμ€
μ§μ§μνμΉ΄
2022. 9. 14. 10:55
728x90
λ°μν
π£ μκ³μ΄ λ°μ΄ν° λΉμ·ν νμΌμ κ·Έλν λΆν¬λ‘ λνλ΄κΈ°
## plot feature data distribution
fig, ax = plt.subplots(2, train.shape[1]//2+1, figsize=(20, 6))
for idx, feature in enumerate(train.columns):
data = train[feature]
if idx<train.shape[1]//2 + 1:
ax[0,idx].hist(train.iloc[:,idx], bins=10, alpha=0.5)
ax[0,idx].set_title(train.columns[idx])
else:
ax[1,idx-train.shape[1]//2-1].hist(train.iloc[:,idx], bins=10, alpha=0.5)
ax[1,idx-train.shape[1]//2-1].set_title(train.columns[idx])
plt.show()
ex) νμκ΄ λ°μ λ μμΈ‘
π£ Optuna λ‘ νμ΄νΌ νλΌλ―Έν° νλ
μΆμ²: https://sswwd.tistory.com/34?category=1194933 [민곡μ§λ₯:ν°μ€ν 리]
pip install optuna
def objective(trial):
from sklearn.svm import SVC
params = {
'C': trial.suggest_loguniform('C', 0.01, 0.1),
'gamma': trial.suggest_categorical('gamma', ["auto"]),
'kernel': trial.suggest_categorical("kernel", ["rbf"])
}
svc = SVC(**params, verbose=True)
svc.fit(X_train, y_train)
return svc.score(X_test, y_test)
study = optuna.create_study(sampler=optuna.samplers.TPESampler(seed=123),
direction="maximize",
pruner=optuna.pruners.MedianPruner())
study.optimize(objective, n_trials=5, show_progress_bar=True)
print(f"Best Value from optune: {study.best_trial.value}")
print(f"Best Params from optune: {study.best_params}")
728x90
λ°μν