Answered step by step
Verified Expert Solution
Question
1 Approved Answer
2 Fitting a Linear Model Problem 2 : Write the following functions. A function that takes as input a data tensor x and vector of
Fitting a Linear Model
Problem : Write the following functions.
A function that takes as input a data tensor and vector of weights and returns a tensor of predictions based on a linear model, for each data point.
A loss function that takes as input a tensor of actual values, and a vector of predicted values, and returns as a result of tensor operations the average squared error between them. Average in this case being over the number of data points in the tensors.
A function that may be useful: torch.matmul.
Problem : Given a training data set and a testing data set and a stepsize write code that calculates a linear model of best fit on the training data using a stepsize of Keep track of the loss on the training set and the loss on the testing set over the course of training, to plot at the end of training. What condition should you put to end your training loop?
Problem : For a training set of size and a test set of size consider fitting a linear model at various stepsizes
What range of lead to convergence, what don't? How can you tell that an is too large?
For an with convergence, plot the loss on the training data and the loss on the testing data as a function of training time. How do the training and testing error compare over time? Is the model learning?
For a good trained to convergence does the resulting model generalize to the testing data well?
How does the fit model compare to the 'actual' model?
Bonus: Show that there are multiple models that produce the same output, and therefore there is no 'best' model. Does this contradict there being a 'true' formula, as indicated above?
Problem : In this problem, we want to look at the effect of the amount of data. For consider training a model on training sets of these sizes keeping the test set fixed at size Plot the training and testing loss for each experiment over the course of training. Analyze and describe your results.
Bonus: How does the optimal seem to depend on the number of training data points? Be thorough.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started