英文:
Trying to use Streaming Standard Scaling
问题
I am trying to use OnlineStats.jl to perform a streaming standard scaling, but this doesn't seem to be properly scaling values to their ZScore. Can you spot anything wrong with this math?
使用 OnlineStats.jl 进行流式标准化尝试,但似乎未正确将值缩放到它们的 Z 分数。您能发现这个数学公式有什么问题吗?
using OnlineStats
onlineStats = OnlineStats.Series(Mean(), Variance(), Extrema())
fit!(onlineStats, value)
(mean, variance, extrema) = OnlineStats.value(onlineStats)
stdDev = variance^0.5
normed = (value - mean) / stdDev
英文:
I am trying to use OnlineStats.jl to perform a streaming standard scaling, but this doesn't seem to be properly scaling values to their ZScore. Can you spot anything wrong with this math?
using OnlineStats
onlineStats = OnlineStats.Series(Mean(), Variance(), Extrema())
fit!(onlineStats, value)
(mean, variance, extrema) = OnlineStats.value(onlineStats)
stdDev = variance^0.5
normed = (value - mean) / stdDev
答案1
得分: 2
似乎运行得相当不错,在 Julia 1.8.5 和 OnlineStats v1.5.14 中:
julia> using OnlineStats
julia> stats = Series(Mean(), Variance(), Extrema());
julia> fit!(stats, -1);
julia> fit!(stats, 1);
julia> values(stats)
Series
├─ Mean: n=2 | value=0.0
├─ Variance: n=2 | value=2.0
└─ Extrema: n=2 | value=(min = -1.0, max = 1.0, nmin = 1, nmax = 1)
julia> (ol_mean, ol_var, (ol_min, ol_max, ol_mincnt, ol_maxcnt)) =
value(stats)
(0.0, 2.0, (min = -1.0, max = 1.0, nmin = 1, nmax = 1))
julia> ol_std = sqrt(ol_var)
1.4142135623730951
julia> zdata = ([-1,1] .- ol_mean)/ol_std
2-element Vector{Float64}:
-0.7071067811865475
0.7071067811865475
julia> mean(zdata)
0.0
julia> std(zdata)
0.9999999999999999
英文:
Seems to be working quite okay, on Julia 1.8.5, OnlineStats v1.5.14 :
julia> using OnlineStats
julia> stats = Series(Mean(), Variance(), Extrema());
julia> fit!(stats, -1);
julia> fit!(stats, 1);
julia> values(stats)
Series
├─ Mean: n=2 | value=0.0
├─ Variance: n=2 | value=2.0
└─ Extrema: n=2 | value=(min = -1.0, max = 1.0, nmin = 1, nmax = 1)
julia> (ol_mean, ol_var, (ol_min, ol_max, ol_mincnt, ol_maxcnt)) =
value(stats)
(0.0, 2.0, (min = -1.0, max = 1.0, nmin = 1, nmax = 1))
julia> ol_std = sqrt(ol_var)
1.4142135623730951
julia> zdata = ([-1,1] .- ol_mean)/ol_std
2-element Vector{Float64}:
-0.7071067811865475
0.7071067811865475
julia> mean(zdata)
0.0
julia> std(zdata)
0.9999999999999999
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论