'How to make sure in a parameter grid search, every sample must have a fix value
I have a parameter grid and I draw some samples from it.
from sklearn.model_selection import ParameterGrid, ParameterSampler
import numpy as np
grid = {'a': np.linspace(1, 10, 10),
'b': np.linspace(1, 5, 5),
'c': ['str1', 'str2'],
'd': ['model1', 'model2']
}
n_combinations = ParameterGrid(grid).__len__()
# 50 % of possible combinations
samples = ParameterSampler(grid, random_state=1,
n_iter=int(0.5*n_combinations))
I want to make sure that for any combination of 'a', 'b' and 'c' should have 'd' ='model1' and the same values 'a', 'b' and 'c' with 'd' = 'model2'.
For instance, for a=1, b=2, c='str2'
The combinations should be:
{'a': 1, 'b':2, c:'str2', d='model1'} # and
{'a': 1, 'b':2, c:'str2', d='model2'}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
