If you provide a random seed to a CV splitter in a multicore grid search, are the splits guaranteed to be the same across cores?

Viewed 363

If I run a grid search across multiple cores, and the CV splitter object provided to GridSearchCV has shuffle=True and the random_state argument set to some integer, is it guaranteed that the cross-validation splits used by the grid search on each of the separate cores will be the same?

Here's an example:

from sklearn.datasets import load_iris
from sklearn.svm import SVC
from sklearn.model_selection import GridSearchCV, KFold

iris = load_iris()

param_grid = {
    'kernel': ['linear', 'polynomial', 'rbf'],
    'C': np.logspace(-4, 5, 10)
}

cv = KFold(n_splits=5, shuffle=True, random_state=42)

clf = GridSearchCV(SVC(), param_grid=param_grid, cv=cv, n_jobs=10)

clf.fit(iris.data, iris.target)

So, in this case I'm distributing the grid search across 10 cores. I want to be certain that each model in the parameter grid is evaluated using exactly the same cross-validation split. Is this guaranteed to be the case when distributing the grid search job across multiple cores?

0 Answers
Related