How vpatel95/decision-tree-classifier works
Project type and purpose
• This is an open-source command-line tool (C++ and Python) that implements a Decision Tree Classifier and Random Forest/Boosted Forest Classifier to predict room occupancy from sensor data.
• It uses data preprocessing, configurable model parameters, training on UCI sensor datasets, and evaluation via a Python test harness.
File structure
• Top-level:
• .gitignore, README.md, bitbucket-pipelines.yml (CI config)
• src/ (all source code)
• src/:
• Makefile (build scripts)
• classifier.cpp, decision_tree.cpp (core C++ implementations)
• includes/json.hpp (header-only JSON parser)
• includes/decision_tree.hpp (public API for tree structures)
• configs/config.json (model/configuration parameters)
• data/ (raw and split datasets + preprocessing script)
– data_preprocessing.py (cleaning/extracting features)
– test.txt, training.txt, validate.txt, validation.txt
• run_test.py (Python harness to invoke the compiled binary on datasets)
• Patterns:
• Modular separation: data preprocessing, core algorithms, config, test harness
• Single binary (appears to be “app” or classifier executable) invoked by Python
Key insights from README
• Configurable pipeline driven by JSON: choose model type, feature set, train/test/validation paths, bagging/boosting parameters.
• Build via Makefile or direct g++ command.
• Usage: run the binary with config, then inspect output or trees.
• Dependencies: g++, Python 3.x, UCI datasets.
Main components
a. Data Sources
• Raw sensor files (training.txt, test.txt, validation.txt)
b. Data Preprocessing Module (Python)
• data_preprocessing.py: cleans raw data, extracts features → writes extracted files
c. Configuration Module
• configs/config.json: holds all pipeline parameters
d. Core Classifier (C++ Binary)
• classifier.cpp & decision_tree.cpp: build Decision Tree, Random Forest, Boosted Forest
• json.hpp: parse config.json at runtime
e. Test Harness (Python)
• run_test.py: invokes the C++ binary with various configs and data splits, collects metrics
f. Build & CI
• src/Makefile: compile steps
• bitbucket-pipelines.yml: CI build/test definitions
Relationships & interactions
• (1) Data Preprocessor reads raw sensor files → outputs preprocessed feature files.
• (2) C++ binary at startup reads configs/config.json via json.hpp.
• (3) C++ binary loads extracted data, instantiates model (Decision Tree or Random Forest), trains on training set.
• (4) C++ binary writes predictions & optionally tree visualizations.
• (5) run_test.py orchestrates multiple runs: calls the binary, captures accuracy, logs results.
• (6) Makefile ties together build; CI definition kicks off Make and run_test.py.
Architectural patterns and design principles
• Single Responsibility: each module (preprocessing, configuration, training, testing) does one job.
• Config-driven pipeline: change behavior by editing JSON.
• Modular C++ code: public API (decision_tree.hpp) vs implementation.
• Extensibility: can add new classifiers or metrics by extending source and config schema.
Technologies & frameworks to annotate
• C++11 (g++): core algorithms.
• Python 3.x: data preprocessing & test harness.
• JSON.hpp: config parsing.
• Make & CI (Bitbucket Pipelines)
Detail
• File paths (e.g., src/data/, src/configs/, src/includes/).
• JSON parsing step inside the binary.
• Optional paths (e.g., validation vs test).
• Do not overcrowd: group similar elements but keep them distinct.