来自 pycall 的 Julia 多线程
假设我有一个 jupyter 笔记本:
%%julia
using Pkg
Pkg.add("DecisionTree")
using DecisionTree
X = Vector([1.1,2.2,3.3])
Y = Vector([1.1,2.2,3.3])
X = reshape(X, size(X))
X = Float32.(X)
Y = Float32.(Y)
print(typeof(X))
print(typeof(Y))
model = DecisionTree.build_forest(Y, X')
据我所知 DecisionTree.jl 使用多线程,而 pycall 不支持多线程,这会导致错误:
RuntimeError: <PyCall.jlwrap (in a Julia function called from Python)
JULIA: TaskFailedException
Stacktrace:
[1] wait
@ .\task.jl:334 [inlined]
[2] threading_run(func::Function)
@ Base.Threads .\threadingconstructs.jl:38
[3] macro expansion
@ .\threadingconstructs.jl:97 [inlined]
[4] build_forest(labels::Vector{Float32}, features::LinearAlgebra.Adjoint{Float32, Vector{Float32}}, n_subfeatures::Int64, n_trees::Int64, partial_sampling::Float64, max_depth::Int64,
我的问题是 - 有什么办法让它工作吗?
Say I have a jupyter notebook:
%%julia
using Pkg
Pkg.add("DecisionTree")
using DecisionTree
X = Vector([1.1,2.2,3.3])
Y = Vector([1.1,2.2,3.3])
X = reshape(X, size(X))
X = Float32.(X)
Y = Float32.(Y)
print(typeof(X))
print(typeof(Y))
model = DecisionTree.build_forest(Y, X')
From what I know DecisionTree.jl uses multithreading, which pycall does not support, which results in the error:
RuntimeError: <PyCall.jlwrap (in a Julia function called from Python)
JULIA: TaskFailedException
Stacktrace:
[1] wait
@ .\task.jl:334 [inlined]
[2] threading_run(func::Function)
@ Base.Threads .\threadingconstructs.jl:38
[3] macro expansion
@ .\threadingconstructs.jl:97 [inlined]
[4] build_forest(labels::Vector{Float32}, features::LinearAlgebra.Adjoint{Float32, Vector{Float32}}, n_subfeatures::Int64, n_trees::Int64, partial_sampling::Float64, max_depth::Int64,
My question is - is there any way to make it work after all?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个问题与从 Python 调用它无关,而是因为您正在尝试创建一个模型,其中特征是具有 3 维的单个记录,标签是 3(记录)向量。
DecisionTrees 确实期望输入是标签维度为 nRecords 的列向量,以及特征的 nRecods × nDimensions 矩阵。
例如:
此外,要创建矢量,您不需要指定“Vector”。
我建议你看看我的 Julia 教程 或在我的用 Julia 进行科学编程和机器学习课程中(我只用了几天就完成了)之前我还需要“清理”一下才公布)
The problem has nothing to do with calling it from Python, but from the fact that you are trying to make a model where the features is a single record with 3 dimensions and the label is a 3 (records) vector.
DecisionTrees expects indeed the input to be a column vector of dimension nRecords for the label and a nRecods by nDimensions matrix for the features.
For example:
Also, to make a vector you don't need to specify "Vector".
I suggest you to have a look on my tutorial on Julia or on my course on Scientific Programming and Machine Learning with Julia (I completed it just a couple of days ago, I still need to "clean" it before announcing it)