Built to order

Software Defect Prediction using Machine Learning (NASA MDP)

This project predicts which software modules are likely to contain defects — before testing even starts — using only static code metrics like cyclomatic complexity and Halstead volume from the NASA Metrics Data Program datasets. A random-forest classifier learns the patterns from thousands of labeled modules (defective or clean), so QA teams can aim code review and testing where the bugs probably are. An interactive demo lets you enter a module's metrics and watch its defect-proneness score with the exact reasons. Suitable for B.E./B.Tech final-year projects in AI & Machine Learning, Computer

Software Defect Prediction using Machine Learning (NASA MDP) — project thumbnail preview
More project photos (2)

The problem

Testing budgets are finite and codebases are not: in any large project, a small fraction of modules hides most of the bugs. If you could predict which modules those are from static measurements alone — lines of code, decision density, operator complexity — you could point reviewers and testers exactly where they matter. That is software defect prediction, and this project implements it on the classic NASA Metrics Data Program datasets (CM1, KC1, JM1 and others) from the PROMISE repository: thousands of real software modules, each described by McCabe and Halstead metrics and labeled defective or clean. A random-forest classifier learns which metric patterns precede defects, evaluated with AUC and cross-project validation — training on one project and testing on another, the honest test of whether the patterns generalize.

How it works

  1. NASA MDP datasets (CM1: 498 modules, KC1: 2,109, JM1: 10,885) are loaded with their static metrics and defect labels.
  2. Metric distributions are explored; skewed Halstead metrics are log-transformed with the choice documented.
  3. A random-forest classifier trains on the metric vectors, with stratified cross-validation and class weighting for the defective minority.
  4. Within-project evaluation reports AUC, precision/recall and the confusion matrix; cross-project runs test generalization across datasets.
  5. Permutation importance ranks the metrics, revealing which complexity measures actually signal defects.
  6. In the demo, entered metrics are fed through the saved model; the app shows P(defective), the driver metrics and a prioritized testing recommendation.

Tech stack:

  • Python 3, scikit-learn (random forest)
  • Pandas, NumPy (data handling)
  • Matplotlib (distributions, ROC curves)
  • Jupyter Notebook (training & evaluation)
  • HTML5 canvas + JavaScript (interactive demo)
  • NASA MDP datasets (PROMISE repository)

Dataset & model details

  • Dataset: NASA Metrics Data Program datasets via the PROMISE repository — CM1 (498 modules), KC1 (2,109 modules), KC2, PC1 and JM1 (10,885 modules); each module described by McCabe (LOC, v(g), ev(g), iv(g)) and Halstead (n, v, l, d, i, e, b, t) metrics with a binary defective/clean label.
  • Task: Binary classification; input = static code-metric vector per module, output = P(defective).
  • Model: Random forest (200 trees, class-weighted), with log-transformed skewed metrics; hyperparameters selected by stratified cross-validation.
  • Metrics: AUC ≥ 0.75 within-project (design target for the built-to-order training run), plus precision/recall at the operating threshold and cross-project AUC. Published defect-prediction studies report AUC around 0.70–0.80 on these datasets; no figure is claimed as measured until the training run is executed for the order.
Parameter Value
Input ~20 static code metrics per module
Output P(defective), binary risk flag
Labeled modules 498–10,885 per dataset (CM1–JM1)
AUC ≥ 0.75 within-project (design target, not a measured claim)
Training time Approximately 2–10 min on a laptop CPU (expected)
Inference Sub-millisecond per module on CPU (expected)
Model file Approximately 5–20 MB (expected)
Demo Single-file web app, runs offline after download

Project features

  • [Defect-proneness classifier] Random forest over McCabe (cyclomatic, essential, design complexity) and Halstead (volume, difficulty, effort) metrics, outputting P(defective) per module.
  • [Interactive module inspector] Enter any module's metrics — or load the sample "god class" — and get a risk score with the exact metrics driving it.
  • [Dataset-median comparison chart] Each module's metrics plotted against dataset medians, making "this module is 4× more complex than typical" visible at a glance.
  • [Cross-project validation] The model is tested training on one NASA dataset and predicting on another, documenting honestly how well defect patterns transfer.
  • [Full training notebook] Data loading, metric distributions, imbalance handling, model training, within- and cross-project evaluation in one reproducible notebook.
  • [Metric-importance analysis] Which metrics actually predict defects (and which are noise) ranked and explained for the report.
  • [Exported trained model] Saved model plus the metric-computation guide, so new modules can be scored without retraining.

What is included

  • Complete training & evaluation Jupyter notebook
  • Trained random-forest model with metric preprocessing code
  • Interactive module-risk web demo
  • ROC curves, metric-importance plots, cross-project tables
  • Project report PDF (background, metrics theory, methodology, results, generalization limits)
  • PPT presentation for final review
  • Viva Q&A preparation document (McCabe vs Halstead, AUC vs accuracy, class imbalance, cross-project validity)

Limitations & prerequisites

  • Static metrics miss defects that come from requirements or integration issues — the report states what the model can and cannot see.
  • Cross-project prediction is weaker than within-project; the honest numbers are reported, not hidden.
  • AUC ≥ 0.75 is a design target for the training run, stated honestly — the report documents the actual achieved figure after training.
  • The demo's in-browser model is a compact illustration on key metrics; the full random forest ships separately.
  • A risk score prioritizes testing; it does not prove a module bug-free — no such claim is made.

Frequently Asked Questions

Which datasets are used and why?

The NASA MDP datasets (CM1, KC1, JM1…) from the PROMISE repository — the most-used public defect-prediction benchmarks, with real modules, standard metric sets and defect labels from actual QA histories.

What are McCabe and Halstead metrics?

McCabe metrics measure control-flow complexity (cyclomatic complexity counts independent paths); Halstead metrics measure code volume and mental effort from operator/operand counts. Both are computable without running the code.

Why AUC instead of accuracy?

Defective modules are a minority, so a lazy "all clean" model scores high accuracy while finding nothing. AUC measures ranking quality across all thresholds — the right metric for prioritization.

What is cross-project validation?

Training on one project's modules and testing on a different project's — the realistic deployment scenario, and much harder than testing on held-out modules of the same project. The report shows both.

How does the demo decide its recommendation?

It combines the predicted probability with the driver metrics: a 90%-risk module with v(g)=67 gets "test first"; a 15%-risk module gets "standard testing suffices."

Is this project suitable for a final-year project?

Yes — for AI & Machine Learning, Computer Science and IT programs. It connects software engineering with machine learning, uses real NASA data, and teaches honest evaluation including cross-project generalization. Suitable for B.E./B.Tech final-year projects in AI & Machine Learning, Computer Science and IT.

Components & software requirements
  • Python 3, scikit-learn (random forest)
  • Pandas, NumPy (data handling)
  • Matplotlib (distributions, ROC curves)
  • Jupyter Notebook (training & evaluation)
  • HTML5 canvas + JavaScript (interactive demo)
  • NASA MDP datasets (PROMISE repository)

Dataset & model details

  • Dataset: NASA Metrics Data Program datasets via the PROMISE repository — CM1 (498 modules), KC1 (2,109 modules), KC2, PC1 and JM1 (10,885 modules); each module described by McCabe (LOC, v(g), ev(g), iv(g)) and Halstead (n, v, l, d, i, e, b, t) metrics with a binary defective/clean label.
  • Task: Binary classification; input = static code-metric vector per module, output = P(defective).
  • Model: Random forest (200 trees, class-weighted), with log-transformed skewed metrics; hyperparameters selected by stratified cross-validation.
  • Metrics: AUC ≥ 0.75 within-project (design target for the built-to-order training run), plus precision/recall at the operating threshold and cross-project AUC. Published defect-prediction studies report AUC around 0.70–0.80 on these datasets; no figure is claimed as measured until the training run is executed for the order.
Delivery information

Built-to-order project. Delivery timeline is shared after order confirmation based on current queue.

Support terms

Complete documentation, setup guide, and viva preparation included. Support for setup and explanation provided.

Download abstract (PDF)

Related guides

All guides
Illustration of object tracking showing video frames with bounding boxes and persistent ID labels following people and vehicles, comparing motion prediction and appearance matching.B.E./B.Tech Computer Science and Electronics students building video analytics projects — people counting, vehicle tracking, sports analysis — who have detection working and need

Object Tracking: DeepSORT and ByteTrack Explained

Detection finds objects per frame; tracking keeps their identities across frames. This guide explains tracking-by-detection, Kalman motion models, DeepSORT's appearance embeddings vs ByteTrack's low-confidence box recovery, tracking metrics (HOTA, IDF1, ID switches), and the tuning parameters that determine real-world quality.

Read guide
Illustration of image segmentation showing U-Net's U-shaped encoder-decoder with skip connections producing pixel masks, alongside Mask R-CNN detecting instances with masks.B.E./B.Tech Computer Science and AI/ML students moving from image classification or detection to pixel-level understanding — medical imaging, defect detection, autonomous driving

Image Segmentation: U-Net and Mask R-CNN

When projects need pixel-level answers, segmentation delivers. This guide explains semantic vs instance vs panoptic segmentation, U-Net's encoder-decoder with skip connections, Mask R-CNN's parallel mask head, Dice and IoU evaluation, paired augmentation, and how to choose the right architecture for your data and question.

Read guide
Illustration of Whisper speech-to-text showing sound waves flowing into a neural network and emerging as transcribed text with timestamps and speaker labels.B.E./B.Tech Computer Science and AI/ML students adding speech-to-text to projects — voice assistants, meeting transcription, accessibility tools

Whisper for Speech-to-Text in Student Projects

Whisper transcribes speech in dozens of languages with no training required. This guide covers how it works, choosing among model sizes, running it locally with faster-whisper, handling hour-long audio, timestamps and speaker diarization, multilingual quirks, and honest evaluation with word error rate.

Read guide
Get a quotation