Is there easy way to grid search without cross validation in python?

后端 未结 4 1253
梦如初夏
梦如初夏 2020-12-13 14:06

There is absolutely helpful class GridSearchCV in scikit-learn to do grid search and cross validation, but I don\'t want to do cross validataion. I want to do grid search wi

4条回答
  •  青春惊慌失措
    2020-12-13 14:43

    Although the question has been solved years ago, I just found a more natural way if you insist on using GridSearchCV() instead of other means (ParameterGrid(), etc.):

    1. Create a sklearn.model_selection.PredefinedSplit(). It takes a parameter called test_fold, which is a list and has the same size as your input data. In the list, you set all samples belonging to training set as -1 and others as 0.
    2. Create a GridSearchCV object with cv="the created PredefinedSplit object".

    Then, GridSearchCV will generate only 1 train-validation split, which is defined in test_fold.

提交回复
热议问题