How to Restrict the output(FloatList Prediction value) to be between 0 and 100

I am working on a simple Tabular data prediction model, which is predicting a single FloatList parameter, and the predictions can be negative or way higher than my max value, so I’m wondering if there is a way to restrict the output value to be within (0 to 100) range.

Please help

Hard to tell with your description. Do you have some example code of what you are doing? I believe fastai should support this as part of creating the learner.

It should definitely be possible though. You will want to look for something called y_range in the learner.

Hi, Here is where im defining my data:
data = (TabularList.from_df(df, path=path, cat_names=cat_names, cont_names=cont_names, procs=procs)
.split_by_rand_pct()
.label_from_df(cols=dep_var, label_cls=FloatList, log=True)
.databunch(bs = 500))

How bout applying sigmoid to the output followed multiplication with 100.0?

Sorry for a dumb question but, how can i do that?

Let’s assume predictions is your output tensor.
Then you can simply call:

predictions.sigmoid()

Which will give you values between zero and 1.
Now you can scale them up to your range my multiplying by 100
Keep in mind that high values (independet of the algebraic sign) will be approx zero after applying sigmoid!!!

1 Like