Skip to content

PMStandardScaler fails when scale = 0 #124

Closed

Description

@AtharvaKhare

A relevant example:

x := PMMatrix rows: #(#(1 0) #(1 0) #(1 1) #(1 1)).
scaler := PMStandardizationScaler new.
scaler fit: x.
scaler scale. "0"
scaler transform: x. "ZeroDivideError"

Possible fix: add a "handleZeroScale" method which changes scale to 1 when it is 0.
Question: Can this be method be added in PMDataTransformer? If we add more scalers in future, all would need this message.

Activity

  1. SergeStinckwich commented on May 27, 2019

    @SergeStinckwich
    Member

    Why we should modify the scale to 1 when this is 0 ? 😄

  2. SergeStinckwich commented on May 27, 2019

    @SergeStinckwich
    Member
  3. AtharvaKhare commented on May 27, 2019

    @AtharvaKhare
    Author

    We are doing (element - mean) / scale. When scale=0, we can't divide by zero. Since all elements are same, the element-mean will be 0 as it should be. So any number in the denominator will be fine. 1 specifically because any number divided by it is itself, but again, any number should be ok.

    sklearn is also setting scale to 1.

  4. SergeStinckwich commented on May 28, 2019

    @SergeStinckwich
    Member
  5. added this to the 1.0 milestone on May 29, 2019
  6. SergeStinckwich commented on May 29, 2019

    @SergeStinckwich
    Member

    Can you propose a fix, should be easy ?

  7. AtharvaKhare commented on May 29, 2019

    @AtharvaKhare
    Author

    One of the fix is to modify this method:

    PMStandardizationScaler >> scale [
    ^ self variance sqrt
    ]

    To calculate sqrt for every element, compare to 0, and return sqrt or 1.

    Other way is to add a handleZeros method, but I do not think we should go there unless we add more types of scaling.

    Do you want me to create PR using first suggested fix?

  8. SergeStinckwich commented on May 29, 2019

    @SergeStinckwich
    Member

    Maybe later will have multiple type of scalin, but at the moment, we have only one.
    So keep it simple and use first method. Maybe add a test when scale is 0 that it returns 1.

  9. changed the title [-]PMStandardScaler fails when scale = 0[/-] [+]``PMStandardScaler`` fails when scale = 0[/+] on Aug 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions