mardi 6 juillet 2021

How to create random float number (between a range) for param_grid

I want to create float numbers between (0.2, 0.3) inside param_grid. I have the code

    test_size = (0.2, 0.3)
    param_iters = 2
    param_grid = {
        "test_size": uniform(test_size[0], test_size[1]),
    }
    sampler = list(ParameterSampler(param_grid, n_iter=param_iters))
    args = [Namespace(**{**args, **dict(params=params)}) for params in sampler]

But I have found that the train_size are 0.3897422919229748 and 0.4852142919229748. That means I am getting over the range (0.2, 0.3)

I also tried to use the below code

    param_grid = {
        "test_size": round(random.uniform(test_size[0], test_size[1]), 2),
    }

But getting an error at the next line

Parameter value is not iterable or distribution (key='test_size', value=0.24)

How can I limit the train_size in between (0.2, 0.3) inside param_grid?




Aucun commentaire:

Enregistrer un commentaire