gpt4 book ai didi

scikit-learn - 在 Julia 中定义冲突模块

转载 作者:行者123 更新时间:2023-12-02 00:50:16 24 4
gpt4 key购买 nike

我是 Julia 的新手(使用 MATLAB)。我正在获取一些数据集,对其进行清理并使用 ScikitLearn 中可用的工具对分类变量进行编码,然后运行清理数据的 XGBoost。

但是,我无法使用经过训练的 XGBoost 模型进行预测,因为 ScitkitLearn 和 XGBoost 都有一个名为 predict 的函数。请引用以下错误消息:

WARNING: both ScikitLearn and XGBoost export "predict"; uses of it in module Main must be qualified ERROR: LoadError: UndefVarError: predict not defined

问题是我无法将 XGBoost 的 predict 函数定义为 XGBoost.predict 因为这不起作用而且它似乎是我知道的唯一解决方案的。

此外,我无法找到或理解如何在不加载预测函数的情况下仅从 ScikitLearn 加载特定模块。例如,格式 import MLDataUtils.splitobs 适用于大多数包,但 ScikitLearn.preprocessing 无效。

最佳答案

这是您问题的 MWE(两个模块 export 同名):

module A
export f
f() = println("f from A")
end
module B
export f
f() = println("f from B")
end

现在,考虑您使用 AB 并尝试调用 f 的情况:

julia> using .A, .B

julia> f()
WARNING: both B and A export "f"; uses of it in module Main must be qualified
ERROR: UndefVarError: f not defined

失败的原因是 Julia 不知道你用 f 是什么意思;是 A.f 还是 B.f?您可以通过显式消除对 f 的 any 调用的歧义来解决此问题:

julia> using .A, .B

julia> A.f()
f from A

julia> B.f()
f from B

如果您希望能够仅通过名称 (f) 调用其中一个函数,那么您(用户)必须选择 f 应该指向什么。您可以通过将其显式定义为导入语句的一部分来执行此操作:

julia> using .A, .B

julia> using .B: f # explicitly choosing f to be B.f

julia> f() # no error
f from B

julia> A.f()
f from A

julia> B.f()
f from B

另一种选择是在您的命名空间中显式定义您自己的名称 f:

julia> using .A, .B

julia> const f = B.f # defining a new name in this namespace pointing to B.f
f (generic function with 1 method)

julia> f() # no error
f from B

julia> A.f()
f from A

julia> B.f()
f from B

关于scikit-learn - 在 Julia 中定义冲突模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58159369/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com