fit_model function

Fit a model using the chosen backend.