main.m351 chars14 lines
This function will take in four inputs: x_tr
and t_tr
represent the training input and target data, respectively, and x_te
and t_te
represent the testing input and target data, respectively.
The m_values
variable is defined as a range of values from 1 to the number of rows (size
) of the training input data x_tr
, which represents the total number of basis functions that can be involved in regression.
A for loop is used to iterate over each possible value of m
. At each iteration, the function trains a model using m
basis functions (through the train
function which is not shown in this code) on the training set, and computes the mean squared error (MSE) of the test set by taking the difference between the test set output and the actual target, squaring the differences and taking the mean. These values are stored in mse
array for each m
value.
Lastly, the function plots the MSE values versus the number of basis functions, and returns the resulting mse
array.
gistlibby LogSnag