Skip to contents

Ridge leaves the intercept unpenalised. The returned predict closure is frozen: new data needs a full retrain, which is what "offline" means.

Usage

morie_geron_batch_learning(X, y, fit_intercept = FALSE, ridge = 0)

Arguments

X

Design matrix.

y

Targets.

fit_intercept

Prepend a ones column.

ridge

Non-negative L2 penalty.

Value

List with theta, predict, fitted, residuals, train_mse, r2.

Examples

V <- c(1, 2, 3, 4, 5, 6, 7, 8)
morie_geron_batch_learning(V, V)
#> $theta
#> [1] 1
#> 
#> $predict
#> function (Xnew) 
#> {
#>     A <- if (is.matrix(Xnew)) 
#>         Xnew
#>     else matrix(as.numeric(Xnew), nrow = 1)
#>     storage.mode(A) <- "double"
#>     .morie_gr_need(ncol(A) == nfeat, "predict: feature count mismatch")
#>     if (fit_intercept) 
#>         A <- cbind(1, A)
#>     as.numeric(A %*% theta)
#> }
#> <environment: 0x56217ab6ba98>
#> 
#> $fitted
#> [1] 1 2 3 4 5 6 7 8
#> 
#> $residuals
#> [1] 0 0 0 0 0 0 0 0
#> 
#> $train_mse
#> [1] 0
#> 
#> $r2
#> [1] 1
#> 
#> $estimate
#> [1] 0
#> 
#> $n
#> [1] 8
#> 
#> $method
#> [1] "Batch learning: closed-form minimisation of the full-dataset squared-error loss"
#>