|
66 | 66 | LearnAPI.functions(algorithm)</code></pre><pre class="documenter-example-output"><code class="nohighlight hljs ansi">(LearnAPI.fit, LearnAPI.obsfit, LearnAPI.minimize, LearnAPI.predict, LearnAPI.obspredict, LearnAPI.obs, LearnAPI.algorithm, LearnAPI.coefficients)</code></pre><h3 id="Naive-user-workflow"><a class="docs-heading-anchor" href="#Naive-user-workflow">Naive user workflow</a><a id="Naive-user-workflow-1"></a><a class="docs-heading-anchor-permalink" href="#Naive-user-workflow" title="Permalink"></a></h3><p>Training and predicting with external resampling:</p><pre><code class="language-julia hljs">using Tables
|
67 | 67 | model = fit(algorithm, Tables.subset(X, train), y[train])
|
68 | 68 | ŷ = predict(model, LiteralTarget(), Tables.subset(X, test))</code></pre><pre class="documenter-example-output"><code class="nohighlight hljs ansi">4-element Vector{Float64}:
|
69 |
| - 1.3923271715113514 |
70 |
| - 0.9897274455080671 |
71 |
| - 1.0833712608796564 |
72 |
| - 2.284815067968779</code></pre><h3 id="Advanced-workflow"><a class="docs-heading-anchor" href="#Advanced-workflow">Advanced workflow</a><a id="Advanced-workflow-1"></a><a class="docs-heading-anchor-permalink" href="#Advanced-workflow" title="Permalink"></a></h3><p>We now train and predict using internal data representations, resampled using the generic MLUtils.jl interface.</p><pre><code class="language-julia hljs">import MLUtils |
| 69 | + 2.035030476492935 |
| 70 | + 3.1348335720184357 |
| 71 | + 1.1359846628809618 |
| 72 | + 2.8785342355493695</code></pre><h3 id="Advanced-workflow"><a class="docs-heading-anchor" href="#Advanced-workflow">Advanced workflow</a><a id="Advanced-workflow-1"></a><a class="docs-heading-anchor-permalink" href="#Advanced-workflow" title="Permalink"></a></h3><p>We now train and predict using internal data representations, resampled using the generic MLUtils.jl interface.</p><pre><code class="language-julia hljs">import MLUtils |
73 | 73 | fit_data = obs(fit, algorithm, X, y)
|
74 | 74 | predict_data = obs(predict, algorithm, X)
|
75 | 75 | model = obsfit(algorithm, MLUtils.getobs(fit_data, train))
|
76 | 76 | ẑ = obspredict(model, LiteralTarget(), MLUtils.getobs(predict_data, test))
|
77 |
| -@assert ẑ == ŷ</code></pre><pre class="documenter-example-output"><code class="nohighlight hljs ansi"><span class="sgr36"><span class="sgr1">[ Info: </span></span>Coefficients: [:a => 1.9764593532693593, :b => -0.44874600614288557, :c => 0.9467477933434958]</code></pre><h3 id="Applying-an-accessor-function-and-serialization"><a class="docs-heading-anchor" href="#Applying-an-accessor-function-and-serialization">Applying an accessor function and serialization</a><a id="Applying-an-accessor-function-and-serialization-1"></a><a class="docs-heading-anchor-permalink" href="#Applying-an-accessor-function-and-serialization" title="Permalink"></a></h3><p>Extracting coefficients:</p><pre><code class="language-julia hljs">LearnAPI.coefficients(model)</code></pre><pre class="documenter-example-output"><code class="nohighlight hljs ansi">3-element Vector{Pair{Symbol, Float64}}: |
78 |
| - :a => 1.9764593532693593 |
79 |
| - :b => -0.44874600614288557 |
80 |
| - :c => 0.9467477933434958</code></pre><p>Serialization/deserialization:</p><pre><code class="language-julia hljs">using Serialization |
| 77 | +@assert ẑ == ŷ</code></pre><pre class="documenter-example-output"><code class="nohighlight hljs ansi"><span class="sgr36"><span class="sgr1">[ Info: </span></span>Coefficients: [:a => 1.9054811886298182, :b => 0.3178672991278192, :c => 1.7868493089298811]</code></pre><h3 id="Applying-an-accessor-function-and-serialization"><a class="docs-heading-anchor" href="#Applying-an-accessor-function-and-serialization">Applying an accessor function and serialization</a><a id="Applying-an-accessor-function-and-serialization-1"></a><a class="docs-heading-anchor-permalink" href="#Applying-an-accessor-function-and-serialization" title="Permalink"></a></h3><p>Extracting coefficients:</p><pre><code class="language-julia hljs">LearnAPI.coefficients(model)</code></pre><pre class="documenter-example-output"><code class="nohighlight hljs ansi">3-element Vector{Pair{Symbol, Float64}}: |
| 78 | + :a => 1.9054811886298182 |
| 79 | + :b => 0.3178672991278192 |
| 80 | + :c => 1.7868493089298811</code></pre><p>Serialization/deserialization:</p><pre><code class="language-julia hljs">using Serialization |
81 | 81 | small_model = minimize(model)
|
82 | 82 | serialize("my_ridge.jls", small_model)
|
83 | 83 |
|
84 | 84 | recovered_model = deserialize("my_ridge.jls")
|
85 | 85 | @assert LearnAPI.algorithm(recovered_model) == algorithm
|
86 |
| -predict(recovered_model, LiteralTarget(), X) == predict(model, LiteralTarget(), X)</code></pre><hr/><p>¹ The definition of this and other structs above is not an explicit requirement of LearnAPI.jl, whose constructs are purely functional. </p><p>² An implementation can provide further accessor functions, if necessary, but like the native ones, they must be included in the <a href="../traits/#LearnAPI.functions"><code>LearnAPI.functions</code></a> declaration.</p></article><nav class="docs-footer"><a class="docs-footer-prevpage" href="../">« Home</a><a class="docs-footer-nextpage" href="../reference/">Reference »</a><div class="flexbox-break"></div><p class="footer-message">Powered by <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> and the <a href="https://julialang.org/">Julia Programming Language</a>.</p></nav></div><div class="modal" id="documenter-settings"><div class="modal-background"></div><div class="modal-card"><header class="modal-card-head"><p class="modal-card-title">Settings</p><button class="delete"></button></header><section class="modal-card-body"><p><label class="label">Theme</label><div class="select"><select id="documenter-themepicker"><option value="documenter-light">documenter-light</option><option value="documenter-dark">documenter-dark</option><option value="auto">Automatic (OS)</option></select></div></p><hr/><p>This document was generated with <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> version 1.2.1 on <span class="colophon-date" title="Wednesday 6 December 2023 21:23">Wednesday 6 December 2023</span>. Using Julia version 1.9.4.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html> |
| 86 | +predict(recovered_model, LiteralTarget(), X) == predict(model, LiteralTarget(), X)</code></pre><hr/><p>¹ The definition of this and other structs above is not an explicit requirement of LearnAPI.jl, whose constructs are purely functional. </p><p>² An implementation can provide further accessor functions, if necessary, but like the native ones, they must be included in the <a href="../traits/#LearnAPI.functions"><code>LearnAPI.functions</code></a> declaration.</p></article><nav class="docs-footer"><a class="docs-footer-prevpage" href="../">« Home</a><a class="docs-footer-nextpage" href="../reference/">Reference »</a><div class="flexbox-break"></div><p class="footer-message">Powered by <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> and the <a href="https://julialang.org/">Julia Programming Language</a>.</p></nav></div><div class="modal" id="documenter-settings"><div class="modal-background"></div><div class="modal-card"><header class="modal-card-head"><p class="modal-card-title">Settings</p><button class="delete"></button></header><section class="modal-card-body"><p><label class="label">Theme</label><div class="select"><select id="documenter-themepicker"><option value="auto">Automatic (OS)</option><option value="documenter-light">documenter-light</option><option value="documenter-dark">documenter-dark</option></select></div></p><hr/><p>This document was generated with <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> version 1.4.1 on <span class="colophon-date" title="Friday 10 May 2024 03:13">Friday 10 May 2024</span>. Using Julia version 1.10.3.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html> |
0 commit comments