Here's a possible implementation of the mse_vs_m
function in MATLAB:
main.m1053 chars35 lines
The function takes four input arguments:
x_tr
is a column vector with the input values for the training sett_tr
is a column vector with the target values for the training setx_te
is a column vector with the input values for the testing sett_te
is a column vector with the target values for the testing setIt returns a struct with two fields:
mse_train
is a column vector with the MSE values for the training set, as a function of the model complexity (polynomial degree)mse_test
is a column vector with the MSE values for the testing set, as a function of the model complexityThe function uses polynomial regression to fit models of increasing complexity to the training set, and evaluates their performance on both the training and testing sets using the MSE metric. The results are stored in the output struct, which you can plot or analyze further as needed.
gistlibby LogSnag