# Saving Decisiontree model using JLD and Load issue.

**URL:** https://discourse.julialang.org/t/saving-decisiontree-model-using-jld-and-load-issue/22840
**Category:** General Usage
**Created:** [April 6, 2019, 1:53pm UTC](https://discourse.julialang.org/t/saving-decisiontree-model-using-jld-and-load-issue/22840 "2019-04-06T13:53:51Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![NaaG\_Balakrish](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/naag_balakrish/32/7832_2.png) [@NaaG\_Balakrish](https://discourse.julialang.org/u/NaaG_Balakrish)
#### Post date: [April 6, 2019, 1:53pm UTC](https://discourse.julialang.org/t/saving-decisiontree-model-using-jld-and-load-issue/22840/1 "2019-04-06T13:53:51Z")

</div>

Hi All,

Good day. I built a DecisionTree model using Iris dataset. Below is the model output.

> DecisionTreeClassifier  
> max\_depth: -1  
> min\_samples\_leaf: 1  
> min\_samples\_split: 2  
> min\_purity\_increase: 0.0  
> pruning\_purity\_threshold: 0.9  
> n\_subfeatures: 0  
> classes: root:  
> [“Iris-setosa”, “Iris-versicolor”, “Iris-virginica”]  
> Decision Tree  
> Leaves: 8  
> Depth: 5

When i try to do a `save("mdl.jld","model",model)` its saving without any issues.

But when i try to load it using `load("mdl.jld","model")` I am getting the below error.

> ┌ Warning: type Random.MersenneTwister not present in workspace; reconstructing └ @ JLD /mnt/juliabox/.julia/packages/JLD/1BoSz/src/jld\_types.jl:703 ┌ Warning: type Random.DSFMT.DSFMT\_state not present in workspace; reconstructing └ @ JLD /mnt/juliabox/.julia/packages/JLD/1BoSz/src/jld\_types.jl:703 MethodError: Cannot ` convert` an object of type getfield(JLD, Symbol(“##random.MersenneTwister#379”)) to an object of type Random.AbstractRNG  
> Closest candidates are:  
> convert(::Type{S}, !Matched::T\<:(Union{CategoricalString{R}, CategoricalValue{T,R} where T} where R)) where {S, T\<:(Union{CategoricalString{R}, CategoricalValue{T,R} where T} where R)} at /home/jrun/.julia/packages/CategoricalArrays/ucKV2/src/value.jl:91  
> convert(::Type{T}, !Matched::T) where T at essentials.jl:154
> 
> Stacktrace:  
> [1] macro expansion at /mnt/juliabox/.julia/packages/JLD/1BoSz/src/jld\_types.jl:387 [inlined]  
> [2] jlconvert(::Type{DecisionTreeClassifier}, ::JLD.JldFile, ::Ptr{UInt8}) at /mnt/juliabox/.julia/packages/JLD/1BoSz/src/jld\_types.jl:560  
> [3] read\_scalar(::JLD.JldDataset, ::HDF5.HDF5Datatype, ::Type) at /mnt/juliabox/.julia/packages/JLD/1BoSz/src/JLD.jl:398  
> [4] read(::JLD.JldDataset) at /mnt/juliabox/.julia/packages/JLD/1BoSz/src/JLD.jl:370  
> [5] read(::JLD.JldFile, ::String) at /mnt/juliabox/.julia/packages/JLD/1BoSz/src/JLD.jl:346  
> [6] [#42](https://github.com/JuliaLang/julia/issues/42) at /mnt/juliabox/.julia/packages/JLD/1BoSz/src/JLD.jl:1240 [inlined]  
> [7] #jldopen#14(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::getfield(JLD, Symbol(“#[#42](https://github.com/JuliaLang/julia/issues/42)#43”)){String}, ::String, ::Vararg{String,N} where N) at /mnt/juliabox/.julia/packages/JLD/1BoSz/src/JLD.jl:246  
> [8] jldopen at /mnt/juliabox/.julia/packages/JLD/1BoSz/src/JLD.jl:244 [inlined]  
> [9] load at /mnt/juliabox/.julia/packages/JLD/1BoSz/src/JLD.jl:1239 [inlined]  
> [10] #load#13(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::String, ::String) at /home/jrun/.julia/packages/FileIO/YJO7Z/src/loadsave.jl:118  
> [11] load(::String, ::String) at /home/jrun/.julia/packages/FileIO/YJO7Z/src/loadsave.jl:118  
> [12] top-level scope at In[24]:1

Can someone help me with this ??? I tried saving a simple variable and an array using JLD and i was able to retrieve the results. In this case i am unable to .

Thanks for your help !!!

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [April 6, 2019, 3:17pm UTC](https://discourse.julialang.org/t/saving-decisiontree-model-using-jld-and-load-issue/22840/2 "2019-04-06T15:17:04Z")

</div>

You need to have the types available. Eg here, `using Random`.

Also, please [quote your code](https://discourse.julialang.org/t/psa-how-to-quote-code-with-backticks/7530). And you may also want to consider JLD2, it is somewhat better maintained (but has the same constraint about types).

---

<div class="post-metadata">

### Author: ![NaaG\_Balakrish](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/naag_balakrish/32/7832_2.png) [@NaaG\_Balakrish](https://discourse.julialang.org/u/NaaG_Balakrish)
#### Post date: [April 7, 2019, 6:43am UTC](https://discourse.julialang.org/t/saving-decisiontree-model-using-jld-and-load-issue/22840/3 "2019-04-07T06:43:54Z")

</div>

It worked after using Random,BSON, and FLUX. Thank you. 🙂
