Implementation of a Partial Least Squares Regressor
MIT License
The PartialLeastSquaresRegressor.jl package is a package with Partial Least Squares Regressor methods. Contains PLS1, PLS2 and Kernel PLS2 NIPALS algorithms. Can be used mainly for regression. However, for classification task, binarizing targets and then obtaining multiple targets, you can apply KPLS.
The package can be installed with the Julia package manager.
From the Julia REPL, type ]
to enter the Pkg REPL mode and run:
pkg> add PartialLeastSquaresRegressor
Or, equivalently, via the Pkg
API:
julia> import Pkg; Pkg.add("PartialLeastSquaresRegressor")
PartialLeastSquaresRegressor is used with MLJ machine learning framework. Here are a few examples to show the Package functionalities:
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
using MLJBase, RDatasets, MLJTuning, MLJModels
@load KPLSRegressor pkg=PartialLeastSquaresRegressor
# loading data and selecting some features
data = dataset("datasets", "longley")[:, 2:5]
# unpacking the target
y, X = unpack(data, ==(:GNP), colname -> true)
# loading the model
pls_model = KPLSRegressor()
# defining hyperparams for tunning
r1 = range(pls_model, :width, lower=0.001, upper=100.0, scale=:log)
# attaching tune
self_tuning_pls_model = TunedModel(model = pls_model,
resampling = CV(nfolds = 10),
tuning = Grid(resolution = 100),
range = [r1],
measure = mae)
# putting into the machine
self_tuning_pls = machine(self_tuning_pls_model, X, y)
# fitting with tunning
fit!(self_tuning_pls, verbosity=0)
# getting the report
report(self_tuning_pls)
PLS - PLS MLJ model (PLS1 or PLS2)
KPLS - Kernel PLS MLJ model
PLS1 and PLS2 based on
A Kernel PLS2 based on
NIPALS: Nonlinear Iterative Partial Least Squares
SIMPLS: more efficient, optimal result
The PartialLeastSquaresRegressor.jl is free software: you can redistribute it and/or modify it under the terms of the MIT "Expat"
License. A copy of this license is provided in LICENSE