diff --git a/src/GLMNet.jl b/src/GLMNet.jl index cd21242..cc94f43 100644 --- a/src/GLMNet.jl +++ b/src/GLMNet.jl @@ -204,9 +204,9 @@ modeltype(::Normal) = "Least Squares" modeltype(::Binomial) = "Logistic" modeltype(::Poisson) = "Poisson" -function show(io::IO, g::GLMNetPath) +function show(io::IO, ::MIME"text/plain", g::GLMNetPath) println(io, "$(modeltype(g.family)) GLMNet Solution Path ($(size(g.betas, 2)) solutions for $(size(g.betas, 1)) predictors in $(g.npasses) passes):") - print(io, CoefTable(Union{Vector{Int},Vector{Float64}}[nactive(g.betas), g.dev_ratio, g.lambda], ["df", "pct_dev", "λ"], [])) + show(io, MIME"text/plain"(), CoefTable(Union{Vector{Int},Vector{Float64}}[nactive(g.betas), g.dev_ratio, g.lambda], ["df", "pct_dev", "λ"], [])) end function check_jerr(jerr, maxit, pmax) diff --git a/test/runtests.jl b/test/runtests.jl index 25b34f2..59d662f 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -172,8 +172,85 @@ cv = glmnetcv(X, y; folds=[1,1,1,1,2,2,2,3,3,3]) glmnetcv(X, y, nfolds = 3) # Make sure show works -show(IOBuffer(), cv) -show(IOBuffer(), cv.path) +@test repr("text/plain", cv) == """ +Least Squares GLMNet Cross Validation +69 models for 6 predictors in 3 folds +Best λ 4.111 (mean loss 121.760, std 16.875)""" +@test repr("text/plain", cv.path) == """ +Least Squares GLMNet Solution Path (69 solutions for 6 predictors in 330 passes): +────────────────────────────── + df pct_dev λ +────────────────────────────── + [1] 0 0.0 31.8289 + [2] 1 0.161141 29.0013 + [3] 1 0.294923 26.4249 + [4] 1 0.405991 24.0774 + [5] 1 0.498201 21.9384 + [6] 1 0.574756 19.9895 + [7] 1 0.638313 18.2137 + [8] 1 0.69108 16.5956 + [9] 1 0.734887 15.1213 +[10] 1 0.771257 13.778 +[11] 1 0.801452 12.554 +[12] 1 0.82652 11.4387 +[13] 1 0.847332 10.4225 +[14] 1 0.864611 9.49663 +[15] 1 0.878956 8.65297 +[16] 1 0.890865 7.88427 +[17] 1 0.900753 7.18385 +[18] 1 0.908961 6.54566 +[19] 1 0.915776 5.96416 +[20] 1 0.921434 5.43432 +[21] 1 0.926132 4.95155 +[22] 1 0.930031 4.51167 +[23] 1 0.933269 4.11086 +[24] 1 0.935957 3.74566 +[25] 2 0.939866 3.41291 +[26] 2 0.945705 3.10972 +[27] 2 0.950551 2.83346 +[28] 2 0.954574 2.58174 +[29] 2 0.957915 2.35239 +[30] 2 0.960688 2.14341 +[31] 2 0.96299 1.95299 +[32] 4 0.966326 1.77949 +[33] 4 0.970479 1.62141 +[34] 5 0.974063 1.47737 +[35] 5 0.977328 1.34612 +[36] 5 0.980032 1.22654 +[37] 5 0.982277 1.11757 +[38] 5 0.984142 1.01829 +[39] 5 0.985689 0.92783 +[40] 5 0.986968 0.845404 +[41] 5 0.988036 0.770301 +[42] 5 0.988922 0.701869 +[43] 6 0.989839 0.639517 +[44] 6 0.990751 0.582704 +[45] 6 0.991518 0.530938 +[46] 6 0.992154 0.483771 +[47] 6 0.992683 0.440794 +[48] 6 0.993116 0.401635 +[49] 6 0.993481 0.365955 +[50] 6 0.993785 0.333445 +[51] 6 0.994037 0.303822 +[52] 6 0.994242 0.276832 +[53] 6 0.994415 0.252239 +[54] 6 0.99456 0.229831 +[55] 6 0.99468 0.209413 +[56] 6 0.994777 0.190809 +[57] 6 0.99486 0.173858 +[58] 6 0.994929 0.158413 +[59] 6 0.994987 0.14434 +[60] 6 0.995035 0.131517 +[61] 6 0.995072 0.119834 +[62] 6 0.995105 0.109188 +[63] 6 0.995133 0.0994882 +[64] 6 0.995156 0.0906499 +[65] 6 0.995175 0.0825968 +[66] 6 0.995191 0.0752591 +[67] 6 0.995204 0.0685733 +[68] 6 0.995215 0.0624815 +[69] 6 0.995224 0.0569308 +──────────────────────────────""" show(IOBuffer(), cv.path.betas) # this catches the showarray issue # Passing RNG makes cv deterministic