Search code examples
pythonscikit-learnpycaret

Pycaret - whats is the parameter for custom grid of tune model


I was trying to set parameters for tune_model function's custom_grid

tune_model(model, n_iter=50, custom_grid={'learning_rate':0.5})

and it will give me this error

Parameter value is not iterable or distribution

I have to pass a list to learning rate, but I don't know why

tune_model(model, n_iter=50, custom_grid={'learning_rate':[0.5, 0.5]})

Can someone explain this to me? And what length should the list be? Should I make the list to [0.5, 0.5, 0.5, 0.5]

if I want to remain learning_rate = 0.5?


Solution

  • When you are tuning the model, your intention is to try different hyperparameters (more than 1). Hence they must be specified in a list. In this case, it will create 2 models - one with learning_rate = 0.5 and the second also with learning rate = 0.5. Finally, it will return the better of these models.

    tune_model(model, n_iter=50, custom_grid={'learning_rate':[0.5, 0.5]})
    

    Ideally, you want to define a grid that has different hyperparameters, e.g.

    tune_model(model, n_iter=50, custom_grid={'learning_rate':[0.1, 0.2, 0.3, 0.4, 0.5]})
    

    In this case, 5 (different) models will be created and the best one will be returned.