How joyal99/machine-learning-k-nn-cancer-diagnosis-with-k-d-trees works
Main Components
• Data Source and Preparation:
• External Data File: data.csv contains the breast cancer dataset.
• Data Reader: The Reader.java module reads the CSV file and populates a Map of Patient objects.
• Data Model: Patient.java represents each data instance with its features (attributes) and diagnosis.
• Core Processing Modules:
• Main Orchestrator: Ass3.java acts as the central controller. It handles overall orchestration – loading data, splitting into training and test sets, constructing trees, performing k-NN search, evaluating results, and timing execution.
• KD-Tree Component: KdTree.java, which includes methods to build the tree (makeTree) and perform nearest neighbor searches. This module encapsulates the logic for partitioning data based on maximum variance and recursive tree creation.
• Ball Tree Component: BallTree.java, which similarly constructs a ball tree from the data and supports k-NN search with its own recursive methods and distance calculations.
• Evaluation and Decision Making:
• k-NN Classification: Both tree components are used to perform efficient nearest neighbor searches for classification decisions.
• Voting Mechanism: Methods like majorityVote (for KD-Tree) and majorityVoteBallTree (for Ball Tree) determine the final diagnosis based on the neighbors found.
• Performance Metrics: Evaluation of accuracy and running time combined with a built-in Stopwatch (inner class in Ass3.java) for execution timing.
Relationships and Interactions
• Flow:
• The process begins with data being loaded from data.csv by Reader.java and converted into Patient objects.
• Ass3.java directs the splitting of this data into training and testing sets.
• The training data is then supplied separately to the KD-Tree and Ball Tree modules (KdTree.java and BallTree.java) where each structure is built.
• When classifying a test instance, Ass3.java queries both tree structures to gather k-nearest neighbor lists.
• The respective majority voting methods determine the predicted diagnosis.
• Finally, the system aggregates results to compare performance metrics such as prediction accuracy and execution time.
Additional Notes
• Blocks are clearly labeled with file/class names.
• Despite the relative simplicity of the overall structure, do not hesitate to break it down into as many detailed components as possible to capture every essential step in the data processing pipeline and classification process.
Happy diagramming!