0
0
SciPydata~30 mins

Non-linear curve fitting in SciPy - Mini Project: Build & Apply

Choose your learning style9 modes available
Non-linear Curve Fitting with SciPy
📖 Scenario: You are a scientist studying how a plant grows over time. You collected data on the plant's height at different days. You want to find a curve that best fits this growth data to understand the growth pattern.
🎯 Goal: Build a Python program that uses SciPy to fit a non-linear curve to the plant growth data and display the fitted curve parameters.
📋 What You'll Learn
Create a dictionary with days and plant heights
Define a growth model function with parameters
Use SciPy's curve_fit to find the best parameters
Print the fitted parameters
💡 Why This Matters
🌍 Real World
Scientists and engineers often collect data that follows complex patterns. Curve fitting helps find formulas that describe these patterns, making predictions easier.
💼 Career
Data scientists and analysts use curve fitting to model trends in data, which is essential in fields like biology, finance, and engineering.
Progress0 / 4 steps
1
Create the plant growth data
Create a dictionary called growth_data with these exact entries: 1: 2.5, 2: 3.6, 3: 5.1, 4: 7.4, 5: 11.2 representing days and plant heights.
SciPy
Need a hint?

Use curly braces to create a dictionary with the exact day-height pairs.

2
Define the growth model function
Define a function called growth_model that takes t, a, and b as inputs and returns a * t ** b.
SciPy
Need a hint?

The function should return the formula a * t ** b where t is time.

3
Fit the curve using SciPy
Import curve_fit from scipy.optimize. Use curve_fit with growth_model, the list of days from growth_data.keys(), and the list of heights from growth_data.values(). Store the output parameters in params.
SciPy
Need a hint?

Use list(growth_data.keys()) and list(growth_data.values()) to pass days and heights as lists.

4
Print the fitted parameters
Print the string "Fitted parameters: a = {params[0]:.2f}, b = {params[1]:.2f}" using an f-string to show the fitted values rounded to two decimals.
SciPy
Need a hint?

Use print(f"Fitted parameters: a = {params[0]:.2f}, b = {params[1]:.2f}") to show the results.