πŸ‘©‍πŸ’» 컴퓨터 ꡬ쑰/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
λ°˜μ‘ν˜•