Skip to content

About

Classroom Decision Tree activity that predicts whether a small business location will succeed from foot traffic, area income, and nearby competitors. Built in sample dataset, CLI options, and tree plot export.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

Repository files navigation

🏪 Location Decision Tree — Will the Business Succeed?

🔍 Overview

A classroom Decision Tree activity that predicts whether a small business location will be successful based on three intuitive features:

Feature Meaning
Person Foot traffic — number of people passing per hour
Income Average income in the area (in thousands)
Shops Number of competing shops nearby

The label is Successful → Yes / No.


📦 Features

  • Built-in sample dataset (15 rows) — no external data needed to start
  • Auto-creates location.csv on first run
  • Trains a DecisionTreeClassifier with a configurable max_depth
  • Reports test-set accuracy
  • NEW: All key parameters exposed as command-line options
  • NEW: Optional tree visualization saved as a PNG (--save-plot)
  • NEW: --regenerate flag to refresh the CSV from the built-in sample
  • 🐛 Bug fix: previous version used nested-list column headers ([["Person",...]]) which broke pandas indexing — fixed to a flat list

🧠 Dataset (built-in sample)

Person Income Shops Successful
20 22 3 Yes
30 17 8 No
10 30 2 Yes
50 15 3 Yes
60 16 5 Yes
5 20 4 No
... ... ... ...

15 rows total. Saved to location.csv automatically the first time you run the script.


🧰 Requirements

pip install -r requirements.txt

⚙️ How to Run

Default run (creates location.csv if missing, trains, and prints accuracy):

python Location_DT_Activity.py

Custom run:

python Location_DT_Activity.py --csv location.csv --max-depth 3 --test-size 0.25 --seed 42 --save-plot tree.png

Regenerate the CSV from the built-in sample:

python Location_DT_Activity.py --regenerate

🛠️ Command-Line Options

Flag Default Description
--csv location.csv Path to the CSV dataset (auto-created if missing)
--max-depth 2 Max depth of the decision tree
--test-size 0.25 Fraction of data used for testing (0.0–1.0)
--seed None Random seed for reproducible splits
--save-plot off If set, saves a tree visualization PNG
--regenerate off Overwrite the CSV with the built-in sample before training

📊 Example Output

Created sample dataset at: location.csv

The dataset:
    Person  Income  Shops Successful
0       20      22      3        Yes
1       30      17      8         No
...

The predictions of the model are:
 ['Yes' 'No' 'Yes' 'Yes']

Accuracy = 0.7500

🎓 Learning Objectives

  1. Build a DataFrame from a Python list of records
  2. Save / load CSV files with pandas
  3. Separate features from the label
  4. Use train_test_split for a fair evaluation
  5. Train a DecisionTreeClassifier and reason about max_depth
  6. Interpret the resulting tree visually (--save-plot)

📁 Project Structure

Location-Decision-Tree-/
├── Location_DT_Activity.py   # Main script
├── location.csv              # Auto-generated on first run
├── requirements.txt          # Python dependencies
└── README.md

📄 License

Educational use — Credits to CS42.org.

About

Classroom Decision Tree activity that predicts whether a small business location will succeed from foot traffic, area income, and nearby competitors. Built in sample dataset, CLI options, and tree plot export.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages