I\'d like to use scikit-learn\'s GridSearchCV to determine some hyper parameters for a random forest model. My data is time dependent and looks something like
i
There's standard sklearn
approach to that, using GroupShuffleSplit. From the docs:
Provides randomized train/test indices to split data according to a third-party provided group. This group information can be used to encode arbitrary domain specific stratifications of the samples as integers.
For instance the groups could be the year of collection of the samples and thus allow for cross-validation against time-based splits.
Very much convenient for your use case. Here how it looks like:
cv = GroupShuffleSplit().split(X, y, groups)
And passing that to GridSearchCV
like before:
GridSearchCV(estimator, param_grid, cv=cv, ...)