Skip to content

Uniform columns return a standard deviation of 1 in StandardScaler #4609

Closed

Description

@TroyHernandez

It should be 0.

StandardScaler().fit(np.zeros(10)).std_
1.0

Activity

  1. lesteve commented on Apr 17, 2015

    @lesteve
    Member

    StandardScaler.fit is using sklearn.preprocessing.data._mean_and_std, this docstring may be a hint to explain this behaviour.

  2. amueller commented on Apr 17, 2015

    @amueller
    Member

    Yeah, it is a bit awkward but setting it to 0 is also awkward. I am a bit conflicted about what would be best here.
    I think we should document this behavior in the std_ docstring. That might be best

  3. added
    Easy
    on Apr 17, 2015
  4. TroyHernandez commented on Apr 17, 2015

    @TroyHernandez
    Author

    0 is the correct answer, so I find it less awkward than 1. Returning 0, but handling it internally to avoid NaNs, and throwing a warning would be my preference. Adding functionality to optionally remove those columns would be even better.

  5. amueller commented on Apr 19, 2015

    @amueller
    Member

    what do you mean by "the correct answer"? This is not a function to compute the standard deviation, you can use np.std for that. This is the "internal handling" to get the desired scaling.

    I feel that the promise here is that

    scaler.transform(X) == (X - scaler.mean_) / scaler.std_ 

    and not that

    scaler.mean_ == np.mean(X, axis=0)
    scaler.std_ == np.std(X, axis=0)

    I don't see what the usefulness of the second contract would be.

    Optionally removing these columns would be a nice addition. PR welcome.

  6. TroyHernandez commented on Apr 20, 2015

    @TroyHernandez
    Author

    By correct I mean reporting the calculated standard deviation (in Latex, sorry)
    $$ \sqrt(\frac{1}{N} \sum_{i=1}{N} (x_i - \mu)^2) $$

    I'm new to sklearn. That PR may be a while.

  7. amueller commented on Apr 20, 2015

    @amueller
    Member

    well, I agree that if we name the attribute std that it is confusing. I think there is a PR that refactors it and renames it scaling.

  8. TomDLT commented on Jun 10, 2015

    @TomDLT
    Member

    I think there is a PR that refactors it and renames it scaling.

    yes, it is #3639

  9. amueller commented on Jun 10, 2015

    @amueller
    Member

    Fixed by #4796.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationEasy

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions