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

[MLJ interface] NeuralNetworkClassifier falsely claims to support Count target #75

Closed
ablaom opened this issue Dec 20, 2024 · 2 comments

Comments

@ablaom
Copy link

ablaom commented Dec 20, 2024

using BetaML
using MLJBase

X = (x1 = rand(5), x2 = rand(5))
y = [1, 2, 3, 2, 1]

scitype(y)
# AbstractVector{Count}

M = BetaML.Bmlj.NeuralNetworkClassifier

@assert scitype(y) <: target_scitype(M)

verbosity = 0
MLJBase.fit(M(), verbosity, X, y)
# ERROR: MethodError: Cannot `convert` an object of type
#   Nothing to an object of type
#   Vector
# The function `convert` exists, but no method is defined for this combination of argument types.

# Closest candidates are:
#   convert(::Type{Vector}, ::StatsBase.UnitWeights{T}) where T
#    @ StatsBase ~/.julia/packages/StatsBase/xgoZ5/src/weights.jl:317
#   convert(::Type{Vector}, ::StatsBase.AbstractWeights)
#    @ StatsBase ~/.julia/packages/StatsBase/xgoZ5/src/weights.jl:35
#   convert(::Type{T}, ::T) where T
#    @ Base Base.jl:126
#   ...

# Stacktrace:
#  [1] setproperty!(x::BetaML.Utils.OneHotEncoder_lp, f::Symbol, v::Nothing)
#    @ Base ./Base.jl:52
#  [2] BetaML.Utils.OneHotEncoder(; kwargs::@Kwargs{…})
#    @ BetaML.Utils ~/.julia/packages/BetaML/NDCDt/src/Utils/Processing.jl:219
#  [3] fit(m::BetaML.Bmlj.NeuralNetworkClassifier, verbosity::Int64, X::@NamedTuple{…}, y::Vector{…})
#    @ BetaML.Bmlj ~/.julia/packages/BetaML/NDCDt/src/Bmlj/Nn_mlj.jl:342
#  [4] top-level scope
#    @ REPL[40]:1
# Some type information was truncated. Use `show(err)` to see complete types.
Status `/private/var/folders/4n/gvbmlhdc8xj973001s6vdyw00000gq/T/jl_smBPYW/Project.toml`
  [024491cd] BetaML v0.12.1
  [a7f614a8] MLJBase v1.7.0
julia> versioninfo()
Julia Version 1.11.1
Commit 8f5b7ca12ad (2024-10-16 10:53 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: macOS (x86_64-apple-darwin22.4.0)
  CPU: 12 × Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, skylake)
Threads: 12 default, 0 interactive, 6 GC (on 12 virtual cores)
Environment:
  JULIA_LTS_PATH = /Applications/Julia-1.10.app/Contents/Resources/julia/bin/julia
  JULIA_PATH = /Applications/Julia-1.11.app/Contents/Resources/julia/bin/julia
  JULIA_EGLOT_PATH = /Applications/Julia-1.7.app/Contents/Resources/julia/bin/julia
  JULIA_NUM_THREADS = 12
  JULIA_NIGHTLY_PATH = /Applications/Julia-1.11.app/Contents/Resources/julia/bin/julia
@sylvaticus
Copy link
Owner

sylvaticus commented Jan 5, 2025

Sorry for the late reply... Christmas (and a strike of flu) in the middle...
I had a look... I can easily fix it to work on integer vectors, but the classifier internally works on one-hot encoding version of the data, so it doesn't exploit any information from the ordered nature of the data.

What would you suggest? That I fix the MLJ interface to get the classifier working with integer data or that I remove MMI.Count from target_scitype = AbstractVector{<: Union{MMI.Multiclass,MMI.Finite,MMI.Count}} ?

@ablaom
Copy link
Author

ablaom commented Jan 8, 2025

I suggest you restrict the target scitype as suggested, thanks.

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