来自 pycall 的 Julia 多线程
Julia multithreading from pycall
假设我有一个 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,
我的问题是 - 到底有没有办法让它发挥作用?
问题与从 Python 调用它无关,而是因为您正在尝试制作一个模型,其中特征是具有 3 个维度的单个记录并且标签是 3 (记录)向量。
DecisionTrees 确实期望输入是标签的维度 nRecords 的列向量和特征的 nDimensions 矩阵的 nRecods。
例如:
julia> X = [1.1,2.2,3.3]
3-element Vector{Float64}:
1.1
2.2
3.3
julia> Y = [1.1,2.2,3.3]
3-element Vector{Float64}:
1.1
2.2
3.3
julia> X = reshape(X,3,1) # reshape to a single column **matrix**
3×1 Matrix{Float64}:
1.1
2.2
3.3
julia> model = DecisionTree.build_forest(Y, X)
Ensemble of Decision Trees
Trees: 10
Avg Leaves: 1.0
Avg Depth: 0.0
此外,要制作矢量,您无需指定“矢量”。
我建议你看看我的tutorial on Julia or on my course on Scientific Programming and Machine Learning with 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,
我的问题是 - 到底有没有办法让它发挥作用?
问题与从 Python 调用它无关,而是因为您正在尝试制作一个模型,其中特征是具有 3 个维度的单个记录并且标签是 3 (记录)向量。 DecisionTrees 确实期望输入是标签的维度 nRecords 的列向量和特征的 nDimensions 矩阵的 nRecods。
例如:
julia> X = [1.1,2.2,3.3]
3-element Vector{Float64}:
1.1
2.2
3.3
julia> Y = [1.1,2.2,3.3]
3-element Vector{Float64}:
1.1
2.2
3.3
julia> X = reshape(X,3,1) # reshape to a single column **matrix**
3×1 Matrix{Float64}:
1.1
2.2
3.3
julia> model = DecisionTree.build_forest(Y, X)
Ensemble of Decision Trees
Trees: 10
Avg Leaves: 1.0
Avg Depth: 0.0
此外,要制作矢量,您无需指定“矢量”。 我建议你看看我的tutorial on Julia or on my course on Scientific Programming and Machine Learning with Julia(我前几天刚完成,我还需要“清理”它才能发布)