Bird
0
0

Consider the following code snippet:

medium📝 Predict Output Q4 of 15
SciPy - Curve Fitting and Regression
Consider the following code snippet:
import numpy as np
from scipy.optimize import curve_fit

def linear_model(x, m, c):
    return m * x + c

x_vals = np.array([1, 2, 3, 4, 5])
y_vals = np.array([2.2, 4.0, 6.1, 7.9, 10.2])

params, covariance = curve_fit(linear_model, x_vals, y_vals)
print(np.round(params, 2))
What will be the output of print(np.round(params, 2))?
A[2.0, 0.0]
B[1.99, 0.11]
C[1.95, 0.15]
D[2.1, -0.1]
Step-by-Step Solution
Solution:
  1. Step 1: Understand the model

    The model is linear: y = m*x + c.
  2. Step 2: Use curve_fit to estimate parameters

    curve_fit finds m and c that best fit the noisy data.
  3. Step 3: Analyze output

    The data roughly follows y ≈ 2*x, with slight noise. The fitted slope (m) will be close to 2, and intercept (c) near 0.1.
  4. Final Answer:

    [1.99, 0.11] -> Option B
  5. Quick Check:

    Parameters close to expected linear relation [OK]
Quick Trick: Fitted params approximate underlying linear trend [OK]
Common Mistakes:
  • Assuming exact parameters without noise
  • Confusing parameter order (m, c)
  • Ignoring rounding effects

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes