Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

파이썬 하는 파이리

Random Search_ 본문

프로그래밍/머신러닝, 딥러닝

Random Search_

gunnwu 2023. 5. 29. 23:11

데이터 준비는 모두 끝났다는 가정하에. ML정리본에는 GridSearch만 있음. 실무에서 Random search를 많이 쓴다고 하니 정리.

# Random Search

model_rf = RandomForestClassifier(max_depth=5, random_state=1)

# 파라미터 지정
param = {
    'n_estimators': sp_randint(10, 1000),
    'max_depth': [None] + list(sp_randint(1, 100).rvs(99)),
    'max_features': sp_randint(1, 50),
    'min_samples_split': sp_randint(2, 20),
    'min_samples_leaf': sp_randint(1, 20),
    'bootstrap': [True, False],
    'criterion': ['gini', 'entropy']
}

# 모델 선언
n_iter_search = 20
model = RandomizedSearchCV(
    model_rf, param_distributions=param, n_iter=n_iter_search, cv=5)

# 학습하기
model.fit(s_x_train, s_y_train)

# 최적 파라미터, 정확도
print("Best parameters: ", model.best_params_)
print("Accuracy score: ", model.best_score_)

'프로그래밍 > 머신러닝, 딥러닝' 카테고리의 다른 글

Auto ML  (0) 2023.05.29
ML정리본  (0) 2023.05.29
CNN  (0) 2023.04.15
Comments