lightweight_mmm icon indicating copy to clipboard operation
lightweight_mmm copied to clipboard

Non zero mean scaling - Not working

Open msdhina opened this issue 2 years ago • 6 comments

I've used "lambda x: jnp.mean(x[x > 0])" in place of "jnp.mean"

media_scaler = preprocessing.CustomScaler(divide_operation=lambda x: jnp.mean(x[x > 0]))

It throws "NonConcreteBooleanIndexError: Array boolean indices must be concrete; got ShapedArray(bool[82])" error.

please help me out, how to do scaling only for non zero values in a column.

Also , how to change the axis (row/column) for scaling)?

msdhina avatar Jan 24 '23 08:01 msdhina

Thanks a lot for flagging this! I just wanted to share a link to our new "support" section in the readme to give you some more information on how we can and cannot support such issues at the moment.

For this particular issue, the documentation for the NonConcreteBooleanIndexError has some potential workarounds you could try!

michevan avatar Feb 08 '23 22:02 michevan

@msdhina This works for a single vector but wouldn't work if you pass multiple columns

slavakx avatar Feb 15 '23 15:02 slavakx

I tried the code below by referring to the documentation @michevan suggested.

def nonzero_mean(arr):
    return jnp.nanmean(jnp.where(arr != 0, arr, jnp.nan))

media_scaler = preprocessing.CustomScaler(divide_operation=nonzero_mean)

I first converted zero values to NaN by jnp.where() and calculated the mean excluding NaN values by jnp.nanmean()

I think this works but still need someone to verify since I'm not a good coder 😅

nseunghee97 avatar Feb 17 '23 09:02 nseunghee97

did anyone make it work?

mariaana-tyba avatar Mar 06 '23 06:03 mariaana-tyba

Did it worked? Im trying to fix this, do you have any alternative for zero data

mariaana-tyba avatar Mar 06 '23 06:03 mariaana-tyba

Did it worked? Im trying to fix this, do you have any alternative for zero data

I tried this solution and the scaling works but not the training, got a ValueError: Normal distribution got invalid loc parameter.

OrellanaJoel avatar Feb 14 '24 16:02 OrellanaJoel