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 ๐Ÿ•ต๏ธโ€โ™€๏ธ? What if you could teach a computer to look at clues from our planet and maybe even predict the future? Today, we're going to do just that. Let's go!

๐Ÿ•ต๏ธโ€โ™€๏ธ 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! 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!

๐ŸŽฏ Treasure Hunt: Be a Data Detective! ๐Ÿ”Ž

Use the interactive chart below to answer the questions. Hover your mouse to see exact numbers, and click and drag to zoom in on a specific time!

โœ๏ธ

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.

Heads Up, Pilot! Once we teach the computer how to find this trend, we're going to use that skill to program a virtual eco-drone in Scratch and help it plant a forest! ๐Ÿš๐ŸŒณ

๐Ÿ‘ฉโ€๐Ÿ’ป

Your Code Lab: Plotting with Python

โš™๏ธ What's an `import`?

Think of Python as an awesome backpack ๐ŸŽ’. Right now, it's empty. The `import` command grabs special power-up tools from a big library and puts them in your pack for the mission! `import pandas` gives us super-goggles for reading data, and `matplotlib` is a set of super-crayons for drawing amazing charts!

๐Ÿค– Click Here to Power Up the Data-Robot!

Ready to use the same tools as real data scientists? You don't have to understand all the code! Just press the big green 'Run' button (โ–ถ๏ธ) in the window below to see what our data-robot discovers.

Did you see it? WHOA! ๐Ÿคฏ With just a few lines of code, the computer read thousands of data points and turned them into that awesome chart. That bumpy line shows almost 10 years of daily temperatures in Melbourne, Australia.

๐Ÿ“ป

Signal vs. Noise

Think about listening to a radio. The daily up-and-down spikes in temperature are like "noise"โ€”the static that gets in the way. The long-term, overall trend is the "signal"โ€”the actual music you want to hear! Our next step is to use code to turn down the noise so we can hear the signal clearly.

๐Ÿš€

Level Up: Find the Hidden Trend

A true data scientist looks for the hidden story. Is the temperature *generally* going up or down? Remember how you traced the trend with your finger? This next bit of code does the *exact* same thing, but with super-fast math! We tell Python to look at a 'window' of 365 days at a time and calculate the average to smooth out the bumps. Go back to the code window above, find Part 2, and run it again to see the smoothed line appear!

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

Your mission is to find the 'Goldilocks' window. In the code window, change `window=365` to `window=7` (a week). The line will be super bumpy! Now try `window=1000`. Too flat! What `window` value do you think best shows the yearly seasons *and* the long-term trend? There's no single right answerโ€”it's what you think tells the best story!

๐Ÿค” Why does a smaller window make the line bumpier?

A smaller window (like 30 days) is only averaging the weather over one month. It's still affected by short-term heat waves or cold snaps. A big 365-day window averages a whole year, so those little bumps get smoothed out, revealing the true long-term trend!

๐Ÿ”ฎ

Your Final Mission: Predict Tomorrow!

Finding a trend is cool, but what about predicting the future? This is where true Machine Learning comes in. So how does our AI predict the future? We're using a model called Linear Regression. Imagine it as a robot that's an expert at drawing a single, perfectly straight 'line of best fit' through all our bumpy temperature data. To predict the future, it just extends that line a little further and tells us where the next point should land. It's one of the most fundamental models in all of machine learning!

โš™๏ธ Under the Hood: How does Linear Regression work?

It's all about a classic math formula: y = mx + b. In our model, 'y' is the temperature, and 'x' is the day number. The machine learning model's only job is to find the perfect values for 'm' (the slope of the line) and 'b' (where the line starts) to draw a line that gets as close as possible to all the real data points. Linear Regression is powerful, but it assumes the trend will continue in a straight line forever. What are the dangers of this assumption when modeling something complex like the climate? This is a core question in data ethics and science. More advanced models, which you'll see in later tracks, try to account for these complex curves and changes.

In the code window (Part 3), our data robot needs to know which day to predict. Our data file has 3,650 days of data. Since programmers start counting from 0, the last day is numbered 3649. To predict the *next* day, we ask about day number 3650. Watch it make a prediction! Go to Part 3 in the code and press Run.

# See how the prediction line continues the trend from our smoothed line?
# Let's predict the temperature for the very next day!
prediction = model.predict([[3650]])

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: Eco-Drone Mission!

Time to choose your mission, agent! Pick the one that excites you most.

Option A: Professional Data Storytelling

Your mission is to make this chart professional enough to show a real scientist. Go back to the Trinket and try adding these lines of code at the top of Part 3. Data visualization is about clarity and telling a story. Make this chart tell a powerful one.

# Add this near the other 'plt' lines!
plt.style.use('fivethirtyeight') # A cool pro style
plt.title("Melbourne Temperature Trends & Prediction")
plt.axvline(x=3650, color='r', linestyle='--') # Adds a prediction line!

Option B: ๐ŸŽฎ Build Your Own Game! (Best for first-time coders!)

You've mastered analyzing data... now let's use code to take action! Drones are used in real life to re-plant forests by dropping "seed pods." Your mission is to program a virtual eco-drone in Scratch, the block-based coding language perfect for builders.

  • Step 1: Open our Eco-Drone Starter Project in Scratch.
  • Step 2: Your challenge is to make the drone drop a "seed" (another sprite) every time it moves 100 steps.
  • Hint: You'll need a loop (like `forever`) and a conditional (`if...then`) block to check the drone's position. Can you figure it out?

This teaches you coordinates, loops, and how code can have a real-world impact. Good luck, pilot! ๐Ÿš

๐Ÿš€ Ready for a Real Dev Environment?

Trinket is a perfect training ground, but pro data scientists work on their own computers. The next step is to install Python and a tool like VS Code or Jupyter Notebook. You can download the data file for this project directly from the Trinket (click the โ˜ฐ menu > Download) and run this entire analysis yourself. This is how real projects are built. You could even connect your code to a live weather API to build a dashboard showing the real-time Air Quality Index (AQI) for your city!

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

Your young scientist just used Pythonโ€”the same programming language used at NASA, Google, and Pixar! They also got a mission for Scratch, a safe and creative coding platform from MIT. These aren't just toys, they're 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