# How to approach this piece of code?

**URL:** <https://discourse.julialang.org/t/how-to-approach-this-piece-of-code/77598>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [March 8, 2022, 4:53pm UTC](https://discourse.julialang.org/t/how-to-approach-this-piece-of-code/77598 "2022-03-08T16:53:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dharik\_Arsath](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dharik_arsath/32/27461_2.png) [@Dharik\_Arsath](https://discourse.julialang.org/u/Dharik_Arsath)\
**Post date:** [March 8, 2022, 4:53pm UTC](https://discourse.julialang.org/t/how-to-approach-this-piece-of-code/77598/1 "2022-03-08T16:53:09Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [March 8, 2022, 5:09pm UTC](https://discourse.julialang.org/t/how-to-approach-this-piece-of-code/77598/2 "2022-03-08T17:09:19Z")

</div>

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

> **[GitHub - JuliaML/TableTransforms.jl: Transforms and pipelines with tabular...](https://github.com/JuliaML/TableTransforms.jl)**
>
> Transforms and pipelines with tabular data in Julia - GitHub - JuliaML/TableTransforms.jl: Transforms and pipelines with tabular data in Julia

You are after the ZScore transform.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [March 8, 2022, 6:03pm UTC](https://discourse.julialang.org/t/how-to-approach-this-piece-of-code/77598/3 "2022-03-08T18:03:43Z")

</div>

> [@Dharik\_Arsath](#):
>
> Since python is object oriented it is easier to create object which holds all these data.

This is not OOP, it’s just a [composite data structure](https://en.wikipedia.org/wiki/Record_(computer_science)). 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.

---

<div class="post-metadata">

**Author:** ![josuagrw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/josuagrw/32/1015_2.png) [@josuagrw](https://discourse.julialang.org/u/josuagrw)\
**Post date:** [March 8, 2022, 9:00pm UTC](https://discourse.julialang.org/t/how-to-approach-this-piece-of-code/77598/4 "2022-03-08T21:00:02Z")

</div>

> [@Dharik\_Arsath](#):
>
> ```julia
> function standard_scalar!(X, scaled_out)
> 
> ```

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