
Linear-regression MSE cost and gradient (Geron Ch 4, morie.fn hmmsec)
Source:R/geron_ml2_native.R
morie_geron_linreg_mse_cost.RdIf theta is one longer than the columns of X, a leading column
of ones is prepended, matching the Python implicit-bias rule.
Examples
morie_geron_linreg_mse_cost(X = c(1, 2, 3, 4, 5, 6, 7, 8), y = c(1, 2, 3, 4, 5, 6, 7, 8),
theta = 0.5)
#> $cost
#> [1] 6.375
#>
#> $mse
#> [1] 6.375
#>
#> $gradient
#> [1] -25.5
#>
#> $grad_norm
#> [1] 25.5
#>
#> $residuals
#> [1] -0.5 -1.0 -1.5 -2.0 -2.5 -3.0 -3.5 -4.0
#>
#> $predictions
#> [1] 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0
#>
#> $estimate
#> [1] 6.375
#>
#> $n
#> [1] 8
#>
#> $method
#> [1] "MSE cost and analytic gradient for linear regression"
#>