Usage
- Create a model
- Fit the model
SModel
The model type used by SparseRegression is SModel
. An SModel
holds onto the sufficient information for generating a solution fo the SparseRegression objective.
Constructing an SModel
does not create a fitted model. It must be learn!
-ed.
SparseRegression.SModel
— TypeSModel(x, y, args...)
Create a SparseRegression model with predictor AbstractMatrix x
and response AbstractVector y
. x
must have methods:
mul!(::Vector{Float64}, x, ::Vector{Float64})
mul!(::Vector{Float64}, x', ::Vector{Float64})
The additional arguments can be given in any order.
Arguments
loss::Loss = .5 * L2DistLoss()
penalty::Penalty = L2Penalty()
λ::Vector{Float64} = fill(size(x, 2), .1)
w::Union{Nothing, AbstractWeights} = nothing
Example
x = randn(1000, 5)
y = x * range(-1, stop=1, length=5) + randn(1000)
s = SModel(x, y)
learn!(s)
s
LearningStrategies
An SModel
can be learned with the default learning strategy with learn!(model)
. You can provide more control over the learning process by providing your own LearningStrategy.
SparseRegression implements several Algorithm <: LearningStrategy
types to do SModel
fitting. An Algorithm
must be constructed with an SModel
to ensure storage buffers are the correct size.
using SparseRegression
# Make some fake data
x = randn(1000, 10)
y = x * range(-1, stop=1, length=10) + randn(1000)
# Create an SModel
s = SModel(x, y)
# All of the following are valid ways to calculate a solution
learn!(s)
learn!(s, strategy(ProxGrad(s), MaxIter(25), TimeLimit(.5)))
learn!(s, Sweep(s))
learn!(s, LinRegCholesky(s))