Answered step by step
Verified Expert Solution
Question
1 Approved Answer
### Train your model * The following was mentioned above, however, it is important and is worth repeating * The goal of curve fitting is
### Train your model
The following was mentioned above, however, it is important and is worth repeating
The goal of curve fitting is to systematically search through the parameter space pppp p to find a special set of numbers that minimizes the MSE
The parameterization will be our "best fit model"
the numerical search process, ie numerical optimization, is called "training"
The minimization search which finds the "optimal" parameter vector pppp p can be done in two ways
Analytical optimization: ie manually do the optimization problem with pen and paper and a lot of calculus
Numerical optimization: Use a computer and a numerical optimization algorithm eg the scipy miminizer This is the option we will use
ASSIGNMENT
Choose an initial guess for the parameter vector p
When you are fitting the normalized data, most of the x and y data values should be roughly in the range to
As discussed in the lecture, the parameters are associated with the stretches and shifts along either the x or y directions.
Therefore the parameters values when fitting the normalized data should also be roughly on the order of to
YOU WILL LIKELY HAVE TO RUN THE CODE SEVERAL TIMES WITH DIFFERENT RANDOM INITIAL GUESSES BEFORE THE OPTIMIZER FINDS THE OPTIMAL FIT ie GLOBAL MINIMA
Just keep doing "Run All" until you get a fit where both peaks are fit by the model
Use the Scipy minimizer to minimize the loss function, by varying the components of the parameter vector p to find the best fit parameters for the model
res minimizeloss p methodBFGS tole
poptres.x
when the minimizer is done, it outputs the parameters ie numbers that correspond to the "best fit" parameters. these are stored in "poptres.x
To get predictions for this particular parameterization, you need to evaluate the model one last time ypredoptmxtrain, popt
Make predictions with the fitted model for the test and validation data
Print the MSE and median percent error for the training AND validation sets the is included to avoid division by zero
printMSE TRAIN:",npmeanyptrainytrain
printMSE VALIDATION:",npmeanypvalyval
printMEDIAN PERCENT ERROR TRAIN:",npmediannpabsoluteyptrainytrainytrain
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