OutlierDetectionJL / OutlierDetectionNetworks.jl

Neural-Network Outlier Detection Algorithms for Julia
MIT License
7 stars 2 forks source link

Problem with MLJ interface for ESADDetector ? #5

Closed ablaom closed 2 years ago

ablaom commented 2 years ago

Not able to train a ESADDetector model and struggling to understand the message. It sounds like the core model wants a matrix with observations as columns, which is fine, but then are we remembering to take the adjoint of the table passed by MLJ user, which has observations as rows? Or is this something else? Or maybe I'm doing something stupid...

I am expecting the same problem with DSADDetector but have not explicitly checked.

Input:

using MLJ
model = (@load ESADDetector)()

X, y0 = make_moons();
y = coerce(y0, OrderedFactor);
@show size(MLJ.matrix(X))
@show size(y)
@show levels(y)

mach = machine(model, X, y) |> fit!

Output:

size(MLJ.matrix(X)) = (150, 2)
size(y) = (150,)
levels(y) = [0, 1]

[ Info: Training Machine{ESADDetector,…}.
┌ Error: Problem fitting the machine Machine{ESADDetector,…}. 
└ @ MLJBase ~/.julia/packages/MLJBase/hHa7b/src/machines.jl:594
[ Info: Running type checks... 
[ Info: Type checks okay. 
ERROR: DomainError with Supervised detectors can only be fitted with array
inputs with one observation per last dimension, found X=SubArray{Float64, 2, Matrix{Float64}, Tuple{Base.Slice{Base.OneTo{Int64}}, Base.Slice{Base.OneTo{Int64}}}, true}, y=SubArray{CategoricalArrays.CategoricalValue{Int64, UInt32}, 1, CategoricalArrays.CategoricalVector{Int64, UInt32, Int64, CategoricalArrays.CategoricalValue{Int64, UInt32}, Union{}}, Tuple{Base.Slice{Base.OneTo{Int64}}}, true}:

Stacktrace:
 [1] fit(::OutlierDetectionNetworks.ESADDetector, X::SubArray{Float64, 2, Matrix{Float64}, Tuple{Base.Slice{Base.OneTo{Int64}}, Base.Slice{Base.OneTo{Int64}}}, true}, y::SubArray{CategoricalArrays.CategoricalValue{Int64, UInt32}, 1, CategoricalArrays.CategoricalVector{Int64, UInt32, Int64, CategoricalArrays.CategoricalValue{Int64, UInt32}, Union{}}, Tuple{Base.Slice{Base.OneTo{Int64}}}, true}; verbosity::Int64)
   @ OutlierDetectionInterface ~/.julia/packages/OutlierDetectionInterface/1QuAr/src/base.jl:137                                                                                 
 [2] fit(detector::OutlierDetectionNetworks.ESADDetector, verbosity::Int64, X::SubArray{Float64, 2, Matrix{Float64}, Tuple{Base.Slice{Base.OneTo{Int64}}, Base.Slice{Base.OneTo{Int64}}}, true}, y::SubArray{CategoricalArrays.CategoricalValue{Int64, UInt32}, 1, CategoricalArrays.CategoricalVector{Int64, UInt32, Int64, CategoricalArrays.CategoricalValue{Int64, UInt32}, Union{}}, Tuple{Base.Slice{Base.OneTo{Int64}}}, true})                 
   @ OutlierDetectionInterface ~/.julia/packages/OutlierDetectionInterface/1QuAr/src/interface.jl:14                                                                             
 [3] fit_only!(mach::Machine{OutlierDetectionNetworks.ESADDetector, true}; rows::Nothing, verbosity::Int64, force::Bool)                                                              
   @ MLJBase ~/.julia/packages/MLJBase/hHa7b/src/machines.jl:592
 [4] fit_only!
   @ ~/.julia/packages/MLJBase/hHa7b/src/machines.jl:545 [inlined]
 [5] #fit!#56
   @ ~/.julia/packages/MLJBase/hHa7b/src/machines.jl:659 [inlined]
 [6] fit!
   @ ~/.julia/packages/MLJBase/hHa7b/src/machines.jl:657 [inlined]
 [7] |>(x::Machine{OutlierDetectionNetworks.ESADDetector, true}, f::typeof(fit!))
   @ Base ./operators.jl:858
 [8] top-level scope
   @ REPL[59]:1
 [9] top-level scope
   @ ~/.julia/packages/CUDA/KnJGx/src/initialization.jl:52
davnn commented 2 years ago

Thanks for reporting this! The problem was that there was an assumption baked in that the levels of the labels are String, which is not necessary and will be removed with the following patch.

davnn commented 2 years ago

Should be fixed with https://github.com/JuliaRegistries/General/pull/55794