Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow transform to avoid Z-score transforming when sigma=0 #911

Closed
wants to merge 3 commits into from
Closed

allow transform to avoid Z-score transforming when sigma=0 #911

wants to merge 3 commits into from

Conversation

tylerjthomas9
Copy link

Ref: #910

Here is my attempt to prevent NaNs when transforming data with 0 variance.

Here is the result:

julia> X = ones(5,8)
5×8 Matrix{Float64}:
 1.0  1.0  1.0  1.0  1.0  1.0  1.0  1.0
 1.0  1.0  1.0  1.0  1.0  1.0  1.0  1.0
 1.0  1.0  1.0  1.0  1.0  1.0  1.0  1.0
 1.0  1.0  1.0  1.0  1.0  1.0  1.0  1.0
 1.0  1.0  1.0  1.0  1.0  1.0  1.0  1.0

julia> feature_transform = fit(ZScoreTransform, X, dims=1)
ZScoreTransform{Float64, Vector{Float64}}(8, 1, [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0], [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0])

julia> StatsBase.transform(feature_transform, X)
5×8 Matrix{Float64}:
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0

@andreasnoack
Copy link
Member

I don't like the discontinuity that this introduces. You'd end up with a huge difference between the transform of X and the smallest perturbation of `X.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants