2

After training an ML model using https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.Lasso.html#sklearn.linear_model.Lasso, when I print out the coefficients, I can see that some of them give 0.00000000e+00 while others are -0.00000000e+00.

Is there a reason for this difference? At the end of the day, I am assuming they are both coefficient=0. (?)

programmer12
  • 111
  • 9

1 Answers1

3

Linear regression models can compute negative coefficients and -0 is the result of rounding originally negative numbers. A comparison like -0 == 0 will yield True and they behave the same for most operations. However, in operations where the sign is important it will make a difference. Thus, it would account as information loss to drop the - sign.

For more information on -0 and its behavior in Python, I refer to the answer(s) of this question.

afsharov
  • 4,774
  • 2
  • 10
  • 27
  • 1
    @programmer12 and [IEE 754](https://en.wikipedia.org/wiki/IEEE_754) allows for this [signed zero](https://en.wikipedia.org/wiki/Signed_zero) representation. – rickhg12hs Jul 08 '20 at 18:54