학습 목표
- RamdomSearchCV로 하이퍼파라메터 찾는 방법을 이해할 수 있다.
핵심 키워드
- RandomizedSearchCV
학습하기
학습 목표
- RamdomSearchCV로 하이퍼파라메터 찾는 방법을 이해할 수 있다.
핵심 키워드
- RandomizedSearchCV
학습하기
학습내용
from sklearn.model_selection import RandomizedSearchCV
max_depth = np.random.randint(2, 20, 10)
max_features = np.random.uniform(0.3, 1.0, 10)
param_distributions = {"max_depth": max_depth,
"max_features": max_features}
clf = RandomizedSearchCV(estimator,
param_distributions,
n_iter=100,
scoring="accuracy",
n_jobs=-1,
cv=5,
verbose=2
)
clf.fit(X_train, y_train)
clf.best_params
결과 :
clf.best_score_
결과 :
from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import RandomForestClassifier, GradientBoostingClassifier
estimators = [DecisionTreeClassifier(random_state=42),
RandomForestClassifier(random_state=42),
GradientBoostingClassifier(random_state=42)
]
estimators