Normal Equation Algorithm求解多元线性回归的Octave仿真
Normal Equation算法及其简洁,仅需一步即可计算出theta的取值,实现如下:
function [theta] = normalEqn(X, y) theta = zeros(size(X, 2), 1); theta = inv(X'*X)*X'*y; end
和梯度下降算法一样,我们预估1650square feet&3 bedrooms的房价:
x_e=[1650,3]; x_e=[ones(size(x_e),1) x_e]; price = x_e*theta;
outputs: