Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #
- #BEGIN Regularization section
- #
- min_err, w_hat = Inf, Inf
- for lamb in vcat([2.0^x for x in -1:4],0)
- #find the best w_hat_lam
- w_hat_lam = (svd_X[:Vt]'*Diagonal(svd_X[:S])^2*svd_X[:Vt]+lamb*eye(size(X_train,2)) )^(-1)*svd_X[:Vt]'*Diagonal(svd_X[:S])*svd_X[:U]'*y_train
- #use this to predict error on the k holdout
- preds = sign.(X_test_k*w_hat_lam)
- error_lam = num_mistakes(y_test_k , preds)/16
- if error_lam < min_err
- min_err = error_lam
- w_hat = w_hat_lam
- end
- end
- preds_actual = sign.(X_test*w_hat)
- error_rate_sum_reg += num_mistakes(y_test , preds_actual)/16
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement