保存决策树模型以供以后在 Julia 中应用



我使用决策树模块在Julia中训练了一个修剪后的决策树模型。我现在想保存此模型以供以后在其他数据集上使用。

我尝试使用writetable()将模型转换为数据数组以进行导出,并且尝试使用writedlm()导出,但这些都不起作用。当我查看模型的类型时,我发现它是DecisionTree.Node类型。我不知道如何使用它,也无法让它导出/保存。

In:DataFrame(PrunedModel)
Out:LoadError: MethodError: `convert` has no method matching convert(::Type{DataFrames.DataFrame}, ::DecisionTree.Node)
This may have arisen from a call to the constructor DataFrames.DataFrame(...),
since type constructors fall back to convert methods.
Closest candidates are:
  call{T}(::Type{T}, ::Any)
  convert(::Type{DataFrames.DataFrame}, !Matched::Array{T,2})
  convert(::Type{DataFrames.DataFrame}, !Matched::Dict{K,V})
  ...
while loading In[22], in expression starting on line 1 
 in call at essentials.jl:56
In:typeof(PrunedModel)
Out:DecisionTree.Node

有什么想法可以保存此模型以供以后使用吗?

如果我正确理解这是一个 Julia 对象,您应该尝试使用 JLD.jl 包将对象保存到磁盘并将其加载回,保留类型信息。

最新更新