Exercise 4
Exercise 4
Write-up:
In this problem, we are given 2 different sets of data. We used the data in NHMC as the values of x,
while we used the C6H6 as the values of y. The two variables may not be a perfect fit since R^2 is not
exactly 1, but it is still correlated to each other seeing how close it is to
1.
Final Answer: R^2: 0.98420. The two variables may not be a perfect fit since R^2 is not
exactly 1, but it is still strongly correlated to each other because it is close to 1.
Best-Fit Line
Script / Code:
x = [11 18 84 260 200 145 188 152 103 193]'; % Given datas of NMHC
y = [1.6 1.9 7.5 21.4 15.4 12.5 15.1 13.7 10.4 15.2]'; % Given datas of 𝐶6𝐻6
scatter(x,y,'b','filled','MarkerEdgeColor','k');
% Display results
a = W(1); b = -W(2);
% Calculate R2
yp = a*x./(1+b*x);
R2 = 1 - sum((y-yp).^2)/sum((y-mean(y)).^2);
fprintf('R^2: %.5f\n',R2);
PROBLEM 2
a)
Write-up:
We used the Ridge Regularization approach to solve this problem in order to discover the solution.to the
issue at hand. The years 1959 through 2019 are entered first as x, and the value of the amount of CO2
that exists annually. It is assumed that a third-degree polynomial and a 0.01 as the regularization value
Using the provided code, it is anticipated that, in accordance with the plot, Mauna Loa, Hawaii's annual
CO2 concentration is expected to be 437.784 in 2030.
Final Answer: R^2: 0.99939. In 2030, the expected annual CO2 concentration (in ppm) is around
437.784
Best-Fit Curve
Script / Code:
y = [315.98 316.91 317.64 318.45 318.99 319.62 320.04 321.37 322.18 323.05 324.62 325.68 326.32
327.46 329.68 330.18 331.12 332.04 333.83 335.40 336.84 338.75 340.11 341.45 343.05 344.66
346.12 347.43 349.18 351.57 353.12 354.39 355.61 356.45 357.10 358.83 360.82 362.61 363.73
366.70 368.38 369.55 371.14 373.28 375.80 377.52 379.80 381.90 383.79 385.59 387.43 389.90
391.65 393.86 396.52 398.64 400.83 404.22 406.55 408.52 411.43]'; % annual mean atmospheric
axis([1958 2030 315 412]); grid on; box on; % Customize the plot
for j = 1:length(reg)
% Display results
fprintf('\ny = %.3f\n',W(1));
for k = 2:length(W)
end
% Calculate R2
yp = polyval(flip(W),x);
R2 = 1 - sum((y-yp).^2)/sum((y-mean(y)).^2);
fprintf('R^2: %.5f\n',R2);
end
b)
Write-up:
For this problem, we are given the data on annual CO2 concentration from 1959 to 2019. It is
also given that we need to use a 5th-degree polynomial and a suitable regularization for this
model. With all the given data, we are expected to forecast the CO2 concentration in the year
2022 in Mauna Lao, Hawaii. We used ridge regularization and the provided code to solve this
problem, and the regularization that we used is 0.01. Based from the plot, it is expected that
Final Answer: R^2: 0.99941. Using a 0.01 regularization, the expected annual CO2 concentration
(in ppm) is around 439.216. The A model has lower MSE than the B model.
Best-Fit Curve
Script Code:
y = [315.98 316.91 317.64 318.45 318.99 319.62 320.04 321.37 322.18 323.05 324.62 325.68 326.32
327.46 329.68 330.18 331.12 332.04 333.83 335.40 336.84 338.75 340.11 341.45 343.05 344.66
346.12 347.43 349.18 351.57 353.12 354.39 355.61 356.45 357.10 358.83 360.82 362.61 363.73
366.70 368.38 369.55 371.14 373.28 375.80 377.52 379.80 381.90 383.79 385.59 387.43 389.90
391.65 393.86 396.52 398.64 400.83 404.22 406.55 408.52 411.43]'; % annual mean atmospheric
axis([1958 2030 315 412]); grid on; box on; % Customize the plot
% Display results
fprintf('\ny = %.3f\n',W(1));
for k = 2:length(W)
end
% Calculate R2
yp = polyval(flip(W),x);
R2 = 1 - sum((y-yp).^2)/sum((y-mean(y)).^2);
fprintf('R^2: %.5f\n',R2);
end