0
0
SciPydata~10 mins

Non-linear curve 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 curve fitting function from scipy.

SciPy
from scipy.optimize import [1]
Drag options to blanks, or click blank then click option'
Acurve_fit
Bminimize
Clinregress
Droot
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'minimize' which is for optimization but not specifically curve fitting.
Using 'linregress' which is for linear regression, not non-linear fitting.
2fill in blank
medium

Complete the code to define a model function for fitting a quadratic curve.

SciPy
def model(x, a, b, c):
    return a * x[1]2 + b * x + c
Drag options to blanks, or click blank then click option'
A//
B**
C*
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using '*' which multiplies but does not square.
Using '+' which adds instead of exponentiation.
3fill in blank
hard

Fix the error in the code to call curve_fit correctly with the model and data arrays x_data and y_data.

SciPy
params, covariance = curve_fit([1], x_data, y_data)
Drag options to blanks, or click blank then click option'
Amodel()
Bcurve_fit
Cmodel
Dx_data
Attempts:
3 left
💡 Hint
Common Mistakes
Calling the model function immediately with parentheses.
Passing the wrong variable like 'curve_fit' or 'x_data' instead of the model.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps each word to its length if the length is greater than 3.

SciPy
{word: [1] for word in words if [2]
Drag options to blanks, or click blank then click option'
Alen(word)
Bword
Clen(word) > 3
Dword > 3
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself instead of its length as the dictionary value.
Comparing the word string directly to 3, which is invalid.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps each key uppercased to its value if the value is positive.

SciPy
{ [1]: [2] for k, v in data.items() if [3] }
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
Cv > 0
Dk.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using k.lower() instead of uppercase.
Filtering with incorrect conditions like k > 0.