Home โ€บ ML for Climate Data
๐Ÿ”ฅ Module 02 ยท Advanced

ML for Climate Data

โœจ PAN'S RULE: The data has a story to tell, you just have to learn how to listen! โœจ

What if you could be a weather detective ๐Ÿ•ต๏ธโ€โ™€๏ธ? Or a superhero who tells a whole city when to save energy? Today, we're teaching a computer to look at clues about our planet and maybe even predict the future!

๐Ÿ•ต๏ธโ€โ™€๏ธ Safety Check: Learning about our planet is exciting, but can sometimes feel a bit big or scary. Remember: every scientist and builder started just like youโ€”curious and wanting to help. Focus on the one small, cool thing you can learn today! Also, real scientists always check their sources. We only use data from trusted places, like NASA, so our clues are real!
๐Ÿ’ก

The Big Picture: Becoming a Weather Detective

So what does a weather detectiveโ€”or a "meteorologist"โ€”actually do? They use data (clues!) from the past to understand what might happen next. This video from SciShow Kids gives you a peek into how they work. We're about to do the same thing, but with code!

๐Ÿง  How Does a Computer Learn? Let's Play!

We showed our computer this dog: ๐Ÿฆฎ and told it "This is a dog." It learned to look for things with four legs, fur, and a tail. Now, which of these new pictures will it most likely call a 'dog'?

A Cat
A Husky
A Yellow Car
๐Ÿ”Ž

Your First Mission: Treasure Hunt! ๐ŸŽฏ

Before we write code, let's practice being data detectives. Your mission: explore the interactive chart below to find the answers to the treasure hunt questions. You can click and drag to zoom in, and hover your mouse to see the exact numbers!

โœ๏ธ

Pre-Code Challenge: Draw the Trend!

Look at the bumpy line in the chart above. It goes up and down every single day! But is there a hidden, long-term trend? Before we use code, use your eyes. Can you guess where the "average" line would go? Try tracing the general direction with your finger on the screen! This is exactly what we're about to ask the computer to do.

๐Ÿ‘ฉโ€๐Ÿ’ป

Your Code Lab: Predicting with Python

Ready to use the same tools as real data scientists? We're going to use a tool called Google Colab. It's like a Google Doc, but for writing and running Python code right in your browser. No installation needed! Let's go!

Here's the secret plan:

Now you're ready! Open a new Colab notebook and copy-paste this code into a cell. Press the play button (โ–ถ๏ธ) to run it!

# 1. Get our super-toolboxes (called libraries)
import pandas as pd # Pandas helps us work with data tables

# 2. Load a real dataset from the internet
# This is a history of minimum daily temperatures in Melbourne, Australia
url = 'https://raw.githubusercontent.com/jbrownlee/Datasets/master/daily-min-temperatures.csv'
df = pd.read_csv(url)

# 3. How many clues do we have?
print(f"This dataset has {len(df)} days of weather clues!")

# 4. Be a detective: let's peek at the first 5 clues!
print("\nHere's a peek at the data:")
print(df.head())

# 5. The magic moment: turn the data into a picture!
print("\nCreating your temperature plot... check it out!")
df.plot(title='Daily Minimum Temperatures in Melbourne')

When you run this, you'll see how many clues our AI detective has to work with (that's almost 10 years of data!), a table of data, AND a chart that visualizes it all. You just used Python to analyze real-world climate data.

๐Ÿงช Tinker Time: Your Turn to Experiment!

Real scientists ask "what if?" Try these challenges in your Colab notebook:

  • Change df.head() to df.tail(). What does it show you now? (Hint: "tail" is the opposite of "head"!)
  • Can you change the title of the plot? Find the text 'Daily Minimum Temperatures in Melbourne' and change it to something fun, like 'My Awesome Weather Chart'.
  • In the second code block (the Level Up one below), change window=365 to window=30. Run it again. Does the line get smoother or bumpier? Why do you think that is?

๐Ÿค” What's a "Rolling Average"?

Imagine you wanted to know your average video game score, but you only looked at the last 10 games you played. That's a rolling average! It smooths out the wild up-and-down scores from single games to show your *real* skill trend over time. We're doing the same thing with 365 days of weather to find the planet's real trend!

๐Ÿš€

Level Up: Find the Hidden Trend

Okay, you've seen the data. But a true data scientist looks for the hidden story. Is the temperature *generally* going up or down? It's hard to tell with all those daily spikes! Let's use that "rolling average" trick to find the trend line. Add this new code to a new cell in your Colab notebook and run it!

# This calculates the average temperature over a full year (365 days)
# and plots that trend! It smooths out the daily bumps.
# You need to run this in a NEW cell after the first one.
# It also needs the 'Temp' column to be a number, let's fix that first!
df['Temp'] = pd.to_numeric(df['Temp'], errors='coerce')

print("Calculating the 365-day average trend...")
df['Temp'].rolling(window=365).mean().plot(title='Smoothed Temperature Trend in Melbourne')

WHOA! See that new line? It's much smoother. It shows the real, long-term pattern hidden in the data. You just used your first data analysis model to find a hidden signal.

๐Ÿ”ฎ

Your Final Mission: Predict Tomorrow!

Finding a trend is cool, but what about predicting the future? This is where true Machine Learning comes in. We'll use a famous toolbox called `scikit-learn` to build a simple "model" that learns from all the past data and makes a guess about the next day. This is itโ€”the big moment! Add this to a new code cell.

# This is real Machine Learning!
# We'll use a simple model to predict the next value.
from sklearn.linear_model import LinearRegression
import numpy as np

# We need to reshape our data for the model
X = np.array(range(len(df))).reshape(-1, 1)
y = df['Temp'].dropna() # Drop any missing values
X = X[:len(y)] # Make sure X and y are the same size

model = LinearRegression()
model.fit(X, y)

# Let's predict the temperature for the very next day!
next_day_index = len(df)
prediction = model.predict([[next_day_index]])

print(f"\n๐Ÿค– AI Prediction for the next day's temp: {prediction[0]:.2f} degrees")

You did it! That number is your AI's best guess for the future based on all the data from the past. You just built and ran a real predictive model!

๐Ÿ† Pro Challenge: Become a Data Explorer

You just analyzed weather in Australia. What about Tokyo? Or your own city? Find a simple, public CSV dataset from a trusted source like Kaggle Datasets or data.gov. Try to load it into your Colab notebook by changing the `url` variable. You might need to change the column names in the code, too. This is exactly what real data scientists do every day!

๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘ง Parent Corner

Your young scientist is using Python and Google Colabโ€”the exact same tools used by data scientists at NASA, Google, and Pixar to analyze everything from climate change to movie animations. This isn't just a toy, it's the real deal!

๐ŸŒŽ Talk About It: Ask them to show you the "smoothed-out" trend line. Does it generally go up or down over the 10 years in the data? What do you think that means for the city of Melbourne?

๐Ÿ“š Learn More