Skip to content
New Workbook
Sign up
Project: Predicting Temperature in London

As the climate changes, predicting the weather becomes ever more important for businesses. You have been asked to support on a machine learning project with the aim of building a pipeline to predict the climate in London, England. Specifically, the model should predict mean temperature in degrees Celsius (°C).

Since the weather depends on a lot of different factors, you will want to run a lot of experiments to determine what the best approach is to predict the weather. In this project, you will run experiments for different regression models predicting the mean temperature, using a combination of sklearn and mlflow.

You will be working with data stored in london_weather.csv, which contains the following columns:

  • date - recorded date of measurement - (int)
  • cloud_cover - cloud cover measurement in oktas - (float)
  • sunshine - sunshine measurement in hours (hrs) - (float)
  • global_radiation - irradiance measurement in Watt per square meter (W/m2) - (float)
  • max_temp - maximum temperature recorded in degrees Celsius (°C) - (float)
  • mean_temp - target mean temperature in degrees Celsius (°C) - (float)
  • min_temp - minimum temperature recorded in degrees Celsius (°C) - (float)
  • precipitation - precipitation measurement in millimeters (mm) - (float)
  • pressure - pressure measurement in Pascals (Pa) - (float)
  • snow_depth - snow depth measurement in centimeters (cm) - (float)
# Run this cell to install mlflow
!pip install mlflow
# Run this cell to import the modules you require
import pandas as pd
import numpy as np
import mlflow
import mlflow.sklearn
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error
from sklearn.impute import SimpleImputer
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LinearRegression
from sklearn.tree import DecisionTreeRegressor
from sklearn.ensemble import RandomForestRegressor

# Read in the data
weather = pd.read_csv("london_weather.csv")

# Start coding here
# Use as many cells as you like
print(weather.head())
print(weather.info())
print(weather.describe())
weather.date = pd.to_datetime(weather['date'], format = '%Y%m%d')
weather
Hidden output
weather['year'] = weather['date'].dt.year
weather['month'] = weather['date'].dt.month
weather
Hidden output
print(weather.shape)
print(weather.isna().sum())

EDA

mean_temp_plot_year = plt.plot(weather['year'], weather['mean_temp'])
Hidden output
mean_temp_plot_month = plt.plot(weather['month'], weather['mean_temp'])
Hidden output

The maximum and minimum average temp are 29°C (July, 2003) and -7.6°C (January, 1987) respectively.

Obtaining the highest and lowest values of the rest features.

def highest_lowest (df, column):
    return df[column].max(), df[column].min() 
highest_lowest(weather, 'global_radiation')
weather.columns