Saving Decisiontree model using JLD and Load issue.

#1

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 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#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 !!!

0 Likes

#2

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

Also, please quote your code. And you may also want to consider JLD2, it is somewhat better maintained (but has the same constraint about types).

0 Likes

#3

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

0 Likes