API
Standalone
Regression
Standard constructors
MLJLinearModels.LinearRegression — FunctionLinearRegression(; fit_intercept)
Objective function: $|Xθ - y|₂²/2$.
MLJLinearModels.RidgeRegression — FunctionRidgeRegression()
RidgeRegression(λ; lambda, fit_intercept, penalize_intercept, scale_penalty_with_samples)
Objective function: $|Xθ - y|₂²/2 + n⋅λ|θ|₂²/2$, where $n$ is the number of samples size(X, 1). With scale_penalty_with_samples = false the objective function is $|Xθ - y|₂²/2 + λ|θ|₂²/2$.
MLJLinearModels.LassoRegression — FunctionLassoRegression()
LassoRegression(λ; lambda, fit_intercept, penalize_intercept, scale_penalty_with_samples)
Objective function: $|Xθ - y|₂²/2 + n⋅λ|θ|₁$, where $n$ is the number of samples size(X, 1). With scale_penalty_with_samples = false the objective function is $|Xθ - y|₂²/2 + λ|θ|₁$
MLJLinearModels.ElasticNetRegression — FunctionElasticNetRegression()
ElasticNetRegression(λ)
ElasticNetRegression(λ, γ; lambda, gamma, fit_intercept, penalize_intercept, scale_penalty_with_samples)
Objective function: $|Xθ - y|₂²/2 + n⋅λ|θ|₂²/2 + n⋅γ|θ|₁$, where $n$ is the number of samples size(X, 1). With scale_penalty_with_samples = false the objective function is $|Xθ - y|₂²/2 + λ|θ|₂²/2 + γ|θ|₁$
MLJLinearModels.HuberRegression — FunctionHuberRegression()
HuberRegression(δ)
HuberRegression(δ, λ)
HuberRegression(δ, λ, γ; delta, lambda, gamma, penalty, fit_intercept, scale_penalty_with_samples, penalize_intercept)
Huber Regression with objective:
$∑ρ(Xθ - y) + n⋅λ|θ|₂²/2 + n⋅γ|θ|₁$
Where ρ is the Huber function ρ(r) = r²/2if|r|≤δandρ(r)=δ(|r|-δ/2)otherwise andnis the number of samplessize(X, 1). Withscalepenaltywith_samples = falsethe objective function is∑ρ(Xθ - y) + λ|θ|₂²/2 + γ|θ|₁`.
MLJLinearModels.QuantileRegression — FunctionQuantileRegression()
QuantileRegression(δ)
QuantileRegression(δ, λ)
QuantileRegression(δ, λ, γ; delta, lambda, gamma, penalty, fit_intercept, scale_penalty_with_samples, penalize_intercept)
Quantile Regression with objective:
$∑ρ(Xθ - y) + n⋅λ|θ|₂²/2 + n⋅γ|θ|₁$
Where ρ is the check function ρ(r) = r(δ - 1(r < 0)) and $n$ is the number of samples size(X, 1). With scale_penalty_with_samples = false the objective function is $∑ρ(Xθ - y) + λ|θ|₂²/2 + γ|θ|₁$.
MLJLinearModels.LADRegression — FunctionLADRegression()
LADRegression(λ)
LADRegression(λ, γ; lambda, gamma, penalty, scale_penalty_with_samples, fit_intercept, penalize_intercept)
Least Absolute Deviation regression with objective:
$|Xθ - y|₁ + n⋅λ|θ|₂²/2 + n⋅γ|θ|₁$ where $n$ is the number of samples size(X, 1). With scale_penalty_with_samples = false the objective function is $|Xθ - y|₁ + λ|θ|₂²/2 + γ|θ|₁$.
This is a specific type of Quantile Regression with δ=0.5 (median).
Generic constructors
MLJLinearModels.GeneralizedLinearRegression — TypeGeneralizedLinearRegression{L<:Loss, P<:Penalty}Generalized Linear Regression (GLR) model with objective function:
$L(y, Xθ) + P(θ)$
where L is a loss function, P a penalty, y is the vector of observed response, X is the feature matrix and θ the vector of parameters. If scale_penalty_with_samples = true (default) the penalty is automatically scaled with the number of samples.
Special cases include:
- OLS regression: L2 loss, no penalty.
- Ridge regression: L2 loss, L2 penalty.
- Lasso regression: L2 loss, L1 penalty.
- Logistic regression: Logit loss, [no,L1,L2] penalty.
MLJLinearModels.RobustRegression — FunctionRobustRegression()
RobustRegression(ρ)
RobustRegression(ρ, λ)
RobustRegression(ρ, λ, γ; rho, lambda, gamma, penalty, fit_intercept, scale_penalty_with_samples, penalize_intercept)
Objective function: $∑ρ(Xθ - y) + n⋅λ|θ|₂² + n⋅γ|θ|₁$ where ρ is a given function on the residuals and $n$ is the number of samples size(X, 1). With scale_penalty_with_samples = false the objective function is $∑ρ(Xθ - y) + λ|θ|₂² + γ|θ|₁$.
Classification
MLJLinearModels.LogisticRegression — FunctionLogisticRegression()
LogisticRegression(λ)
LogisticRegression(λ, γ; lambda, gamma, penalty, fit_intercept, penalize_intercept, scale_penalty_with_samples, multi_class, nclasses)
Objective function: $L(y, Xθ) + n⋅λ|θ|₂²/2 + n⋅γ|θ|₁$ where L is either the logistic loss in the binary case or the multinomial loss otherwise and $n$ is the number of samples size(X, 1). With scale_penalty_with_samples = false the objective function is $L(y, Xθ) + λ|θ|₂²/2 + γ|θ|₁$.
MLJLinearModels.MultinomialRegression — FunctionMultinomialRegression(a; kwa...)
Objective function: $L(y, Xθ) + n⋅λ|θ|₂²/2 + n⋅γ|θ|₁$ where L is the multinomial loss and $n$ is the number of samples size(X, 1). With scale_penalty_with_samples = false the objective function is $L(y, Xθ) + λ|θ|₂²/2 + γ|θ|₁$.
MLJ Interface
Regressors
MLJLinearModels.LinearRegressor — TypeLinearRegressorA model type for constructing a linear regressor, based on MLJLinearModels.jl, and implementing the MLJ model interface.
From MLJ, the type can be imported using
LinearRegressor = @load LinearRegressor pkg=MLJLinearModelsDo model = LinearRegressor() to construct an instance with default hyper-parameters.
This model provides standard linear regression with objective function
$|Xθ - y|₂²/2$
Different solver options exist, as indicated under "Hyperparameters" below.
Training data
In MLJ or MLJBase, bind an instance model to data with
mach = machine(model, X, y)where:
Xis any table of input features (eg, aDataFrame) whose columns haveContinuousscitype; check column scitypes withschema(X)yis the target, which can be anyAbstractVectorwhose element scitype isContinuous; check the scitype withscitype(y)
Train the machine using fit!(mach, rows=...).
Hyperparameters
fit_intercept::Boolwhether to fit the intercept or not. Default: true
solver::Union{Nothing, MLJLinearModels.Solver}"any instance of
MLJLinearModels.Analytical. UseAnalytical()for Cholesky andCG()=Analytical(iterative=true)for conjugate-gradient.If
solver = nothing(default) thenAnalytical()is used. Default: nothing
Example
using MLJ
X, y = make_regression()
mach = fit!(machine(LinearRegressor(), X, y))
predict(mach, X)
fitted_params(mach)MLJLinearModels.RidgeRegressor — TypeRidgeRegressorA model type for constructing a ridge regressor, based on MLJLinearModels.jl, and implementing the MLJ model interface.
From MLJ, the type can be imported using
RidgeRegressor = @load RidgeRegressor pkg=MLJLinearModelsDo model = RidgeRegressor() to construct an instance with default hyper-parameters.
Ridge regression is a linear model with objective function
$|Xθ - y|₂²/2 + n⋅λ|θ|₂²/2$
where $n$ is the number of observations.
If scale_penalty_with_samples = false then the objective function is instead
$|Xθ - y|₂²/2 + λ|θ|₂²/2$.
Different solver options exist, as indicated under "Hyperparameters" below.
Training data
In MLJ or MLJBase, bind an instance model to data with
mach = machine(model, X, y)where:
Xis any table of input features (eg, aDataFrame) whose columns haveContinuousscitype; check column scitypes withschema(X)yis the target, which can be anyAbstractVectorwhose element scitype isContinuous; check the scitype withscitype(y)
Train the machine using fit!(mach, rows=...).
Hyperparameters
lambda::Realstrength of the L2 regularization. Default: 1.0
fit_intercept::Boolwhether to fit the intercept or not. Default: true
penalize_intercept::Boolwhether to penalize the intercept. Default: false
scale_penalty_with_samples::Boolwhether to scale the penalty with the number of observations. Default: true
solver::Union{Nothing, MLJLinearModels.Solver}any instance of
MLJLinearModels.Analytical. UseAnalytical()for Cholesky andCG()=Analytical(iterative=true)for conjugate-gradient. Ifsolver = nothing(default) thenAnalytical()is used. Default: nothing
Example
using MLJ
X, y = make_regression()
mach = fit!(machine(RidgeRegressor(), X, y))
predict(mach, X)
fitted_params(mach)See also ElasticNetRegressor.
MLJLinearModels.LassoRegressor — TypeLassoRegressorA model type for constructing a lasso regressor, based on MLJLinearModels.jl, and implementing the MLJ model interface.
From MLJ, the type can be imported using
LassoRegressor = @load LassoRegressor pkg=MLJLinearModelsDo model = LassoRegressor() to construct an instance with default hyper-parameters.
Lasso regression is a linear model with objective function
$|Xθ - y|₂²/2 + n⋅λ|θ|₁$
where $n$ is the number of observations.
If scale_penalty_with_samples = false the objective function is
$|Xθ - y|₂²/2 + λ|θ|₁$.
Different solver options exist, as indicated under "Hyperparameters" below.
Training data
In MLJ or MLJBase, bind an instance model to data with
mach = machine(model, X, y)where:
Xis any table of input features (eg, aDataFrame) whose columns haveContinuousscitype; check column scitypes withschema(X)yis the target, which can be anyAbstractVectorwhose element scitype isContinuous; check the scitype withscitype(y)
Train the machine using fit!(mach, rows=...).
Hyperparameters
lambda::Realstrength of the L1 regularization. Default: 1.0
fit_intercept::Boolwhether to fit the intercept or not. Default: true
penalize_intercept::Boolwhether to penalize the intercept. Default: false
scale_penalty_with_samples::Boolwhether to scale the penalty with the number of observations. Default: true
solver::Union{Nothing, MLJLinearModels.Solver}any instance of
MLJLinearModels.ProxGrad. Ifsolver=nothing(default) thenProxGrad(accel=true)(FISTA) is used. Solver aliases:FISTA(; kwargs...) = ProxGrad(accel=true, kwargs...),ISTA(; kwargs...) = ProxGrad(accel=false, kwargs...). Default: nothing
Example
using MLJ
X, y = make_regression()
mach = fit!(machine(LassoRegressor(), X, y))
predict(mach, X)
fitted_params(mach)See also ElasticNetRegressor.
MLJLinearModels.ElasticNetRegressor — TypeElasticNetRegressorA model type for constructing a elastic net regressor, based on MLJLinearModels.jl, and implementing the MLJ model interface.
From MLJ, the type can be imported using
ElasticNetRegressor = @load ElasticNetRegressor pkg=MLJLinearModelsDo model = ElasticNetRegressor() to construct an instance with default hyper-parameters.
Elastic net is a linear model with objective function
$|Xθ - y|₂²/2 + n⋅λ|θ|₂²/2 + n⋅γ|θ|₁$
where $n$ is the number of observations.
If scale_penalty_with_samples = false the objective function is instead
$|Xθ - y|₂²/2 + λ|θ|₂²/2 + γ|θ|₁$.
Different solver options exist, as indicated under "Hyperparameters" below.
Training data
In MLJ or MLJBase, bind an instance model to data with
mach = machine(model, X, y)where:
Xis any table of input features (eg, aDataFrame) whose columns haveContinuousscitype; check column scitypes withschema(X)yis the target, which can be anyAbstractVectorwhose element scitype isContinuous; check the scitype withscitype(y)
Train the machine using fit!(mach, rows=...).
Hyperparameters
lambda::Realstrength of the L2 regularization. Default: 1.0
gamma::Realstrength of the L1 regularization. Default: 0.0
fit_intercept::Boolwhether to fit the intercept or not. Default: true
penalize_intercept::Boolwhether to penalize the intercept. Default: false
scale_penalty_with_samples::Boolwhether to scale the penalty with the number of observations. Default: true
solver::Union{Nothing, MLJLinearModels.Solver}any instance of
MLJLinearModels.ProxGrad.If
solver=nothing(default) thenProxGrad(accel=true)(FISTA) is used.Solver aliases:
FISTA(; kwargs...) = ProxGrad(accel=true, kwargs...),ISTA(; kwargs...) = ProxGrad(accel=false, kwargs...). Default: nothing
Example
using MLJ
X, y = make_regression()
mach = fit!(machine(ElasticNetRegressor(), X, y))
predict(mach, X)
fitted_params(mach)See also LassoRegressor.
MLJLinearModels.HuberRegressor — TypeHuberRegressorA model type for constructing a huber regressor, based on MLJLinearModels.jl, and implementing the MLJ model interface.
From MLJ, the type can be imported using
HuberRegressor = @load HuberRegressor pkg=MLJLinearModelsDo model = HuberRegressor() to construct an instance with default hyper-parameters.
This model coincides with RobustRegressor, with the exception that the robust loss, rho, is fixed to HuberRho(delta), where delta is a new hyperparameter.
Different solver options exist, as indicated under "Hyperparameters" below.
Training data
In MLJ or MLJBase, bind an instance model to data with
mach = machine(model, X, y)where:
Xis any table of input features (eg, aDataFrame) whose columns haveContinuousscitype; check column scitypes withschema(X)yis the target, which can be anyAbstractVectorwhose element scitype isContinuous; check the scitype withscitype(y)
Train the machine using fit!(mach, rows=...).
Hyperparameters
delta::Realparameterizes the
HuberRhofunction (radius of the ball within which the loss is a quadratic loss) Default: 0.5lambda::Realstrength of the regularizer if
penaltyis:l2or:l1. Strength of the L2 regularizer ifpenaltyis:en. Default: 1.0gamma::Realstrength of the L1 regularizer if
penaltyis:en. Default: 0.0penalty::Union{String, Symbol}the penalty to use, either
:l2,:l1,:en(elastic net) or:none. Default: :l2fit_intercept::Boolwhether to fit the intercept or not. Default: true
penalize_intercept::Boolwhether to penalize the intercept. Default: false
scale_penalty_with_samples::Boolwhether to scale the penalty with the number of observations. Default: true
solver::Union{Nothing, MLJLinearModels.Solver}some instance of
MLJLinearModels.SwhereSis one of:LBFGS,IWLSCG,Newton,NewtonCG, ifpenalty = :l2, andProxGradotherwise.If
solver = nothing(default) thenLBFGS()is used, ifpenalty = :l2, and otherwiseProxGrad(accel=true)(FISTA) is used.Solver aliases:
FISTA(; kwargs...) = ProxGrad(accel=true, kwargs...),ISTA(; kwargs...) = ProxGrad(accel=false, kwargs...)Default: nothing
Example
using MLJ
X, y = make_regression()
mach = fit!(machine(HuberRegressor(), X, y))
predict(mach, X)
fitted_params(mach)See also RobustRegressor, QuantileRegressor.
MLJLinearModels.QuantileRegressor — TypeQuantileRegressorA model type for constructing a quantile regressor, based on MLJLinearModels.jl, and implementing the MLJ model interface.
From MLJ, the type can be imported using
QuantileRegressor = @load QuantileRegressor pkg=MLJLinearModelsDo model = QuantileRegressor() to construct an instance with default hyper-parameters.
This model coincides with RobustRegressor, with the exception that the robust loss, rho, is fixed to QuantileRho(delta), where delta is a new hyperparameter.
Different solver options exist, as indicated under "Hyperparameters" below.
Training data
In MLJ or MLJBase, bind an instance model to data with
mach = machine(model, X, y)where:
Xis any table of input features (eg, aDataFrame) whose columns haveContinuousscitype; check column scitypes withschema(X)yis the target, which can be anyAbstractVectorwhose element scitype isContinuous; check the scitype withscitype(y)
Train the machine using fit!(mach, rows=...).
Hyperparameters
delta::Realparameterizes the
QuantileRhofunction (indicating the quantile to use with default0.5for the median regression) Default: 0.5lambda::Realstrength of the regularizer if
penaltyis:l2or:l1. Strength of the L2 regularizer ifpenaltyis:en. Default: 1.0gamma::Realstrength of the L1 regularizer if
penaltyis:en. Default: 0.0penalty::Union{String, Symbol}the penalty to use, either
:l2,:l1,:en(elastic net) or:none. Default: :l2fit_intercept::Boolwhether to fit the intercept or not. Default: true
penalize_intercept::Boolwhether to penalize the intercept. Default: false
scale_penalty_with_samples::Boolwhether to scale the penalty with the number of observations. Default: true
solver::Union{Nothing, MLJLinearModels.Solver}some instance of
MLJLinearModels.SwhereSis one of:LBFGS,IWLSCG, ifpenalty = :l2, andProxGradotherwise.If
solver = nothing(default) thenLBFGS()is used, ifpenalty = :l2, and otherwiseProxGrad(accel=true)(FISTA) is used.Solver aliases:
FISTA(; kwargs...) = ProxGrad(accel=true, kwargs...),ISTA(; kwargs...) = ProxGrad(accel=false, kwargs...)Default: nothing
Example
using MLJ
X, y = make_regression()
mach = fit!(machine(QuantileRegressor(), X, y))
predict(mach, X)
fitted_params(mach)See also RobustRegressor, HuberRegressor.
MLJLinearModels.LADRegressor — TypeLADRegressorA model type for constructing a lad regressor, based on MLJLinearModels.jl, and implementing the MLJ model interface.
From MLJ, the type can be imported using
LADRegressor = @load LADRegressor pkg=MLJLinearModelsDo model = LADRegressor() to construct an instance with default hyper-parameters.
Least absolute deviation regression is a linear model with objective function
$∑ρ(Xθ - y) + n⋅λ|θ|₂² + n⋅γ|θ|₁$
where $ρ$ is the absolute loss and $n$ is the number of observations.
If scale_penalty_with_samples = false the objective function is instead
$∑ρ(Xθ - y) + λ|θ|₂² + γ|θ|₁$.
Different solver options exist, as indicated under "Hyperparameters" below.
Training data
In MLJ or MLJBase, bind an instance model to data with
mach = machine(model, X, y)where:
Xis any table of input features (eg, aDataFrame) whose columns haveContinuousscitype; check column scitypes withschema(X)yis the target, which can be anyAbstractVectorwhose element scitype isContinuous; check the scitype withscitype(y)
Train the machine using fit!(mach, rows=...).
Hyperparameters
See also RobustRegressor.
Parameters
lambda::Realstrength of the regularizer if
penaltyis:l2or:l1. Strength of the L2 regularizer ifpenaltyis:en. Default: 1.0gamma::Realstrength of the L1 regularizer if
penaltyis:en. Default: 0.0penalty::Union{String, Symbol}the penalty to use, either
:l2,:l1,:en(elastic net) or:none. Default: :l2fit_intercept::Boolwhether to fit the intercept or not. Default: true
penalize_intercept::Boolwhether to penalize the intercept. Default: false
scale_penalty_with_samples::Boolwhether to scale the penalty with the number of observations. Default: true
solver::Union{Nothing, MLJLinearModels.Solver}some instance of
MLJLinearModels.SwhereSis one of:LBFGS,IWLSCG, ifpenalty = :l2, andProxGradotherwise.If
solver = nothing(default) thenLBFGS()is used, ifpenalty = :l2, and otherwiseProxGrad(accel=true)(FISTA) is used.Solver aliases:
FISTA(; kwargs...) = ProxGrad(accel=true, kwargs...),ISTA(; kwargs...) = ProxGrad(accel=false, kwargs...)Default: nothing
Example
using MLJ
X, y = make_regression()
mach = fit!(machine(LADRegressor(), X, y))
predict(mach, X)
fitted_params(mach)MLJLinearModels.RobustRegressor — TypeRobustRegressorA model type for constructing a robust regressor, based on MLJLinearModels.jl, and implementing the MLJ model interface.
From MLJ, the type can be imported using
RobustRegressor = @load RobustRegressor pkg=MLJLinearModelsDo model = RobustRegressor() to construct an instance with default hyper-parameters.
Robust regression is a linear model with objective function
$∑ρ(Xθ - y) + n⋅λ|θ|₂² + n⋅γ|θ|₁$
where $ρ$ is a robust loss function (e.g. the Huber function) and $n$ is the number of observations.
If scale_penalty_with_samples = false the objective function is instead
$∑ρ(Xθ - y) + λ|θ|₂² + γ|θ|₁$.
Different solver options exist, as indicated under "Hyperparameters" below.
Training data
In MLJ or MLJBase, bind an instance model to data with
mach = machine(model, X, y)where:
Xis any table of input features (eg, aDataFrame) whose columns haveContinuousscitype; check column scitypes withschema(X)yis the target, which can be anyAbstractVectorwhose element scitype isContinuous; check the scitype withscitype(y)
Train the machine using fit!(mach, rows=...).
Hyperparameters
rho::MLJLinearModels.RobustRhothe type of robust loss, which can be any instance of
MLJLinearModels.LwhereLis one of:AndrewsRho,BisquareRho,FairRho,HuberRho,LogisticRho,QuantileRho,TalwarRho,HuberRho,TalwarRho. Default: HuberRho(0.1)lambda::Realstrength of the regularizer if
penaltyis:l2or:l1. Strength of the L2 regularizer ifpenaltyis:en. Default: 1.0gamma::Realstrength of the L1 regularizer if
penaltyis:en. Default: 0.0penalty::Union{String, Symbol}the penalty to use, either
:l2,:l1,:en(elastic net) or:none. Default: :l2fit_intercept::Boolwhether to fit the intercept or not. Default: true
penalize_intercept::Boolwhether to penalize the intercept. Default: false
scale_penalty_with_samples::Boolwhether to scale the penalty with the number of observations. Default: true
solver::Union{Nothing, MLJLinearModels.Solver}some instance of
MLJLinearModels.SwhereSis one of:LBFGS,IWLSCG,Newton,NewtonCG, ifpenalty = :l2, andProxGradotherwise.If
solver = nothing(default) thenLBFGS()is used, ifpenalty = :l2, and otherwiseProxGrad(accel=true)(FISTA) is used.Solver aliases:
FISTA(; kwargs...) = ProxGrad(accel=true, kwargs...),ISTA(; kwargs...) = ProxGrad(accel=false, kwargs...)Default: nothing
Example
using MLJ
X, y = make_regression()
mach = fit!(machine(RobustRegressor(), X, y))
predict(mach, X)
fitted_params(mach)See also HuberRegressor, QuantileRegressor.
Classifiers
MLJLinearModels.LogisticClassifier — TypeLogisticClassifierA model type for constructing a logistic classifier, based on MLJLinearModels.jl, and implementing the MLJ model interface.
From MLJ, the type can be imported using
LogisticClassifier = @load LogisticClassifier pkg=MLJLinearModelsDo model = LogisticClassifier() to construct an instance with default hyper-parameters.
This model is more commonly known as "logistic regression". It is a standard classifier for both binary and multiclass classification. The objective function applies either a logistic loss (binary target) or multinomial (softmax) loss, and has a mixed L1/L2 penalty:
$L(y, Xθ) + n⋅λ|θ|₂²/2 + n⋅γ|θ|₁$.
Here $L$ is either MLJLinearModels.LogisticLoss or MLJLinearModels.MultiClassLoss, $λ$ and $γ$ indicate the strength of the L2 (resp. L1) regularization components and $n$ is the number of training observations.
With scale_penalty_with_samples = false the objective function is instead
$L(y, Xθ) + λ|θ|₂²/2 + γ|θ|₁$.
Training data
In MLJ or MLJBase, bind an instance model to data with
mach = machine(model, X, y)where:
Xis any table of input features (eg, aDataFrame) whose columns haveContinuousscitype; check column scitypes withschema(X)yis the target, which can be anyAbstractVectorwhose element scitype is<:OrderedFactoror<:Multiclass; check the scitype withscitype(y)
Train the machine using fit!(mach, rows=...).
Hyperparameters
lambda::Realstrength of the regularizer if
penaltyis:l2or:l1and strength of the L2 regularizer ifpenaltyis:en. Default: eps()gamma::Realstrength of the L1 regularizer if
penaltyis:en. Default: 0.0penalty::Union{String, Symbol}the penalty to use, either
:l2,:l1,:en(elastic net) or:none. Default: :l2fit_intercept::Boolwhether to fit the intercept or not. Default: true
penalize_intercept::Boolwhether to penalize the intercept. Default: false
scale_penalty_with_samples::Boolwhether to scale the penalty with the number of samples. Default: true
solver::Union{Nothing, MLJLinearModels.Solver}some instance of
MLJLinearModels.SwhereSis one of:LBFGS,Newton,NewtonCG,ProxGrad; but subject to the following restrictions:If
penalty = :l2,ProxGradis disallowed. Otherwise,ProxGradis the only option.Unless
scitype(y) <: Finite{2}(binary target)Newtonis disallowed.
If
solver = nothing(default) thenProxGrad(accel=true)(FISTA) is used, unlessgamma = 0, in which caseLBFGS()is used.Solver aliases:
FISTA(; kwargs...) = ProxGrad(accel=true, kwargs...),ISTA(; kwargs...) = ProxGrad(accel=false, kwargs...)Default: nothing
Example
using MLJ
X, y = make_blobs(centers = 2)
mach = fit!(machine(LogisticClassifier(), X, y))
predict(mach, X)
fitted_params(mach)See also MultinomialClassifier.
MLJLinearModels.MultinomialClassifier — TypeMultinomialClassifierA model type for constructing a multinomial classifier, based on MLJLinearModels.jl, and implementing the MLJ model interface.
From MLJ, the type can be imported using
MultinomialClassifier = @load MultinomialClassifier pkg=MLJLinearModelsDo model = MultinomialClassifier() to construct an instance with default hyper-parameters.
This model coincides with LogisticClassifier, except certain optimizations possible in the special binary case will not be applied. Its hyperparameters are identical.
Training data
In MLJ or MLJBase, bind an instance model to data with
mach = machine(model, X, y)where:
Xis any table of input features (eg, aDataFrame) whose columns haveContinuousscitype; check column scitypes withschema(X)yis the target, which can be anyAbstractVectorwhose element scitype is<:OrderedFactoror<:Multiclass; check the scitype withscitype(y)
Train the machine using fit!(mach, rows=...).
Hyperparameters
lambda::Realstrength of the regularizer if
penaltyis:l2or:l1. Strength of the L2 regularizer ifpenaltyis:en. Default: eps()gamma::Realstrength of the L1 regularizer if
penaltyis:en. Default: 0.0penalty::Union{String, Symbol}the penalty to use, either
:l2,:l1,:en(elastic net) or:none. Default: :l2fit_intercept::Boolwhether to fit the intercept or not. Default: true
penalize_intercept::Boolwhether to penalize the intercept. Default: false
scale_penalty_with_samples::Boolwhether to scale the penalty with the number of samples. Default: true
solver::Union{Nothing, MLJLinearModels.Solver}some instance of
MLJLinearModels.SwhereSis one of:LBFGS,NewtonCG,ProxGrad; but subject to the following restrictions:If
penalty = :l2,ProxGradis disallowed. Otherwise,ProxGradis the only option.Unless
scitype(y) <: Finite{2}(binary target)Newtonis disallowed.
If
solver = nothing(default) thenProxGrad(accel=true)(FISTA) is used, unlessgamma = 0, in which caseLBFGS()is used.Solver aliases:
FISTA(; kwargs...) = ProxGrad(accel=true, kwargs...),ISTA(; kwargs...) = ProxGrad(accel=false, kwargs...)Default: nothing
Example
using MLJ
X, y = make_blobs(centers = 3)
mach = fit!(machine(MultinomialClassifier(), X, y))
predict(mach, X)
fitted_params(mach)See also LogisticClassifier.