COM6018 Data Science with Python

Week 9: Curve Fitting with scikit-learn

Jon Barker

Copyright © 2023–2025 Jon Barker, University of Sheffield. All rights reserved.

Copyright © 2023–2025 Jon Barker, University of Sheffield. All rights reserved.
COM6018 Data Science with Python

In this lab

We will use scikit-learn to fit the atmospheric CO2 concentration data.

We will then use our model to predict future atmospheric CO2 concentration.

On what date will it reach 450 ppm?

Copyright © 2023–2025 Jon Barker, University of Sheffield. All rights reserved.
COM6018 Data Science with Python

The Task

The stages of the task are as follows:

  • Loading the CO2 data.
  • Fitting a polynomial curve to describe the long-term growth trend.
  • Fitting a periodic function to describe the seasonal variation.
  • Tuning the model hyperparameters (order of polynomial, etc.).
  • Evaluating the model.
  • Using the model to make a prediction.
Copyright © 2023–2025 Jon Barker, University of Sheffield. All rights reserved.
COM6018 Data Science with Python

Obtaining the Jupyter Notebook

If you have cloned and pulled the module's GitHub repository, then you should see,

materials/labs/
├── 080_curve_fitting_with_scikit_learn.ipynb
├── data
│   ├── co2.csv
│   └── ... etc.

The lab is 080_curve_fitting_with_scikit_learn.ipynb and it will need the data file data/co2.csv.

Alternatively, you can download the notebook and data via links on Blackboard.

Copyright © 2023–2025 Jon Barker, University of Sheffield. All rights reserved.
COM6018 Data Science with Python

Getting Help

Copyright © 2023–2025 Jon Barker, University of Sheffield. All rights reserved.