假設我有一個 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,
我的問題是 - 畢竟有什么辦法讓它作業嗎?
uj5u.com熱心網友回復:
該問題與從 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
此外,要制作矢量,您無需指定“矢量”。我建議你看看我的 Julia 教程或我的 Julia科學編程和機器學習課程(我在幾天前完成了它,我仍然需要在宣布它之前“清理”它)
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/450258.html
