Freezable

Freezable(model; frozen=true, cache=true)

Wrap model so fit! is a no-op after the first training pass. Place the wrapper inside a Pipeline, Stack, TunedModel, or any other NetworkComposite model, and the inner component skips retraining even when the parent rebuilds its learning network on a row change.

Set frozen=false to allow normal retraining. Use freeze! and thaw! to toggle after construction. Set cache=false to prioritize memory over speed.

Example 1: Freezing a single model

This example and the next assume you have MLJDecisionTreeInterface in your environment.

using MLJ    ## or `using MLJBase, MLJModels`

X, y = make_regression(100)
DecisionTreeRegressor = @load DecisionTreeRegressor pkg=DecisionTree

model = Freezable(DecisionTreeRegressor())  ## frozen=true by default
mach  = machine(model, X, y)

fit!(mach)                    ## first fit trains
fit!(mach, rows=1:50)         ## no-op while frozen
thaw!(model)
fit!(mach, rows=1:50)         ## retrains

Example 2: Freezing a component inside a pipeline

using MLJ    ## or `using MLJBase, MLJModels, MLJTransforms`

X, y = make_blobs(200)
DecisionTreeClassifier = @load DecisionTreeClassifier pkg=DecisionTree

pipe = Pipeline(
    scaler = Freezable(Standardizer()),
    clf    = DecisionTreeClassifier(),
)
mach = machine(pipe, X, y)
fit!(mach, rows=1:100)        ## both components train
fit!(mach, rows=101:200)      ## only clf retrains; scaler is frozen