lalvim / PartialLeastSquaresRegressor.jl

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

Example 1 does not work #32

Closed JeffFessler closed 1 year ago

JeffFessler commented 1 year ago

The example 1 in the readme has issues:

julia> regressor = PLSRegressor(n_factors=2)
ERROR: UndefVarError: PLSRegressor not defined

This is easily fixed by adding using PartialLeastSquaresRegressor: PLSRegressor but maybe you really should export that type from the package?

Then a bit later this happens:

julia> pls_model = @pipeline Standardizer regressor target=Standardizer

ERROR: LoadError: The `@pipeline` macro is deprecated. For pipelines without target transformations use pipe syntax, as in `ContinuousEncoder() |> Standardizer() |> my_classifier`. For details and advanced optioins, query the `Pipeline` docstring. To wrap a supervised model in a target transformation, use `TransformedTargetModel`, as in `TransformedTargetModel(my_regressor, target=Standardizer())`
in expression starting at REPL[16]:1

We would love to use the package, but we need a working example.

In the long term, I recommend using Literate.jl, to show working examples because then they are tested as part of CI, whereas examples in a README are not. But in the short run could you please fix the readme? Here is one Literate example: https://jefffessler.github.io/ScoreMatching.jl/dev/generated/examples/01-overview/

ablaom commented 1 year ago

I'm not a maintainer of this package, but here's an update to the example in the readme that works for me:

using MLJBase, RDatasets, MLJModels
PLSRegressor = @load PLSRegressor pkg=PartialLeastSquaresRegressor

# loading data and selecting some features
data = dataset("datasets", "longley")[:, 2:5]

# unpacking the target
y, X = unpack(data, ==(:GNP))

# loading the model
regressor = PLSRegressor(n_factors=2)

# building a pipeline with scaling on data
pipe = Standardizer |> regressor
model = TransformedTargetModel(pipe, transformer=Standardizer())

# a simple hould out
(Xtrain, Xtest), (ytrain, ytest) = partition((X, y), 0.7, rng=123, multi=true)

mach = machine(model, Xtest, ytest)

fit!(mach)
yhat = predict(mach, Xtest)

mae(yhat, ytest) |> mean

Note you need PartialLeastSquaresRegressor in your environment.

lalvim commented 1 year ago

Thanks @ablaom .

Now it is ok @JeffFessler ?

I am a little away from package maintenance due to other work tasks.

JeffFessler commented 1 year ago

Yes, that version ran fine for me. Thanks @ablaom! I guess I'll leave the issue open and someone can close it after the readme gets updated...

lalvim commented 1 year ago

Readme updated.