Answered step by step
Verified Expert Solution
Link Copied!

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 p=[p0,p1,p2... p6] to find a special set of 7 numbers that minimizes the MSE
* The parameterization will be our "best fit model"
* the numerical search process, i.e. numerical optimization, is called "training"
* The minimization search which finds the "optimal" parameter vector p=[p0,p1,p2... p6] can be done in two ways
***Analytical optimization**: i.e. manually do the optimization problem with pen and paper and a lot of calculus
***Numerical optimization:** Use a computer and a numerical optimization algorithm (e.g. the scipy miminizer). This is the option we will use
**ASSIGNMENT-7**
* 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 [-3 to 3].
* 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 [-3 to 3].
***YOU WILL LIKELY HAVE TO RUN THE CODE SEVERAL TIMES WITH DIFFERENT RANDOM INITIAL GUESSES BEFORE THE OPTIMIZER FINDS THE OPTIMAL FIT (i.e 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 = minimize(loss, p0, method='BFGS', tol=1e-5)
popt=res.x
```
* when the minimizer is done, it outputs the 7 parameters (i.e. numbers) that correspond to the "best fit" parameters. these are stored in "popt=res.x".
* To get predictions for this particular parameterization, you need to evaluate the model one last time ypred_opt=m(x_train, 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 0.00001) is included to avoid division by zero
```
print("MSE TRAIN:",np.mean((yp_train-y_train)**2.0))
print("MSE VALIDATION:",np.mean((yp_val-y_val)**2.0))
print("MEDIAN PERCENT ERROR TRAIN:",100*np.median(np.absolute((yp_train-y_train)/(y_train+0.00001))))

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

6. Explain the strengths of a dialectical approach.

Answered: 1 week ago