JuliaAI / MLJ.jl

A Julia machine learning framework
https://juliaai.github.io/MLJ.jl/
Other
1.8k stars 157 forks source link

Improve error message for non-functions in @pipeline ... operation=... #600

Closed ghost closed 4 years ago

ghost commented 4 years ago

Describe the bug

Some keyword arguments raise an error when included in pipeline. In the below example, this is the case for operation=:predict_mode but not for prediction_type=:probabilistic.

To Reproduce

KnnPipe = @pipeline(Standardizer(), KNNClassifier(), prediction_type=:probabilistic, operation=:predict_mode)

Expected behavior Expected to be able to use operation as a kwarg based on latest doc: https://alan-turing-institute.github.io/MLJ.jl/stable/composing_models/

Additional context

ERROR: LoadError: ArgumentError: @pipeline error.
`operation=predict_mode` is unsupported. 
Stacktrace:
 [1] pipe_alert(::String) at /Users/GD/.julia/packages/MLJBase/b1egR/src/composition/models/pipelines.jl:144
 [2] pipeline_preprocess(::Module, ::Expr, ::Vararg{Expr,N} where N) at /Users/GD/.julia/packages/MLJBase/b1egR/src/composition/models/pipelines.jl:251
 [3] pipeline_(::Module, ::Expr, ::Vararg{Expr,N} where N) at /Users/GD/.julia/packages/MLJBase/b1egR/src/composition/models/pipelines.jl:439
 [4] @pipeline(::LineNumberNode, ::Module, ::Vararg{Any,N} where N) at /Users/GD/.julia/packages/MLJBase/b1egR/src/composition/models/pipelines.jl:562
in expression starting at none:1

Versions

ablaom commented 4 years ago

Great spot! This is a bug.

ablaom commented 4 years ago

Correction. Strictly speaking, not a bug. The correct call is

KnnPipe = @pipeline(Standardizer(), KNNClassifier(), prediction_type=:probabilistic, operation=predict_mode)

(no colon before predict_mode)

But we should improve the error message.

ablaom commented 4 years ago

By the way, the prediction_type=:probablistic is now redundant as this is automatically inferred. If the macro cannot safely infer this, it will let you know.

ablaom commented 4 years ago

Closing in favour of https://github.com/alan-turing-institute/MLJBase.jl/issues/367