lalvim / PartialLeastSquaresRegressor.jl

Implementation of a Partial Least Squares Regressor
MIT License
40 stars 8 forks source link

Regressors failing for some kinds of data #29

Closed ablaom closed 1 year ago

ablaom commented 2 years ago

For some data sets training is failing. Given the MethodError thrown, this looks like a bug to me:

julia> using MLJBase, PartialLeastSquaresRegressor

julia> X, y = @load_boston;

julia> machine(PartialLeastSquaresRegressor.PLSRegressor(), X, y) |> fit!
[ Info: Training machine(PLSRegressor(n_factors = 1), …).
┌ Error: Problem fitting the machine machine(PLSRegressor(n_factors = 1), …). 
└ @ MLJBase ~/.julia/packages/MLJBase/wnJff/src/machines.jl:617
[ Info: Running type checks... 
[ Info: Type checks okay. 
ERROR: MethodError: no method matching check_constant_cols(::SubArray{Float64, 1, Matrix{Float64}, Tuple{Base.Slice{Base.OneTo{Int64}}, Int64}, true})
Closest candidates are:
  check_constant_cols(::Matrix{T}) where T<:AbstractFloat at /Users/anthony/.julia/packages/PartialLeastSquaresRegressor/OrIoJ/src/utils.jl:26
  check_constant_cols(::Vector{T}) where T<:AbstractFloat at /Users/anthony/.julia/packages/PartialLeastSquaresRegressor/OrIoJ/src/utils.jl:27
Stacktrace:
 [1] fit(m::PartialLeastSquaresRegressor.PLSRegressor, verbosity::Int64, X::NamedTuple{(:Crim, :Zn, :Indus, :NOx, :Rm, :Age, :Dis, :Rad, :Tax, :PTRatio, :Black, :LStat), NTuple{12, SubArray{Float64, 1, Matrix{Float64}, Tuple{Base.Slice{Base.OneTo{Int64}}, Int64}, true}}}, Y::SubArray{Float64, 1, Matrix{Float64}, Tuple{Base.Slice{Base.OneTo{Int64}}, Int64}, true})
   @ PartialLeastSquaresRegressor ~/.julia/packages/PartialLeastSquaresRegressor/OrIoJ/src/mlj_interface.jl:65
 [2] fit_only!(mach::Machine{PartialLeastSquaresRegressor.PLSRegressor, true}; rows::Nothing, verbosity::Int64, force::Bool)
   @ MLJBase ~/.julia/packages/MLJBase/wnJff/src/machines.jl:615
 [3] fit_only!
   @ ~/.julia/packages/MLJBase/wnJff/src/machines.jl:568 [inlined]
 [4] #fit!#52
   @ ~/.julia/packages/MLJBase/wnJff/src/machines.jl:683 [inlined]
 [5] fit!
   @ ~/.julia/packages/MLJBase/wnJff/src/machines.jl:681 [inlined]
 [6] |>(x::Machine{PartialLeastSquaresRegressor.PLSRegressor, true}, f::typeof(fit!))
   @ Base ./operators.jl:858
 [7] top-level scope
   @ REPL[162]:1
 [8] top-level scope
   @ ~/.julia/packages/CUDA/fAEDi/src/initialization.jl:52
ablaom commented 1 year ago

Probably check_constant_cols(::Matrix{T}) and check_constant_cols(::Vector{T}) just need to be made generic: