0
0
SciPydata~10 mins

Polynomial fitting in SciPy - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the polynomial fitting function from numpy.

SciPy
from numpy import [1]
Drag options to blanks, or click blank then click option'
Apolyfit
Binterpolate
Cstats
Doptimize
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to import from scipy submodules like optimize or stats.
Using interpolate which is for interpolation, not fitting.
2fill in blank
medium

Complete the code to fit a polynomial of degree 2 to data points x and y.

SciPy
coefficients = [1](x, y, 2)
Drag options to blanks, or click blank then click option'
Acurve_fit
Bpolyfit
Cminimize
Dlinregress
Attempts:
3 left
💡 Hint
Common Mistakes
Using curve_fit which is for general curve fitting, not specifically polynomials.
Using linregress which fits only linear regression.
3fill in blank
hard

Fix the error in the code to evaluate the polynomial at points x_new using the coefficients. Assume polyval is imported from numpy.

SciPy
y_new = [1](coefficients, x_new)
Drag options to blanks, or click blank then click option'
Apolyval1d
Bpolyfit
Cpolyval2d
Dpolyval
Attempts:
3 left
💡 Hint
Common Mistakes
Using polyfit instead of polyval to evaluate values.
Using polyval2d which is for 2D polynomials.
4fill in blank
hard

Fill both blanks to create a dictionary of polynomial coefficients for degrees 1 and 3 from data x and y.

SciPy
coeffs = {1: [1](x, y, 1), 3: [2](x, y, 3)}
Drag options to blanks, or click blank then click option'
Apolyfit
Bcurve_fit
Dminimize
Attempts:
3 left
💡 Hint
Common Mistakes
Using different functions for each degree.
Using curve_fit which requires a function definition.
5fill in blank
hard

Fill all three blanks to create a dictionary of polynomial fits for degrees 1, 2, and 4, then evaluate degree 2 polynomial at x_new. Assume polyfit and polyval imported from numpy.

SciPy
coeffs = {1: [1](x, y, 1), 2: [2](x, y, 2), 4: [3](x, y, 4)}
y_new = polyval(coeffs[2], x_new)
Drag options to blanks, or click blank then click option'
Apolyfit
Dcurve_fit
Attempts:
3 left
💡 Hint
Common Mistakes
Using curve_fit for polynomial fitting.
Mixing different fitting functions.