Skip to content

OneClassSVM cannot be converted to probabilistic outlier classificator #1188

@IJ1TI

Description

@IJ1TI

Describe the bug
Probably Mismatch in internal functions - expected different implementation of scale_minmax

[ Info: Training machine(ProbabilisticUnsupervisedCompositeDetector(normalize = scale_minmax, …), …).
[ Info: Training machine(OneClassSVM(kernel = Polynomial, …), …).
┌ Error: Failed to apply the operation #19.
│ Incoming data:
│ arg of #19 scitype
│ -------------------------------------------
│ Node @959 → OneClassSVM(…) AbstractVector{Continuous}

│ Learning network sources:
│ source scitype
│ -------------------------------------------
│ Source @500 Table{AbstractVector{Continuous}}
└ @ MLJBase ~/.julia/packages/MLJBase/GY2fM/src/composition/learning_networks/nodes.jl:164
┌ Error: Problem fitting the machine machine(ProbabilisticUnsupervisedCompositeDetector(normalize = scale_minmax, …), …).
└ @ MLJBase ~/.julia/packages/MLJBase/GY2fM/src/machines.jl:695
[ Info: Running type checks...
[ Info: Type checks okay.
ERROR: MethodError: no method matching scale_minmax(::Vector{Float64})
The function scale_minmax exists, but no method is defined for this combination of argument types.

Closest candidates are:
scale_minmax(::Tuple{AbstractVector{<:Real}, AbstractVector{<:Real}})
@ OutlierDetection ~/.julia/packages/OutlierDetection/bjM0k/src/normalization.jl:24

Stacktrace:
[1] (::OutlierDetection.var"#19#22"{OutlierDetection.ProbabilisticUnsupervisedCompositeDetector{…}})(n::Vector{Float64})
@ OutlierDetection ~/.julia/packages/OutlierDetection/bjM0k/src/mlj_wrappers.jl:153
[2] _apply(::Tuple{Node{Nothing, OutlierDetection.var"#19#22"{…}}}; kwargs::@kwargs{rows::Colon})
@ MLJBase ~/.julia/packages/MLJBase/GY2fM/src/composition/learning_networks/nodes.jl:153
[3] _apply
@ ~/.julia/packages/MLJBase/GY2fM/src/composition/learning_networks/nodes.jl:146 [inlined]
[4] Node
@ ~/.julia/packages/MLJBase/GY2fM/src/composition/learning_networks/nodes.jl:143 [inlined]
[5] #77
@ ~/.julia/packages/MLJBase/GY2fM/src/composition/learning_networks/nodes.jl:150 [inlined]
[6] map(f::MLJBase.var"#77#78"{@kwargs{rows::Colon}, Tuple{}}, t::Tuple{Node{Nothing, OutlierDetection.var"#19#22"{…}}})
@ Base ./tuple.jl:355
[7] _apply(::Tuple{Node{Nothing, typeof(combine_mean)}}; kwargs::@kwargs{rows::Colon})
@ MLJBase ~/.julia/packages/MLJBase/GY2fM/src/composition/learning_networks/nodes.jl:149
[8] _apply
@ ~/.julia/packages/MLJBase/GY2fM/src/composition/learning_networks/nodes.jl:146 [inlined]
[9] Node
@ ~/.julia/packages/MLJBase/GY2fM/src/composition/learning_networks/nodes.jl:143 [inlined]
[10] #77
@ ~/.julia/packages/MLJBase/GY2fM/src/composition/learning_networks/nodes.jl:150 [inlined]
[11] map(f::MLJBase.var"#77#78"{@kwargs{rows::Colon}, Tuple{}}, t::Tuple{Node{Nothing, typeof(combine_mean)}})
@ Base ./tuple.jl:355
[12] _apply(::Tuple{Node{Nothing, typeof(first)}}; kwargs::@kwargs{rows::Colon})
@ MLJBase ~/.julia/packages/MLJBase/GY2fM/src/composition/learning_networks/nodes.jl:149
[13] _apply
@ ~/.julia/packages/MLJBase/GY2fM/src/composition/learning_networks/nodes.jl:146 [inlined]
[14] Node
@ ~/.julia/packages/MLJBase/GY2fM/src/composition/learning_networks/nodes.jl:143 [inlined]
[15] call_and_copy
@ ~/.julia/packages/MLJBase/GY2fM/src/composition/learning_networks/signatures.jl:81 [inlined]
[16] _broadcast_getindex_evalf
@ ./broadcast.jl:678 [inlined]
[17] _broadcast_getindex
@ ./broadcast.jl:651 [inlined]
[18] #17
@ ./broadcast.jl:1102 [inlined]
[19] ntuple
@ ./ntuple.jl:48 [inlined]
[20] copy
@ ./broadcast.jl:1102 [inlined]
[21] materialize
@ ./broadcast.jl:872 [inlined]
[22] call_and_copy
@ ~/.julia/packages/MLJBase/GY2fM/src/composition/learning_networks/signatures.jl:85 [inlined]
[23] report_supplement
@ ~/.julia/packages/MLJBase/GY2fM/src/composition/learning_networks/signatures.jl:293 [inlined]
[24] report(signature::MLJBase.Signature{@NamedTuple{…}}; supplement::Bool)
@ MLJBase ~/.julia/packages/MLJBase/GY2fM/src/composition/learning_networks/signatures.jl:328
[25] report(signature::MLJBase.Signature{@NamedTuple{predict::Node{…}, transform::Node{…}, report::@NamedTuple{…}}})
@ MLJBase ~/.julia/packages/MLJBase/GY2fM/src/composition/learning_networks/signatures.jl:326
[26] fit(composite::OutlierDetection.ProbabilisticUnsupervisedCompositeDetector{…}, verbosity::Int64, data::Tables.MatrixTable{…})
@ MLJBase ~/.julia/packages/MLJBase/GY2fM/src/composition/models/network_composite.jl:33
[27] fit_only!(mach::Machine{…}; rows::Nothing, verbosity::Int64, force::Bool, composite::Nothing)
@ MLJBase ~/.julia/packages/MLJBase/GY2fM/src/machines.jl:693
[28] fit_only!
@ ~/.julia/packages/MLJBase/GY2fM/src/machines.jl:617 [inlined]
[29] #fit!#66
@ ~/.julia/packages/MLJBase/GY2fM/src/machines.jl:790 [inlined]
[30] fit!
@ ~/.julia/packages/MLJBase/GY2fM/src/machines.jl:787 [inlined]
[31] |>(x::Machine{…}, f::typeof(fit!))
@ Base ./operators.jl:926
[32] top-level scope
@ ~/DevOps/learning_ML/tests/test.jl:23
Some type information was truncated. Use show(err) to see complete types.

To Reproduce
Run the exmaple from documentation or source below

https://juliaai.github.io/MLJ.jl/dev/models/OneClassSVM_LIBSVM/#Outlier-classification-using-a-probability-threshold:

using MLJ
import LIBSVM
import StableRNGs.StableRNG

OneClassSVM = @load OneClassSVM pkg = LIBSVM           ## model type
model = OneClassSVM(kernel=LIBSVM.Kernel.Polynomial) ## instance

rng = StableRNG(123)
Xmatrix = randn(rng, 5, 3)
Xmatrix[1, 1] = 100.0 # outlier 
X = MLJ.table(Xmatrix)

mach = machine(model, X) |> fit!
report(mach).scores

using OutlierDetection
pmodel = ProbabilisticDetector(model) # throws error! 
pmach = machine(pmodel, X) |> fit!

dmodel = BinaryThresholdPredictor(pmodel, threshold=0.9)
dmach = machine(dmodel, X) |> fit!

Versions
Status ~/DevOps/learning_ML/Project.toml
[a93c6f00] DataFrames v1.8.1
[b4f34e82] Distances v0.10.12
[b1bec4e5] LIBSVM v0.8.1
[add582a8] MLJ v0.22.0
[61c7150f] MLJLIBSVMInterface v0.2.2
[6ee0df7b] MLJLinearModels v0.10.1
[1b6a4a23] MLJMultivariateStatsInterface v0.5.4
[5ae90465] MLJScikitLearnInterface v0.7.0
[262411bb] OutlierDetection v0.4.2
[91a5bcdd] Plots v1.41.3
[54e16d92] PrettyPrinting v0.4.2
[ce6b1742] RDatasets v0.8.0
[860ef19b] StableRNGs v1.0.4
[2913bbd2] StatsBase v0.34.9

Julia Version 1.11.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions