Using the python API from the documentation of xgboost I am creating the train data by: dtrain = xgb.DMatrix(file_path) Here file_path is of libsvm format txt file. As I am doing pairwise ranking I am also inputting the length of the groups in the dtrain data that we just inputed: dtrain.set_group(group_len_file) and now I am training the model: param = {'bst:max_depth':2, 'bst:eta':1, 'silent':1, 'objective':'rankairwise' } param['nthread'] = 4 param['eval_metric'] = 'ndcg' bst = xgb.train(param,dtrain,10) Now I want to use gridsearch. So my question is how to use gridsearch from sklearn when I am inputing DMatrix? Gennerally: from sklearn.grid_search import GridSearchCV param_test1 = { 'max_depth':list(range(3,10,2)), 'min_child_weiht':list(range(1,6,2)) } gsearch = GridSearchCV(estimator=XGBClassifier(objective='rankairwise'), param_grid = param_test1) but gsearch doesnt have train. It only have fit which takes X and y as inputs and not DMatrix. Is there a way to do it? And if not I can transform the DMatrix to be of format from Dmatrix => X, y but I can't find in documentation how to input set_group in that case? Any idea on it? Continue reading...