【问题标题】:Saving a decision tree model for later application in Julia保存决策树模型以供以后在 Julia 中应用
【发布时间】:2016-10-13 06:32:48
【问题描述】:

我使用 DecisionTree 模块在 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

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

【问题讨论】:

    标签: export julia decision-tree


    【解决方案1】:

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

    【讨论】:

    • 谢谢,这很好用。然后,当我将保存的 .jld 文件导入新会话时,我必须首先使用 DecisionTree 键入,以便会话可以理解正在导入的数据的结构,但在这样做并使用 JLD 之后它工作得很好。
    猜你喜欢
    • 2014-11-26
    • 2016-11-15
    • 2023-03-12
    • 1970-01-01
    • 2019-06-24
    • 1970-01-01
    • 1970-01-01
    • 2013-12-17
    • 1970-01-01
    相关资源
    最近更新 更多