Created
September 9, 2017 05:20
-
-
Save supachaic/9ac8f70c6af9eef6120c3eced2880654 to your computer and use it in GitHub Desktop.
RandomSearch with XGBClassifier
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scipy.stats as st | |
from sklearn.model_selection import RandomizedSearchCV | |
from xgboost import XGBClassifier | |
# Preconfigure estimator and parameters | |
estimator = XGBClassifier(nthreads=-1) | |
params = { | |
"n_estimators": st.randint(3, 40), | |
"max_depth": st.randint(3, 40), | |
"learning_rate": st.uniform(0.05, 0.4), | |
"colsample_bytree": st.beta(10, 1), | |
"subsample": st.beta(10, 1), | |
"gamma": st.uniform(0, 10), | |
'objective': ['binary:logistic'], | |
'scale_pos_weight': st.randint(0, 2), | |
"min_child_weight": st.expon(0, 50), | |
} | |
# Random Search Training with 5 folds Cross Validation | |
clf = RandomizedSearchCV(estimator, params, cv=5, | |
n_jobs=1, n_iter=100) | |
clf.fit(X_train, y_train) | |
best_params = clf.best_params_ | |
best_score = clf.best_score_ | |
# Predict label from Test data | |
y_pred = clf.predict(X_test) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment