Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ MLBase = "f0e99cf1-93fa-52ec-9ecc-5026115318e0"

[compat]
DataFrames = "1"
Documenter = "0.24"
Documenter = "0.24, 1"
Lasso = "0.7"
MLBase = "0.9"
2 changes: 2 additions & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ makedocs(
sitename = "Lasso.jl",
authors = "Simon Kornblith, Asaf Manela, and contributors.",
linkcheck = !("skiplinks" in ARGS),
warnonly = [:missing_docs],
doctestfilters = [r"(?<=\.\d{5})\d+"],
pages = [
"Home" => "index.md",
"Lasso paths" => "lasso.md",
Expand Down
14 changes: 7 additions & 7 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Journal of Computational and Graphical Statistics, 26:3, 525-536.
julia> using DataFrames, Lasso

julia> data = DataFrame(X=[1,2,3], Y=[2,4,7])
3×2 DataFrames.DataFrame
3×2 DataFrame
Row │ X Y
│ Int64 Int64
─────┼──────────────
Expand All @@ -60,20 +60,20 @@ Coefficients:
────────────
Estimate
────────────
x1 3.88915
x1 3.88915
x2 0.222093
────────────

julia> predict(m)
3-element Array{Float64,1}:
4.111240223622052
3-element Vector{Float64}:
4.111240223622057
4.333333333333333
4.555426443044614
4.555426443044609

julia> predict(m, data[2:end,:])
2-element Array{Union{Missing, Float64},1}:
2-element Vector{Union{Missing, Float64}}:
4.333333333333333
4.555426443044614
4.555426443044609
```

In the variant above, it automatically picks the size of penalty to apply to ``x_2``.
Expand Down
18 changes: 8 additions & 10 deletions docs/src/lasso.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,32 +71,30 @@ step as follows:
```jldoctest
julia> using DataFrames, Lasso, MLBase, Random

julia> Random.seed!(124); # because CV folds are random

julia> data = DataFrame(X=[1,2,3], Y=[2,4,7])
3×2 DataFrames.DataFrame
3×2 DataFrame
Row │ X Y
│ Int64 Int64
─────┼──────────────
1 │ 1 2
2 │ 2 4
3 │ 3 7

julia> m = fit(LassoModel, @formula(Y ~ X), data; select=MinCVmse(Kfold(3,2)))
LassoModel using MinCVmse(Kfold([3, 1, 2], 2, 1.5)) segment of the regularization path.
julia> m = fit(LassoModel, @formula(Y ~ X), data; select=MinCVmse(Kfold(MersenneTwister(124), 3, 2)))
LassoModel using MinCVmse(Kfold([1, 2, 3], 2, 1.5)) segment of the regularization path.

Coefficients:
────────────
Estimate
────────────
x1 4.33333
x2 0.0
x1 -0.63377
x2 2.48355
────────────

julia> coef(m)
2-element Array{Float64,1}:
4.333333333333333
0.0
2-element Vector{Float64}:
-0.6337700054337887
2.483551669383561

```

Expand Down
7 changes: 6 additions & 1 deletion src/segselect.jl
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,13 @@ end
function Base.show(io::IO, obj::RegularizedModel)
# prefix = isa(obj.m, GeneralizedLinearModel) ? string(typeof(distfun(path)).name.name, " ") : ""
println(io, "$(typeof(obj).name.name) using $(obj.select) segment of the regularization path.")
println(io, "\nCoefficients:")
show(io, MIME("text/plain"), coeftable(obj))
println(io)
end

println(io, "\nCoefficients:\n", coeftable(obj))
function Base.show(io::IO, ::MIME"text/plain", obj::StatsModels.TableRegressionModel{<:RegularizedModel})
show(io, obj.model)
end

StatsBase.vcov(obj::RegularizedModel, args...) = error("variance-covariance matrix for a regularized model is not yet implemented")
24 changes: 11 additions & 13 deletions test/cross_validation.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using MLBase, Random
using MLBase, Random, StableRNGs

@testset "cross validation" begin

Expand Down Expand Up @@ -27,25 +27,23 @@ segminAIC = Lasso.minAIC(path)
@test segminAIC == 72
@test coefsAIC == β[:,segminAIC]

Random.seed!(13)
gen = Kfold(length(y),10)
gen = Kfold(StableRNG(13), length(y), 10)
segCVmin = cross_validate_path(path, MinCVmse(gen))
coefsCVmin = coef(path, MinCVmse(path))
coefsCVmin = coef(path, MinCVmse(Kfold(StableRNG(13), length(y), 10)))
@test segCVmin == 72
@test coefsCVmin == β[:,segCVmin]

Random.seed!(13)
gen = Kfold(length(y),10)
segCVmin = cross_validate_path(path,X,y, MinCVmse(gen), offset=offset)
coefsCVmin = coef(path, MinCVmse(path))
gen = Kfold(StableRNG(13), length(y), 10)
segCVmin = cross_validate_path(path, X, y, MinCVmse(gen), offset=offset)
coefsCVmin = coef(path, MinCVmse(Kfold(StableRNG(13), length(y), 10)))
@test segCVmin == 72
@test coefsCVmin == β[:,segCVmin]

Random.seed!(13)
coefsCV1se = coef(path, MinCV1se(path, 20))
Random.seed!( 13)
segCV1se = cross_validate_path(path,X,y, MinCV1se(path, 20),offset=offset)
@test segCV1se == 42
gen1 = Kfold(StableRNG(13), length(y), 20)
coefsCV1se = coef(path, MinCV1se(gen1))
gen2 = Kfold(StableRNG(13), length(y), 20)
segCV1se = cross_validate_path(path, X, y, MinCV1se(gen2), offset=offset)
@test segCV1se == 41
@test coefsCV1se == β[:,segCV1se]

end
Loading