Improve the solution of Example 28.2.1 by using weights to compensate for data transformation. Compare the results to the previous ones.
Solution.
We continue the code from Example 28.2.1 by adding the following lines.
w = y.*(1-y); % weights
beta = (X.*w)\(yt.*w); % weighted least squares solution
f = @(x) 1 ./ (1 + exp(-(x.^(0:1))*beta));
figure();
plot(t, f(t), 'b', x, y, 'r*')
title('Weighted Least Squares')
The first two lines compute new parameters \(\beta_1, \beta_2\) for logistic function \(1/(1+\exp(-\beta_1 - \beta_2 x))\text{,}\) using weights. The rest proceeds as before. The plot is shown on a new figure.
