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
— Type.SModel(x, y, args...)
Create a SparseRegression model with predictor matrix x
and response vector y
. 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{Void, AbstractWeights} = nothing
Example
x = randn(1000, 5)
y = x * linspace(-1, 1, 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 * linspace(-1, 1, 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))