Skip to content

Commit a089615

Browse files
committed
remove target transform demo from pluto tute 03, as incorrect
1 parent 3b63b66 commit a089615

File tree

1 file changed

+17
-85
lines changed

1 file changed

+17
-85
lines changed

notebooks/03_pipelines/notebook.pluto.jl

Lines changed: 17 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ instantiate properly for other Julia versions.
110110

111111
# ╔═╡ 99cbb473-2785-48ad-bcba-9840c8a65923
112112
md"""
113-
The follwing is a temporary fix until the macro-free pipline mechanism will be included in an offical release of MLJ (then the cell above can be used):
113+
The follwing is a temporary fix until the macro-free pipeline mechanism will be included in an offical release of MLJ (then the cell above can be used):
114114
"""
115115

116116
# ╔═╡ 499cbc31-83ba-4583-ba1f-6363f43ec697
@@ -281,12 +281,19 @@ transformation to `XHouseCont`, we can combine both the encoding and the
281281
dimension-reducing models into a single model, known as a
282282
*pipeline*. While MLJ offers a powerful interface for composing
283283
models in a variety of ways, we'll stick to these simplest class of
284-
composite models for now. The easiest way to construct them is using
285-
the `Pipeline` type:
284+
composite models for now. The simplest "hard-wired" composite type is the `Pipeline` type, which is for linear (non-branching) sequences of models. At most one of these can be a supervised model (which often appears last):
286285
"""
287286

288287
# ╔═╡ 5ed77309-afa6-4c94-88c0-761fe6b5a5d4
289-
pipe1 = Pipeline(ContinuousEncoder, PCA)
288+
pipe0 = Pipeline(ContinuousEncoder, PCA)
289+
290+
# ╔═╡ d45ff6ec-2dd6-4a9c-a97e-79337b0be5c8
291+
md"""
292+
Notice that component models now appear as *hyper-parameters* of the pipeline model, and these have automatically generated field names (which can be overwritten, as in `Pipeline(enc=ContinuousEncoder, reducer=PCA)`). There is also an "arrow" syntax for constructing pipelines. The following defines the same pipeline as above:
293+
"""
294+
295+
# ╔═╡ 380a3bb6-535d-4f4b-8e7c-18148f7cc0b8
296+
pipe1 = ContinuousEncoder |> PCA
290297

291298
# ╔═╡ eee1bcc8-ff0b-4238-950d-551d88aab415
292299
md"""
@@ -317,7 +324,7 @@ md"Want to combine this pre-processing with ridge regression?"
317324
RidgeRegressor = @load RidgeRegressor pkg=MLJLinearModels
318325

319326
# ╔═╡ f96a84ec-1cc0-400c-9493-9c2a2e3c5b51
320-
pipe2 = Pipeline(ContinuousEncoder, PCA, RidgeRegressor)
327+
pipe2 = pipe1 |> RidgeRegressor
321328

322329
# ╔═╡ e9a2070b-41b5-41bd-9994-5929469b8436
323330
md"""
@@ -396,84 +403,17 @@ md"## Incorporating target transformations"
396403

397404
# ╔═╡ 667917e3-25d2-435c-bb0e-3a45761c733a
398405
md"""
399-
Next, suppose that instead of using the raw `:price` as the
400-
training target, we want to use the log-price (a common practice in
401-
dealing with house price data). However, suppose that we still want
402-
to report final *predictions* on the original linear scale (and use
403-
these for evaluation purposes). Then we supply appropriate functions
404-
to key-word arguments `target` and `inverse`.
405-
"""
406+
Target transformations are not supported by the `Pipeline` type, only the `@pipeline` macro, which does not currently work from Pluto notebooks. Refer to the Juptyer notebook or plain julia script for a demonstration. Target transformations can also be implemented using MLJ's generic model composition syntax introduced in Part 5.
406407
407-
# ╔═╡ 72d314eb-74ef-4555-9979-7044b2f2df33
408-
md"First we'll overload `log` and `exp` for broadcasting:"
409-
410-
# ╔═╡ bc2bdda0-8fe3-4ef0-b2a1-fbbde543f620
411-
begin
412-
Base.log(v::AbstractArray) = log.(v)
413-
Base.exp(v::AbstractArray) = exp.(v)
414-
end
408+
In the future you will be able to conveniently implement target transformations with a separate model wrapper.
409+
"""
415410

416411
# ╔═╡ 0398adfe-721a-4b97-910b-f8a9a217eff2
417412
md"Now for the new pipeline:"
418413

419-
# ╔═╡ 9d044fe7-b62e-4b51-bb69-47ebf84b4ea4
420-
pipe3 = Pipeline(encoder = ContinuousEncoder, reducer = PCA, rgs = RidgeRegressor, target = log, inverse = exp)
421-
422-
# ╔═╡ 89251d28-6c54-4b2f-829e-9cefd6f19d95
423-
md"""
424-
!!! note
425-
426-
In the former macro-based version this was
427-
428-
`pipe3 = @pipeline encoder reducer rgs target=log inverse=exp`
429-
"""
430-
431-
# ╔═╡ e183ea7a-172f-49c2-a47e-30edcce038f2
432-
mach5 = machine(pipe3, XHouse, yHouse)
433-
434-
# ╔═╡ df510e0a-ef23-4858-83f0-b50c129e6ef8
435-
evaluate!(mach5, measure = mae)
436-
437-
# ╔═╡ e98fef59-a5cb-4c24-88a1-a2bf91434413
438-
md"""
439-
MLJ will also allow you to insert *learned* target
440-
transformations. For example, we might want to apply
441-
`Standardizer()` to the target, to standardize it, or
442-
`UnivariateBoxCoxTransformer()` to make it look Gaussian. Then
443-
instead of specifying a *function* for `target`, we specify a
444-
unsupervised *model* (or model type). One does not specify `inverse`
445-
because only models implementing `inverse_transform` are
446-
allowed.
447-
"""
448-
449414
# ╔═╡ 4fd0807d-61e5-4b4b-a1cb-54e34396a855
450415
md"Let's see which of these two options results in a better outcome:"
451416

452-
# ╔═╡ 271f5dae-38ad-4e5b-8037-0de5806e1a54
453-
begin
454-
box = UnivariateBoxCoxTransformer(n=20)
455-
stand = Standardizer()
456-
pipe4 = Pipeline(encoder = ContinuousEncoder, reducer = PCA,
457-
rgs = RidgeRegressor, target = box)
458-
mach6 = machine(pipe4, XHouse, yHouse)
459-
evaluate!(mach6, measure=mae)
460-
end
461-
462-
# ╔═╡ 60177e97-7b28-487a-8264-9ba66dede674
463-
md"""
464-
!!! note
465-
466-
In the former macro-based version this was
467-
468-
`pipe4 = @pipeline encoder reducer rgs target=box`
469-
"""
470-
471-
# ╔═╡ 3d8a2959-63c5-4bee-9961-a09632c33fb0
472-
begin
473-
pipe4.target = stand
474-
evaluate!(mach6, measure=mae)
475-
end
476-
477417
# ╔═╡ a0488295-9642-4156-b7cc-46f4ef988c68
478418
md"# Resources for Part 3"
479419

@@ -597,6 +537,8 @@ md"""
597537
# ╠═1e780939-abf0-4203-97a7-88e3af4f10ee
598538
# ╟─8e76b5a5-7c80-4684-b372-8c9866e51852
599539
# ╠═5ed77309-afa6-4c94-88c0-761fe6b5a5d4
540+
# ╟─d45ff6ec-2dd6-4a9c-a97e-79337b0be5c8
541+
# ╠═380a3bb6-535d-4f4b-8e7c-18148f7cc0b8
600542
# ╟─eee1bcc8-ff0b-4238-950d-551d88aab415
601543
# ╟─e68044d8-42b4-49cd-86cf-35420d9e6995
602544
# ╠═26d649a8-3d96-4479-a29a-8d0445351914
@@ -620,18 +562,8 @@ md"""
620562
# ╠═92c5bc62-b430-41b8-8378-5aa686f0b407
621563
# ╟─adcb0506-e89d-43b0-9f43-49763e8691a1
622564
# ╟─667917e3-25d2-435c-bb0e-3a45761c733a
623-
# ╟─72d314eb-74ef-4555-9979-7044b2f2df33
624-
# ╠═bc2bdda0-8fe3-4ef0-b2a1-fbbde543f620
625565
# ╟─0398adfe-721a-4b97-910b-f8a9a217eff2
626-
# ╠═9d044fe7-b62e-4b51-bb69-47ebf84b4ea4
627-
# ╟─89251d28-6c54-4b2f-829e-9cefd6f19d95
628-
# ╠═e183ea7a-172f-49c2-a47e-30edcce038f2
629-
# ╠═df510e0a-ef23-4858-83f0-b50c129e6ef8
630-
# ╟─e98fef59-a5cb-4c24-88a1-a2bf91434413
631566
# ╟─4fd0807d-61e5-4b4b-a1cb-54e34396a855
632-
# ╠═271f5dae-38ad-4e5b-8037-0de5806e1a54
633-
# ╟─60177e97-7b28-487a-8264-9ba66dede674
634-
# ╠═3d8a2959-63c5-4bee-9961-a09632c33fb0
635567
# ╟─a0488295-9642-4156-b7cc-46f4ef988c68
636568
# ╟─d59d9e91-b26d-4342-90fb-7f2721f6fcc7
637569
# ╟─c4f30527-c9b4-44e9-af65-ccd25ecb9818

0 commit comments

Comments
 (0)