JuliaAI / CatBoost.jl

Julia wrapper of the python library CatBoost for boosted decision trees
MIT License
11 stars 3 forks source link

MLJ Readme example fails on v0.3.4 #32

Closed ericphanson closed 4 months ago

ericphanson commented 4 months ago
julia> module Regression

       using CatBoost.MLJCatBoostInterface
       using DataFrames
       using MLJBase

       train_data = DataFrame([[1,4,30], [4,5,40], [5,6,50], [6,7,60]], :auto)
       eval_data = DataFrame([[2,1], [4,4], [6,50], [8,60]], :auto)
       train_labels = [10.0, 20.0, 30.0]

       # Initialize MLJ Machine
       model = CatBoostRegressor(iterations = 2, learning_rate = 1, depth = 2)
       mach = machine(model, train_data, train_labels)

       # Fit model
       MLJBase.fit!(mach)

       # Get predictions
       preds = predict(model, eval_data)

       end # module
WARNING: replacing module Regression.
[ Info: Training machine(CatBoostRegressor(iterations = 2, …), …).
ERROR: MethodError: no method matching predict(::CatBoost.MLJCatBoostInterface.CatBoostRegressor, ::DataFrames.DataFrame)

Closest candidates are:
  predict(::CatBoost.MLJCatBoostInterface.CatBoostRegressor, ::Any, ::Any)
   @ CatBoost ~/.julia/packages/CatBoost/TiqIz/src/mlj_catboostregressor.jl:90
  predict(::CatBoost.MLJCatBoostInterface.CatBoostClassifier, ::Any, ::Any)
   @ CatBoost ~/.julia/packages/CatBoost/TiqIz/src/mlj_catboostclassifier.jl:100
  predict(::MLJBase.Machine, ::Any)
   @ MLJBase ~/.julia/packages/MLJBase/mIaqI/src/operations.jl:130
  ...

Stacktrace:
 [1] top-level scope
   @ REPL[10]:19

(jl_VyECfX) pkg> st
Status `/private/var/folders/jb/plyyfc_d2bz195_0rc0n_zcw0000gp/T/jl_VyECfX/Project.toml`
  [e2e10f9a] CatBoost v0.3.4
  [a93c6f00] DataFrames v1.6.1
  [a7f614a8] MLJBase v1.1.1
  [6099a3de] PythonCall v0.9.15
ericphanson commented 4 months ago

works, ty!


julia> module Regression

       using CatBoost.MLJCatBoostInterface
       using DataFrames
       using MLJBase

       # Initialize data
       train_data = DataFrame([[1, 4, 30], [4, 5, 40], [5, 6, 50], [6, 7, 60]], :auto)
       train_labels = [10.0, 20.0, 30.0]
       eval_data = DataFrame([[2, 1], [4, 4], [6, 50], [8, 60]], :auto)

       # Initialize CatBoostClassifier
       model = CatBoostRegressor(; iterations=2, learning_rate=1.0, depth=2)
       mach = machine(model, train_data, train_labels)

       # Fit model
       MLJBase.fit!(mach)

       # Get predictions
       preds_class = MLJBase.predict(mach, eval_data)

       end # module
[ Info: Training machine(CatBoostRegressor(iterations = 2, …), …).
Main.Regression

julia> Regression.preds_class
2-element Vector{Float64}:
 15.625
 18.125