# How do I can I selectively inspect and use learned parameters in an MLJ pipeline?

**URL:** https://discourse.julialang.org/t/how-do-i-can-i-selectively-inspect-and-use-learned-parameters-in-an-mlj-pipeline/83097
**Category:** Machine Learning
**Tags:** mlj, pipelines
**Created:** [June 20, 2022, 10:50pm UTC](https://discourse.julialang.org/t/how-do-i-can-i-selectively-inspect-and-use-learned-parameters-in-an-mlj-pipeline/83097 "2022-06-20T22:50:16Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![ablaom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ablaom/32/4889_2.png) [@ablaom](https://discourse.julialang.org/u/ablaom)
#### Post date: [June 20, 2022, 10:50pm UTC](https://discourse.julialang.org/t/how-do-i-can-i-selectively-inspect-and-use-learned-parameters-in-an-mlj-pipeline/83097/1 "2022-06-20T22:50:16Z")

</div>

From a question on slack:

If I have a pipeline like this `@pipeline ContinuousEncoder(drop_last=true) Standardizer()` can I specify to `inverse_transform` the standadizer part so that I won’t have to break up the pipeline?

---

<div class="post-metadata">

### Author: ![ablaom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ablaom/32/4889_2.png) [@ablaom](https://discourse.julialang.org/u/ablaom)
#### Post date: [June 20, 2022, 10:57pm UTC](https://discourse.julialang.org/t/how-do-i-can-i-selectively-inspect-and-use-learned-parameters-in-an-mlj-pipeline/83097/2 "2022-06-20T22:57:25Z")

</div>

First, a note that `@pipeline` is now deprecated in favour of macro-free pipeline creation. See [these docs](https://alan-turing-institute.github.io/MLJ.jl/dev/linear_pipelines/#Linear-Pipelines). That said, I think the following example works for the old synax as well.

```julia
using MLJ

X = (
    x1 = [2.3, 4.5, 5.6],
    x2 = coerce(["a", "b", "a"], Multiclass),
);

pipe = ContinuousEncoder() |> Standardizer()
mach = machine(pipe, X) |> fit!
julia> Xout = transform(mach, X);
(x1 = [-1.0910894511799618, 0.21821789023599267, 0.8728715609439697],
 x2__a = [0.5773502691896257, -1.1547005383792512, 0.5773502691896257],
 x2__b = [-0.5773502691896256, 1.1547005383792515, -0.5773502691896256],)

# learned parameters of pipeline:
theta = fitted_params(mach);
julia> keys(theta)
(:standardizer, :continuous_encoder, :machines, :fitted_params_given_machine)

# to just *inspect* the learned standardization parameters:
julia> theta.standardizer
Dict{Symbol, Tuple{Float64, Float64}} with 3 entries:
  :x2__a => (0.666667, 0.57735)
  :x2__b => (0.333333, 0.57735)
  :x1 => (4.13333, 1.68028)

# to `inverse_transform` some data using those learned parameters:
sub_machines = theta.machines
standardizer_machine = sub_machines[2]
julia> inverse_transform(standardizer_machine, Xout)
(x1 = [2.3, 4.5, 5.6],
 x2__a = [1.0, 0.0, 1.0],
 x2__b = [0.0, 1.0, 0.0],)

```
