> Source URL: /ai-and-sports/projects/6-predicting-the-future/predicting-the-future.basketball.project
---
title: Predicting the Future - Points, Performance & Breakouts (Basketball)
student_outcomes:
  - use dictionaries to store structured player and game data
  - find simple patterns in recent performance data
  - build a reusable prediction function for next-game output
  - label breakout candidates with a clear rule-based threshold
---

# Project: Predicting the Future - Points, Performance & Breakouts (Basketball)

---

## Introduction

Basketball prediction starts with simple models. If we know recent production and expected minutes, we can estimate what might happen next game.

In this project, you will build a lightweight prediction model and flag breakout-watch games.

### What we're building

By the end of this project, you will:

- **Store player data in dictionaries**
- **Detect trends** in recent scoring
- **Predict next-game points** from recent rates
- **Classify breakout potential** with clear rules

### Why this matters

Most advanced models start with a simple baseline. If you can build and explain a baseline model, you are thinking like an analyst.

---

## Part 1: Quick Start

### Set up your project in Cursor

For this project, you will create your files from scratch (no starter pack download).

#### Before you start: quick vocabulary

- A **folder** is a container that holds files.
- A **file** is one item inside a folder.
- A file **extension** is the ending in the file name:
  - `.py` means Python code.
  - `.csv` means table-style data.

1. Pick an easy location for your project folder:
   - Mac: `Desktop` in Finder
   - Windows: `Desktop` in File Explorer
   - Chromebook: `My files` in the Files app
2. Create a folder called `basketball-performance-predictor`.
3. In Cursor, go to `File > Open Folder` and open `basketball-performance-predictor`.
4. In Cursor's left file explorer:
   - click **New Folder** and create `data`
   - click **New File** and create `performance_predictor.py`
   - open `data`, click **New File**, and create `recent_games.csv`
5. If you do not see file extensions on your computer, that is okay. Type the full names exactly, including `.py` and `.csv`.

### Writing the code

Type this into `performance_predictor.py`:

```python
recent_points = [18, 22, 25, 21, 27]
recent_minutes = [30, 32, 35, 31, 34]
projected_minutes = 33

points_per_minute = sum(recent_points) / sum(recent_minutes)
predicted_points = points_per_minute * projected_minutes

print(f"Predicted points next game: {predicted_points:.1f}")
```

You just built a simple model:
`prediction = scoring rate x projected minutes`

### Running the code

Save the file (<Kbd>Cmd + S</Kbd> on Mac, <Kbd>Ctrl + S</Kbd> on Windows/Chromebook).

Run the file with Cursor's built-in **Run Python File** play button in the top-right.

If the play button is missing, install/enable the Python extension in Cursor and reopen `performance_predictor.py`.

Expected output:

```
Predicted points next game: 23.7
```

If your output matches, your project setup is working.

---

## Part 2: Project Milestones

### Milestone 1: Store player data in a dictionary

Dictionaries let you give each value a name (`"season_average"`, `"recent_points"`) instead of remembering index positions.

Add this below your existing code:

```python
player = {
    "name": "Jalen Carter",
    "team": "Greenville Comets",
    "season_average": 20.8,
    "recent_points": [18, 22, 25, 21, 27],
    "recent_minutes": [30, 32, 35, 31, 34]
}

print(player["name"])
print(player["recent_points"])
```

Expected output:

```text
Jalen Carter
[18, 22, 25, 21, 27]
```

---

### Milestone 2: Build reusable prediction functions

Now wrap your logic into reusable functions.
This makes your code easier to test and reuse for other players.

Add this below Milestone 1:

```python
def average(values):
    return sum(values) / len(values)

def predict_points(recent_points, recent_minutes, projected_minutes):
    points_per_minute = sum(recent_points) / sum(recent_minutes)
    return points_per_minute * projected_minutes

projected_minutes = 33
prediction = predict_points(
    player["recent_points"],
    player["recent_minutes"],
    projected_minutes
)

print(f"{player['name']} predicted points: {prediction:.1f}")
```

Expected output:

```text
Jalen Carter predicted points: 23.7
```

---

### Milestone 3: Detect trend direction

Prediction is not just one number. Analysts also ask: "Is this player trending up or down?"

Add this below your current code:

```python
recent = player["recent_points"]
first_half_avg = average(recent[:2])
second_half_avg = average(recent[-2:])

if second_half_avg > first_half_avg:
    trend = "up"
elif second_half_avg < first_half_avg:
    trend = "down"
else:
    trend = "flat"

print(f"Trend: {trend}")
```

Expected output:

```text
Trend: up
```

---

### Milestone 4: Add breakout watch logic

Now turn prediction + season average into a category label.

Add this below your current code:

```python
def breakout_label(predicted_points, season_average, breakout_margin):
    if predicted_points >= season_average + breakout_margin:
        return "Breakout watch"
    if predicted_points >= season_average:
        return "On pace"
    return "Below season pace"

tag = breakout_label(prediction, player["season_average"], 3.0)
print(f"Tag: {tag}")
```

Expected output:

```text
Tag: Breakout watch
```

---

### Milestone 5: Load recent game logs from CSV

Now you will keep game data in a CSV so you can update predictions without editing Python logic.

1. Open `data/recent_games.csv`.
2. Paste the data below.
3. Save the file.
4. Make sure the file name is exactly `recent_games.csv` (not `recent_games.csv.txt`).

Paste this into `data/recent_games.csv`:

```text
date,points,minutes
2026-02-01,18,30
2026-02-03,22,32
2026-02-06,25,35
2026-02-08,21,31
2026-02-10,27,34
```

Now load that CSV in Python and re-run the prediction using file data.
Add this below your existing code:

```python
import csv

recent_points = []
recent_minutes = []

with open("data/recent_games.csv", "r") as file:
    reader = csv.DictReader(file)
    for row in reader:
        recent_points.append(float(row["points"]))
        recent_minutes.append(float(row["minutes"]))

player["recent_points"] = recent_points
player["recent_minutes"] = recent_minutes
prediction = predict_points(recent_points, recent_minutes, projected_minutes)

first_half_avg = average(recent_points[:2])
second_half_avg = average(recent_points[-2:])
if second_half_avg > first_half_avg:
    trend = "up"
elif second_half_avg < first_half_avg:
    trend = "down"
else:
    trend = "flat"

print(f"CSV-based prediction: {prediction:.1f}")
```

Click **Run Python File** again and verify your CSV-based prediction prints.

Expected output (your exact decimal may vary slightly):

```text
CSV-based prediction: 23.7
```

---

### Milestone 6: Build a final prediction card

Now combine prediction, trend, and tag in one clean report block.

Add this below Milestone 5:

```python
tag = breakout_label(prediction, player["season_average"], 3.0)

print("=" * 46)
print(f"PREDICTION CARD: {player['name']}")
print("=" * 46)
print(f"Projected minutes: {projected_minutes}")
print(f"Predicted points: {prediction:.1f}")
print(f"Season average: {player['season_average']:.1f}")
print(f"Trend: {trend}")
print(f"Tag: {tag}")
print("=" * 46)
```

Expected result:

- A final prediction card with projected minutes, prediction, season average, trend, and breakout tag.

If you made it this far, you built a complete basketball prediction workflow from scratch.

---

## Common Fixes

- `FileNotFoundError`: confirm the path is exactly `data/recent_games.csv`.
- `ValueError`: check the CSV `points` and `minutes` columns are numeric.
- No play button: install/enable Python extension in Cursor and reopen `performance_predictor.py`.

---

## Bonus Exercises: Push It Further with Your Agent

Use this short prompt structure for better AI help:

1. **Goal**: what you want to build
2. **Context**: file name + what code already exists
3. **Constraints**: keep beginner-friendly, minimal changes
4. **Output format**: ask for exact code + where to paste + expected output

### Bonus 1: Predict Multiple Players

Try this prompt:

```text
You are my Python tutor and coding assistant.

Goal:
Predict points for 3 players and print one prediction card per player.

Context:
I am editing performance_predictor.py.
I already have predict_points(...), breakout_label(...), and a final prediction card format.

Constraints:
- Keep my current single-player flow working.
- Add only what is needed for multi-player support.
- Use beginner-friendly Python.

Output format:
1) Plan (3 bullets)
2) CSV format I should use
3) Exact code changes
4) Where to paste each code block
5) Example output for 2 players
```

### Bonus 2: Add a Prediction Range

Try this prompt:

```text
You are my Python tutor and coding assistant.

Goal:
Show low / medium / high prediction ranges instead of only one predicted value.

Context:
Current code calculates one prediction from recent points and minutes.

Constraints:
- Keep formulas simple (no advanced libraries).
- Explain the math in one short paragraph.
- Keep my current print card and add range lines.

Output format:
1) Range formula and reason
2) Code changes only
3) Expected output block
4) One way to tune the range width
```

### Bonus 3: Compare Prediction vs Actual

Try this prompt:

```text
You are my Python tutor and coding assistant.

Goal:
Compare predicted points to actual points and calculate prediction error.

Context:
I already compute prediction in performance_predictor.py.
I want to add this after the final prediction card.

Constraints:
- Keep this beginner-level.
- Show both signed error and absolute error.
- Do not remove existing outputs.

Output format:
1) Code block to add
2) Where to paste it
3) Expected output with sample numbers
4) One sentence explaining how to interpret error
```


---

## Backlinks

The following sources link to this document:

- [>button: 🏀 Basketball](/ai-and-sports/projects/6-predicting-the-future/predicting-the-future.project.llm.md)
