Skip to contents

Subgradient update: violated margin (y_i f(x_i) < 1) -> w -= lr*(alpha*w - y_i x_i), b += lr*y_i; satisfied -> w -= lr*alpha*w. Sample order drawn from a deterministic LCG Fisher-Yates shuffle.

Usage

morie_geron_sgd_classifier(
  X,
  y,
  lr = 0.1,
  n_iter = 10,
  alpha = 1e-04,
  seed = 0,
  shuffle = TRUE
)

Arguments

X

Design matrix (n, d).

y

Binary labels (2 distinct values).

lr, n_iter, alpha, seed, shuffle

As in the Python original.

Value

list with w, b, loss_curve, decision, predicted, accuracy, n_support, classes, estimate, n, method.

Examples

V <- c(1, 2, 3, 4, 5, 6, 7, 8)
morie_geron_sgd_classifier(V, V)
#> $w
#> [1] 0.2000889
#> 
#> $b
#> [1] -1.2
#> 
#> $loss_curve
#>  [1] 1.4000685 0.5124858 0.7999670 0.5124433 0.6249250 0.3374235 0.3499135
#>  [8] 0.3624145 0.9628053 0.6002244
#> 
#> $decision
#> [1] -0.9999110511 -0.7998221021 -0.5997331532 -0.3996442043 -0.1995552553
#> [6]  0.0005336936  0.2006226425  0.4007115915
#> 
#> $predicted
#> [1] -1 -1 -1 -1 -1  1  1  1
#> 
#> $accuracy
#> [1] 0.75
#> 
#> $n_support
#> [1] 8
#> 
#> $classes
#> [1] 1 2 3 4 5 6 7 8
#> 
#> $estimate
#> [1] 0.6002244
#> 
#> $n
#> [1] 8
#> 
#> $method
#> [1] "Hinge-loss linear SVM trained by stochastic subgradient descent with L2 decay"
#>