Model Components
Previously, you have been given a pre-defined model to work with. In this exercise, you will implement a model function that returns model values for y, computed from input x data, and any input coefficients for the "zero-th" order term a0, the "first-order" term a1, and a quadratic term a2 of a model (see below).
\(y = a_0 + a_1 x + a_2 x^2\)
Recall that "first order" is linear, so we'll set the defaults for this general linear model with a2=0, but later, we will change this for comparison.
Cet exercice fait partie du cours
Introduction to Linear Modeling in Python
Instructions
- Complete the function definition
model()so it takesx, and default inputsa0=3, a1=2, a2=0as input, and returnsy. - Create an array of values
xusing thenumpymethodnp.linspace(). - Pass
xinto yourmodel()without specifyinga0, a1, a2, to get default predictedyvalues. - Use the pre-defined
plot_prediction()to see a plot of the resulting dataxandy.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
# Define the general model as a function
def model(x, a0=____, a1=____, a2=____):
return a0 + (a1*____) + (a2*____*____)
# Generate array x, then predict y values for specific, non-default a0 and a1
x = np.____(-10, 10, 21)
y = model(____)
# Plot the results, y versus x
fig = plot_prediction(____, ____)