Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The MLJ example in README does not work #30

Closed
liuyxpp opened this issue Feb 29, 2024 · 3 comments
Closed

The MLJ example in README does not work #30

liuyxpp opened this issue Feb 29, 2024 · 3 comments

Comments

@liuyxpp
Copy link

liuyxpp commented Feb 29, 2024

Julia version:

Julia Version 1.10.1
Commit 7790d6f0641 (2024-02-13 20:41 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 128 × Intel(R) Xeon(R) Platinum 8362 CPU @ 2.80GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, icelake-server)
Threads: 1 default, 0 interactive, 1 GC (on 128 virtual cores)
Environment:
  JULIA_EDITOR = code
  JULIA_PKG_SERVER = https://mirrors.tuna.tsinghua.edu.cn/julia
  JULIA_PKG_USE_CLI_GIT = true

CatBoost version: v0.3.3
MLJBase version: v1.1.1

The following line errored:

julia> mach = machine(model, train_data, train_labels)
ERROR: MethodError: no method matching machine(::PythonCall.Py, ::DataFrame, ::Vector{Float64})

Closest candidates are:
  machine(::Type{<:Model}, ::Any...; kwargs...)
   @ MLJBase ~/.julia/packages/MLJBase/mIaqI/src/machines.jl:336
  machine(::Static, ::Any...; cache, kwargs...)
   @ MLJBase ~/.julia/packages/MLJBase/mIaqI/src/machines.jl:340
  machine(::Union{Symbol, Model}, ::Any, ::Any...; scitype_check_level, kwargs...)
   @ MLJBase ~/.julia/packages/MLJBase/mIaqI/src/machines.jl:364
  ...

Stacktrace:
 [1] top-level scope
   @ REPL[7]:1

Do I have to install any other packages?

@tylerjthomas9
Copy link
Collaborator

I forgot to update the readme example when I split up the MLJ interface into its own module. Here is the working version of this example. I will update the readme. Thank you for bringing this to my attention. Let me know if this does not work for you.

module Regression

using CatBoost.MLJCatBoostInterface
using DataFrames
using MLJBase
using PythonCall

# 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

@liuyxpp
Copy link
Author

liuyxpp commented Feb 29, 2024

Great! It now works like a charm. Thank you!

@tylerjthomas9
Copy link
Collaborator

Closed with #31

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants