# MLJ unpack example from MLJ getting started not working

**URL:** <https://discourse.julialang.org/t/mlj-unpack-example-from-mlj-getting-started-not-working/100641>\
**Category:** New to Julia\
**Tags:** mlj\
**Created:** [June 21, 2023, 7:46am UTC](https://discourse.julialang.org/t/mlj-unpack-example-from-mlj-getting-started-not-working/100641 "2023-06-21T07:46:19Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![roeya](https://avatars.discourse-cdn.com/v4/letter/r/ecb155/32.png) [@roeya](https://discourse.julialang.org/u/roeya)\
**Post date:** [June 21, 2023, 7:46am UTC](https://discourse.julialang.org/t/mlj-unpack-example-from-mlj-getting-started-not-working/100641/1 "2023-06-21T07:46:20Z")

</div>

I am trying to run the most basic example from MLJ getting started tutorial and I am getting an error when trying to unpack the iris dataset

```julia
y,x = unpack(iris, ==(:target); rng=123)

```

I get

```julia
ERROR: BoundsError: attempt to access Tuple{CategoricalArrays.CategoricalVector{String, UInt32, String, CategoricalArrays.CategoricalValue{String, UInt32}, Union{}}} at index 

```

The error somehow relates to that there are two return values, if I leave only one (x = unpack…) it works

What’s going on ? I have just copied code from a tutorial how come it is failing to run ?  
What am I meesing ?

I am using Julia 1.9.1 On windows 10, Here is the complete program:

```julia
import Random.seed!
using CSV, DataFrames, MLJ

iris = load_iris()

iris = DataFrame(iris)
describe(iris)

y,x = unpack(iris, ==(:target); rng=123)

```

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [June 21, 2023, 7:59am UTC](https://discourse.julialang.org/t/mlj-unpack-example-from-mlj-getting-started-not-working/100641/2 "2023-06-21T07:59:52Z")

</div>

Works fine for me:

```julia
julia> using MLJ, DataFrames

julia> iris = DataFrame(load_iris());

julia> y, x = unpack(iris, ==(:target));

julia> typeof(x)
DataFrame

julia> typeof(y)
CategoricalVector{String, UInt32, String, CategoricalValue{String, UInt32}, Union{}}

```

(I’m not showing the actual values of `x` and `y` here as they are large but they are as expected.

With these kinds of questions (“why is this code I copied not working as expected”) I recommend two things:

- Actually link to where you found the code; and
- Tell people the versions of all of the packages you are using (i.e. the output of `]st` in the REPL) - 9 times out of 10 you are just using an outdated version of a package (or reading outdated docs while using a newer version of the package)

---

<div class="post-metadata">

**Author:** ![roeya](https://avatars.discourse-cdn.com/v4/letter/r/ecb155/32.png) [@roeya](https://discourse.julialang.org/u/roeya)\
**Post date:** [June 21, 2023, 8:27am UTC](https://discourse.julialang.org/t/mlj-unpack-example-from-mlj-getting-started-not-working/100641/3 "2023-06-21T08:27:17Z")

</div>

> [@nilshg](#):
>
> With these kinds of questions (“why is this code I copied not working as expected”) I recommend two things:

[Getting Started · MLJ (alan-turing-institute.github.io)](https://alan-turing-institute.github.io/MLJ.jl/dev/getting_started/#Getting-Started)

---

<div class="post-metadata">

**Author:** ![roeya](https://avatars.discourse-cdn.com/v4/letter/r/ecb155/32.png) [@roeya](https://discourse.julialang.org/u/roeya)\
**Post date:** [June 21, 2023, 8:27am UTC](https://discourse.julialang.org/t/mlj-unpack-example-from-mlj-getting-started-not-working/100641/4 "2023-06-21T08:27:52Z")

</div>

What version of MLJ & Julia you use ?

---

<div class="post-metadata">

**Author:** ![roeya](https://avatars.discourse-cdn.com/v4/letter/r/ecb155/32.png) [@roeya](https://discourse.julialang.org/u/roeya)\
**Post date:** [June 21, 2023, 8:28am UTC](https://discourse.julialang.org/t/mlj-unpack-example-from-mlj-getting-started-not-working/100641/5 "2023-06-21T08:28:58Z")

</div>

The only way the code works for me is like this:

```julia
y,x = unpack(iris, ==(:target), !=(:traget); rng=123)

```

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [June 21, 2023, 8:53am UTC](https://discourse.julialang.org/t/mlj-unpack-example-from-mlj-getting-started-not-working/100641/6 "2023-06-21T08:53:56Z")

</div>

The Julia version should not matter (only to the extent that it restricts package versions), but I’m on 1.9.1.

```julia
(jl_adrQDT) pkg> st
Status `...\Temp\jl_adrQDT\Project.toml`
 [add582a8] MLJ v0.19.2
```

---

<div class="post-metadata">

**Author:** ![roeya](https://avatars.discourse-cdn.com/v4/letter/r/ecb155/32.png) [@roeya](https://discourse.julialang.org/u/roeya)\
**Post date:** [June 21, 2023, 12:02pm UTC](https://discourse.julialang.org/t/mlj-unpack-example-from-mlj-getting-started-not-working/100641/7 "2023-06-21T12:02:29Z")

</div>

After looking at the Pkg status for some reason the version of MLJ was very very old

So I removed all Julia completely. and reinstalled

I have created a new project add MLJ and now every thing works fine

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [June 21, 2023, 12:06pm UTC](https://discourse.julialang.org/t/mlj-unpack-example-from-mlj-getting-started-not-working/100641/8 "2023-06-21T12:06:21Z")

</div>

In general I would recommend working in project environments - the problem you encountered most often stems from a crowded default environment, which can be easily avoided.
