# Can I fit a model with the parameters found with RandomizedSearchCV?

I want to ask you a question. Suppose I use the following RandomizedSearchCV to find the model's best hyperparams:

classification = RandomizedSearchCV(XGBClassifier(n_jobs=-1, random_state=42), {
'max_depth': [1,2,3,4,5,6,7,8,9,10],
'learning_rate': [.001, .005, .01, .05, .1, .2, .3],
'n_estimators': [300, 500, 1000, 1500],
'min_child_weight': [1,2,3,4,5,6,7,8,9,10],
'subsample': [.4, .5, .6, .7, .8, .9, 1],
'colsample_bytree': [.4, .5, .6, .7, .75, .77, .79 ,.8, .85],
'gamma': [0.0, 0.1, 0.2, 0.3, 0.4, 0.5],
'reg_lambda':[0, 0.5, 1, 1.5, 2, 3, 4.5]
}, cv=5, return_train_score=False, scoring='roc_auc', n_iter=5)

classification.fit(X,y)


Then I print the best parameters using .best_params_

Later can I train a separate model using those parameters like this:

model = XGBClassifier(n_jobs=-1, n_estimators=500, max_depth=2, subsample=0.8, gamma=0, colsample_bytree=0.5, learning_rate=0.2,
reg_lambda=4.5, min_child_weight=2 ,random_state=42)
model.fit(X,y)


I have used X and y (the training set) to train both the RandomizedSearchCV and the model, in order not to repeat every time the params' search.

Is this correct?

the model with parameters best_params_ is stored in best_estimator_ as long as you set refit=True when instantiating RandomizedSearchCV.