JuliaML / LIBSVM.jl

LIBSVM bindings for Julia

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bug?

ablaom opened this issue · comments

It seems that the MLJ interface for this package has stopped working, without any change to the code: JuliaAI/MLJLIBSVMInterface.jl#18

The culprit appears to be the linear SVC model. Locally testing this package reveals no problem, but it looks to me that there are no tests for the linear case. A MWE that reproduces the same fail observed in the MLJ interface package is below:

using LIBSVM

n, p = 500, 2
X = rand(p, n)
y = rand([0, 1], n)
solver = LIBSVM.Linearsolver.L2R_L2LOSS_SVC_DUAL 
C = 1.0
bias = -1.0
eps = Inf
verbose = true

LIBSVM.LIBLINEAR.linear_train(
    y,
    X;
    solver_type = Int32(solver),  # this is just `Int32(1)`
    C,
    bias,
    eps,
    verbose,
)

# ERROR: Please check your parameters: Initial-solution specification supported only for solvers L2R_LR, L2R_L2LOSS_SVC, and L2R_L2LOSS_SVR
# Stacktrace:
#  [1] error(s::String)
#    @ Base ./error.jl:35
#  [2] linear_train(labels::Vector{…}, instances::Matrix{…}; weights::Nothing, solver_type::Int32, eps::Float64, C::Float64, p::Float64, init_sol::Ptr{…}, bias::Float64, verbose::Bool)
#    @ LIBLINEAR ~/.julia/packages/LIBLINEAR/77yny/src/LIBLINEAR.jl:227
#  [3] top-level scope
#    @ REPL[26]:1
# Some type information was truncated. Use `show(err)` to see complete types.

All my testing is with julia v1.10.0 and LIBSVM v0.8.0.

Since the last release of LIBSVM.jl, there was an update to the C library, LIBLINEAR. From their website: "Version 2.47 released on July 9, 2023. We fix some minor bugs." Could this be the culprit? Be good if someone else can confirm this or otherwise resolve the issue 😄.

It is a bug in LIBLINEAR.jl. Structure Parameter was not properly mirroring the corresponding C structure in LIBLINEAR. I pushed a quick fix (see JuliaML/LIBLINEAR.jl#29), but it needs some more work.

It would help if LIBLINEAR.jl is in JuliaML (JuliaML/LIBLINEAR.jl#27).