Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- y = degree_reg(V, b1f);
- k = build_plot_disp_loss(V, b1f, y);
- function y=lin_reg(V, bf)
- a = [sum(V) length(V);
- sum(V.^2) sum(V)];
- b = [sum(bf) sum(V .* bf)]';
- x = a\b;
- a = x(1);
- b = x(2);
- y = a * V + b;
- end
- function y = square_reg(V, bf)
- a = [sum(V.^2) sum(V) length(V);
- sum(V.^3) sum(V.^2) sum(V);
- sum(V.^4) sum(V.^3) sum(V.^2)];
- b = [sum(bf) sum(V .* bf) sum(V.^2 .* bf)]';
- x = a\b;
- a = x(1);
- b = x(2);
- c = x(3);
- y = a * V.^2 + b * V + c;
- end
- function y = degree_reg(V, bf)
- a = [length(V) sum(log(V));
- sum(log(V)) sum(log(V).^2)];
- b = [sum(log(bf)) sum(log(bf).*log(V))]';
- x = a\b;
- a = exp(x(1));
- b = x(2);
- y = a * V.^b;
- end
- function y = loss_fn(bf, res)
- y = 1/length(bf) * sum(abs((bf - res)./bf));
- end
- function loss = build_plot_disp_loss(V, bf, res)
- loss = loss_fn(bf, res);
- disp("loss is: " + loss * 100 + "%");
- figure('Color', 'w');
- plot(V, bf, 'r');
- hold on;
- plot(V, res, 'b');
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement