How to approach this piece of code?

I am trying to implement Standard Scalar, where I have to store my mean and standard deviation of training data and use that mean and std_dev in the test set.

function standard_scalar!(X, scaled_out)

mean = 1/length(X) * sum(X)

std_dev = standard_deviation(X)

for each in eachindex(X)
   scaled_out[each] = (X[each] - mean) / std_dev
end

end

Since python is object oriented it is easier to create object which holds all these data.

Question

How to implement Standard Scalar like functions in Julia? I can return mean and std_dev from training and pass that to function when computing in test_set but that might not look good I feel…

You don’t need to implement it yourself, we have a bunch of transforms with caches in

You are after the ZScore transform.

This is not OOP, it’s just a composite data structure. Virtually every programming language introduced in the last 50 years has had those.

In Julia, you’d most likely use a struct, or maybe just a tuple or named tuple.

5 Likes

Please note that by convention, the argument that is modified (in your case scaled_out) should come first in the method signature.

1 Like