假设我有一个笔记本:
%%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, 我的问题是-有什么办法让它起作用吗?
发布于 2022-03-27 13:43:24
这个问题与从Python调用它无关,而是因为您试图建立一个模型,其中的特性是一个带有3维的单一记录,标签是一个3(记录)向量。实际上,DecisionTrees期望输入是标签的维度nRecords的列向量,特征的nRecods by nDimensions矩阵。
例如:
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此外,要生成一个向量,您不需要指定“向量”。我建议你看看我的朱莉娅教程或者我在朱莉娅的科学编程与机器学习上的课程(就在几天前,我还需要“清理”它,然后才宣布)。
https://stackoverflow.com/questions/71632579
复制相似问题