Question: Our last component is the model itself! ???? Create function named model that takes as arguments matrix x (our independent variables) and a vector p
Our last component is the model itself! ???? Create function named model that takes as arguments matrix x (our independent variables) and a vector p (the parameters we want to optimize, with the length of p being the number of columns in x + 1) and returns the result of y = x*p1 + p2 . This type of model is called "multiple linear regression", where p2 is the last item in our p vector, representing our model intercept, and p1 is every item in our vector p except for the last item, representing the slope of our model with respect to each independent variable.
model (generic function with 1 method) . function model(x: : AbstractMatrix, p: : AbstractVector) length(p) == size(x, 2) + 1 . p1 = view(p, 1: length(p)-1) # slope coefficients p2 = p[end] # intercept return x * p1 . + p2 # ) = xxp1 + p2 endStep by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
