Home > database >  Julia "MethodError: no method matching build_tree"
Julia "MethodError: no method matching build_tree"

Time:03-25

I have a very simple sample script:

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"])

Which returns an error:

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\**\.julia\packages\DecisionTree\iWCbW\src\classification\main.jl:74
  build_tree(::AbstractVector{T}, ::AbstractMatrix{S}, ::Any) where {S, T} at C:\Users\**\.julia\packages\DecisionTree\iWCbW\src\classification\main.jl:74
  build_tree(::AbstractVector{T}, ::AbstractMatrix{S}, ::Any, ::Any) where {S, T} at C:\Users\**\.julia\packages\DecisionTree\iWCbW\src\classification\main.jl:74

What is going on? How do I deal with that?

CodePudding user response:

Your data types do not match. Try this:

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