Apply your knowledge to build something amazing!
:information_source: Project Overview Difficulty Level: Intermediate
Estimated Time: 4-6 hours
Skills Practiced:
In this project, you will build a program to predict the new Covid-19 cases using the basic reproduction number (R0). R0 represents the average number of people who will catch the disease from one infected person. Your program will predict how the number of cases grows based on this factor. This project will enhance your understanding of lists, for loops, and functions in programming.
graph TD
A[Start: Understand R0 Concept] --> B[Part 1: Calculate Average R0]
B --> C[Collect Daily Case Data]
C --> D[Calculate R0 for Each Day]
D --> E[Find Average R0]
E --> F[Part 2: Predict Future Cases]
F --> G[Create Prediction Model]
G --> H[Generate Daily Predictions]
H --> I[Display Results]
I --> J[Create Video Demo]
J --> K[Submit Project]
This project involves coding a simple Covid-19 prediction model based on R0, and submitting a video demonstrating how your program works. There is no report required for this project.
:warning: Critical Setup Before starting:
- Make a copy of the Google Colab notebook
- Save it to your Google Drive
- Rename it with your name:
YourName_Covid19_Prediction.ipynb
- Make sure you're logged into your Google account
Your project will be evaluated based on the following criteria:
Code Functionality (50%)
Code Quality (25%)
Creativity and Features (15%)
Video Submission (10%)
Final submission should include:
.py
or notebook)Make sure to double-check your project before submitting. Ensure you have included the Python code file and the video explanation as required.
:link: Submit your project here
:bulb: Understanding R0 What is R0? Think of it like this:
- If R0 = 2.0, one infected person spreads to 2 people on average
- If `R0 < 1.0`, the outbreak will eventually die out
- If `R0 > 1.0`, cases will grow exponentially
In this project, you need to create a program to predict the new Covid-19 cases using R0. Click the link here and make a copy of Colab Notebook into your Google Drive for coding.
To predict the Covid-19 cases in Malaysia, the basic reproduction number (R0) of Covid-19 in Malaysia is used. In short, the R0 is a projection of how many people on average each new Covid-19 patient would infect.
Example:
Important facts:
Disclaimer: In this project, R0 is predicted by the assumptions:
In general, this project will be divided into 2 parts:
:memo: Milestone Checkpoint 1 :white_check_mark: Goal: Calculate the average R0 from historical data
⏱️ Time: ~1 hour
:dart: Success Criteria: Your program can calculate R0 from user-provided case data
:bulb: Common Error If you get a
ValueError
, make sure to convert input to integer usingint()
How many days of data do you want to insert? 3
Cases for 3 day(s) before:
1095
Cases for 2 day(s) before:
2188
Cases for 1 day(s) before:
1500
day_case = int(input(""))
Store the day_case in the list "data_cases" using the .append() method.
Continue when 1st iteration, then calculate r0 using the formula:
day_r0 = today_cases / yesterday_cases
if x == 0:
continue
day_r0 = data_cases[x]/data_cases[x-1]
:warning: Important Make sure your
data_r0
list is not empty before calculating the average!
def average(data_r0):
a = 0
for b in data_r0:
a += b
return a / len(data_r0)
How many days of data do you want to insert? 3
Cases for 3 day(s) before:
1095
Cases for 2 day(s) before:
2188
Cases for 1 day(s) before:
1500
Data Cases: [1095, 2188, 1500]
Calculated r0: [2.0, 0.69]
Average of r0: 1.34
Remarks: More days of data leads to more accurate prediction of R0.
:memo: Milestone Checkpoint 2 :white_check_mark: Goal: Use calculated R0 to predict future cases
⏱️ Time: ~2 hours
:dart: Success Criteria: Your program generates daily predictions with varying R0
predict = {
"new_cases":[data_cases[-1]],
"cum_cases":[data_cases[-1]],
"r0":[r0]
}
Day 0 is started with the data of the last day inserted and the average of r0 calculated
predict_days = int(input("How many days do you want to predict? "))
:bulb: Debugging Tip If predictions seem too high or low:
- Check your R0 calculation
- Verify the random range is +/-0.1
- Make sure you're using the correct index in lists
import random
def randomr0(r0):
if random.random() > 0.5:
r0 = r0 + 0.1 * random.random()
else:
r0 = r0 - 0.1 * random.random()
return r0
new_r0 = round(randomr0(r0), 2)
Calculate new case by using the formula as follows:
new_case = yesterday_newcases * new_r0
new_case = int(predict["new_cases"][i] * new_r0)
Calculate cumulative case by using the formula as follows:
cum_case = yesterday_cumcases + new_case
cum_case = predict["cum_cases"][i] + new_case
print("Predict Day", i+1, "- new:", new_case, "cum:", cum_case, "r0:", new_r0)
How many days do you want to predict? 10
Predict Day 1 - new: 2040 cum: 3540 r0: 1.36
Predict Day 2 - new: 2590 cum: 6130 r0: 1.27
Predict Day 3 - new: 3470 cum: 9600 r0: 1.34
Predict Day 4 - new: 4580 cum: 14180 r0: 1.32
Predict Day 5 - new: 6595 cum: 20775 r0: 1.44
Predict Day 6 - new: 8243 cum: 29018 r0: 1.25
Predict Day 7 - new: 11787 cum: 40805 r0: 1.43
Predict Day 8 - new: 16855 cum: 57660 r0: 1.43
Predict Day 9 - new: 21911 cum: 79571 r0: 1.3
Predict Day 10 - new: 27388 cum: 106959 r0: 1.25
IndexError: list index out of range
ValueError: invalid literal for int()
ZeroDivisionError
# Test with small numbers first
# Example: 3 days with cases [100, 150, 200]
# Expected R0: [1.5, 1.33], Average: 1.42
Add a simple bar chart showing daily cases using matplotlib:
import matplotlib.pyplot as plt
# Plot your predictions
Modify your program to show three scenarios:
By the assumption that the infection of Covid-19 happens randomly on any day within 2 weeks, predict the new cases for one month.
Example:
:memo: Final Milestone :white_check_mark: Goal: Complete project and create video demo
⏱️ Time: ~1 hour
:dart: Success Criteria:
- Code runs without errors
- Predictions are reasonable
- Video clearly explains your solution
Code with AI: Try using AI for project-related tasks.
Prompts:
:bulb: Pro Tip Remember to test your code with different R0 values to understand how they affect the spread!