Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %Remember to load X and y before running
- %init XX,yy
- XX = X;
- yy = y;
- m = size(XX,1);
- n = size(XX,2);
- %Make it a sqrt function
- XX(:,1) = sqrt(XX(:,1));
- %Normalize X
- %[XX, mu, sigma] = normalize(XX);
- %Add bias term
- XX = [ones(m, 1), XX];
- %Linear regression
- lambda = 0;
- costFunction = @(t) costGrad(XX,yy,t,lambda);
- options = optimset('MaxIter', 2000, 'GradObj', 'on');
- initial_theta = zeros(n+1,1);
- [theta, J] = fminunc(costFunction, initial_theta, options);
- theta
- %Display the entire surface equation in an easily copy pastable form
- %no sqrt
- %disp([num2str(theta(1)), " + ", num2str(theta(2)), " * x + ", num2str(theta(3)), " * y"]);
- %sqrt(x)
- disp([num2str(theta(1)), " + ", num2str(theta(2)), " * sqrt(x) + ", num2str(theta(3)), " * y"]);
- %normalization
- %disp([num2str(theta(1)), " + ", num2str(theta(2)), " * (x-", num2str(mu(1)), ")/", num2str(sigma(1)) ," + ", num2str(theta(3)), " * (y-", num2str(mu(2)), ")/", num2str(sigma(2))]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement