朱莉娅·"MethodError: no method matching build_tree"



我有一个非常简单的示例脚本:

using Pkg
Pkg.add("DecisionTree")
Pkg.add("DataFrames")
using DataFrames
using DecisionTree
dat = DataFrame(A=[1, 2, 3, 4, 5], B=[2, 5, 1, 2, 6])
model = build_tree(dat[!, "A"], dat[!, "B"])

返回错误:

ERROR: LoadError: MethodError: no method matching build_tree(::Vector{Int64}, ::Vector{Int64})
Closest candidates are:
build_tree(::AbstractVector{T}, ::AbstractMatrix{S}) where {S, T} at C:Users**.juliapackagesDecisionTreeiWCbWsrcclassificationmain.jl:74
build_tree(::AbstractVector{T}, ::AbstractMatrix{S}, ::Any) where {S, T} at C:Users**.juliapackagesDecisionTreeiWCbWsrcclassificationmain.jl:74
build_tree(::AbstractVector{T}, ::AbstractMatrix{S}, ::Any, ::Any) where {S, T} at C:Users**.juliapackagesDecisionTreeiWCbWsrcclassificationmain.jl:74

发生了什么事?我该如何处理?

您的数据类型不匹配。试试这个:

C = reshape(dat[!, "B"], (1, 5))
model = DecisionTree.build_tree(dat[!, "A"], C')

最新更新