Complete the code to fit a linear regression model using the fitlm function.
mdl = fitlm(X, [1]);Complete the code to predict new values using the trained model.
y_pred = predict([1], X_new);Fix the error in the code to extract the R-squared value from the model.
R2 = mdl.[1];Fill both blanks to create a scatter plot of data and overlay the regression line.
scatter(X, y); hold on; plot(X, mdl.[1](2) * X + mdl.[2](1)); hold off;
Fill all three blanks to compute residuals and plot them.
residuals = y - predict([1], [2]); figure; plot([3], residuals, 'o'); xlabel('Predictor'); ylabel('Residuals');
