I have a DataFrame like this:
import pandas as pd
pd.DataFrame({"x": [10, 15, 0, 5, 21, 2, 3, 99],
"y": [123, 321, 25, 85, 721, 1232, 32, 994],
"country": ["a", "a", "b", "a", "a", "b", "c", "c"],
"age_group": ["e", "r", "t", "t", "r", "r", "e", "t"]})
I would like to cross-validate a model, I want to not have the same groups in test and training. E.g. a fold were country "c" and "b" and age_group "e" are in the test would lead to the instance 0, 2 and the last three instances to be in the test set.
I can't find a library for this and I do not have an idea for a simple implementation. Is there something like sklearn.model_selection.GroupKFold for more than one group? Is there an easy way to solve this problem? (I do not want "leave one group out" since in reality, my two group columns have high cardinality.)