Predict using 2 models?

Hi,
(Sorry if there’s an obvious response, I’m completely new to R.)

I’m using the zip file submission approach and it says to NOT modify the Predict.r script.

Let’s say I have two trained models, a glm and a random forest.
Can I modify the code to something like:

claims = predict_expected_claim(trained_model_glm, trained_model_rf, Xraw) ?
(in order to pass two trained models?)

Hi @michael_bordeleau and welcome to the challenge :partying_face:

You cannot alter the predict files that way as when we call it we don’t pass two models.

However, you can train two models in your fit_model function and return a vector (or list) with the models.

Then that vector gets saved and loaded and you will then have to write the logic within your predict_expected_claim and predict_premium functions to expand the vector and make the predictions accordingly.

Hi @alfarzan
Why cannot we alter the prediction file codes?
Are we also not allowed to modify the number of arguments we can pass to any other function (in model file)?

It is more a curiosity if those are kind of restrictions we have.

Hi @pejo92

The only functions you are allowed to change in terms of number of arguments given are:

  1. Any preprocessing functions you write
  2. The save_model and load_model

The reason you cannot alter the prediction files is because our servers call on those functions directly to generate predictions by feeding them 2 arguments (your model and the data). Hence if you alter the number of required arguments your code will not be able to run.

A note on the remaining code files if you are using R and want to use something other than an .RData file to save your models:

  1. predict.R. You will have to alter the load_model accordingly.
  2. train.R. Similarly you will have to alter the save_model accordingly.

We are going to push an update that fixes the R issue soon! :rocket:

Thank you so much for you answer, precise as always.

But are you sure it doesn’t work? I did a submission with more than one model modifying both the function in model file and the call in predict and it went good.
Did i do something “illegal”?

I can give you the number of submission if you need.

That’s why we’re here :slight_smile:

It might work, but there would be no guarantee that it will continue to do so if we change some minor details in the backend. That’s why it’s safer not to.

And yes, that would be helpful, what is the submission number?

Aah okay, so in case I want to use them in the future it would be more safe to not modify but to use a list or a vector.

Here it is the submission that worked with more than one model:

Submission #112243

Ah I see. Thanks for bringing this to our attention.

Yes please refrain from doing it this way because the moment we change something in the backend this might not run properly.

But the solution should be easy enough as a list correct? Or do you think that raises other issues that we should account for?

Ok thank you, I will try to use a list then.
I will let you know if some new problems come out.