尝试使用流式标准缩放。

huangapple go评论50阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年4月17日 03:06:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/76029839.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定