Defect Prediction Model

Simulation
Introduced by
Thomas Ostrand, Elaine Weyuker, Robert Bell
Year
2005
Type
machine learning model
Family
Quality prediction

What does it do?

Defect prediction models estimate where software faults are likely to occur, using statistical or machine learning models trained on code metrics and historical defect records.

Ostrand, Weyuker, and Bell (2005) used negative binomial regression to predict the number of faults in each file of the next release of large industrial systems, while Nagappan, Ball, and Zeller (2006) related code complexity metrics to post-release failures. Teams use the resulting rankings to direct testing, review, and refactoring effort.

The intuition behind the method

Software faults are not spread evenly across a system. The cited studies relate fault occurrence to code complexity and to modification history: Nagappan et al. found failure-prone entities to be statistically correlated with complexity measures, and Ostrand et al. used the fault and modification history of each file from earlier releases. A model learns these relationships from past data and applies them to the current code, so that limited testing effort can go first to the files it ranks highest.

History

Ostrand, Weyuker, and Bell (2005) developed a negative binomial regression model to predict the expected number of faults in each file of the next release, using the file's code and its fault and modification history from earlier releases. They applied it to two large industrial systems. Nagappan, Ball, and Zeller (2006) studied the post-release defect history of five Microsoft software systems and used principal component analysis on code metrics to build regression models of post-release defect likelihood. Menzies, Dekhtyar, Di Stefano, and Greenwald (2007) responded to a debate about how precision and recall should be judged for defect predictors.

When to use it

Choose defect prediction when a team has records of multiple releases of the same system, including fault records and modification history, and when test or review capacity is too limited to cover every file. The cited studies apply the method in different ways. Ostrand et al. applied their model within each of two large industrial systems across successive releases: one had 17 consecutive quarterly releases over 4 years, and the other had nine releases over 2 years. Nagappan et al. studied the post-release defect histories of five Microsoft software systems and built regression models from code metrics. Do not rely on it where defect records are missing or unreliable, because the model is trained on those labels. Transfer to a different system is weaker than within-system prediction: Nagappan et al. report that predictors can apply to new, similar projects, so validate carefully before reusing a model on markedly different systems. Do not use a ranking as the sole basis for a release decision when the goal is certainty about individual modules.

Limitations and considerations

  • Nagappan et al. found no single set of complexity metrics that works as a universally best defect predictor, so the feature set must be tested against local data.
  • Files selected to maximise predicted fault counts differ from files with the highest fault density. In Ostrand et al., the top 20 percent by predicted density held an average of 62 percent of faults, and those files covered a much smaller share of the code than the count-based selection.
  • A ranking indicates where faults are more likely, not whether a particular module is faulty; individual module predictions are unreliable.
  • Predictions depend on how defects were recorded in the historical data, so differences in fault definition between projects limit direct comparison of results.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • In the two industrial systems studied by Ostrand et al., the 20 percent of files with the highest predicted fault counts contained between 71 and 92 percent of detected faults, averaging 83 percent across releases.
  • Predicts fault counts per file from measurable code metrics and fault history, giving a ranking that can be used to allocate a fixed testing budget.
  • Nagappan et al. show that failure-prone entities correlate with code complexity measures, which makes the input features concrete and inspectable.
  • A simplified version of the Ostrand et al. predictor still selected files holding on average 73 and 74 percent of faults in the two systems, so the approach does not depend entirely on a complex feature set.

Applications

  • Ranking files for targeted testing within a release, as in Ostrand et al., where the top 20 percent of files by predicted fault count contained most of the faults.
  • Choosing between a count-based and a density-based ranking, since the two identify different files and have different coverage of the codebase.
  • Directing code review and refactoring toward complex modules, which Nagappan et al. associate with failure-prone code, and toward files with a history of faults and modifications, which the Ostrand et al. model uses as predictors.
  • Reusing a predictor from one project on a similar new project, as Nagappan et al. suggest is possible, after checking its accuracy on local data.

How it works

How it works

1

Collect historical data from several releases of the same system: fault records, the modification history of each file, and code metrics for each file. Ostrand, Weyuker, and Bell (2005) used the code of each file in the current release together with the fault and modification history of that file from earlier releases.

2

For each file in the current release, compute its code metrics and attach its fault and modification history from earlier releases as predictors. Later variants may add other engineered features, such as change frequency, author experience, or test coverage, but these are not part of the original study and should be validated on local data.

3

Fit a negative binomial regression of the number of faults recorded per file in the next release on these predictors. Because the response is a count, the fitted model gives an expected number of faults for each file.

4

Apply the fitted model to the current release to obtain an expected fault count for every file, then rank files from highest to lowest. Classifiers such as logistic regression, random forest, or SVM can also be trained to predict whether a module is defective. These are alternative variants, not the original method, and their output is a defect label or probability rather than an expected fault count.

5

Use the ranking to direct testing and review effort to the top-ranked files. In Ostrand et al., the 20 percent of files with the highest predicted fault counts contained between 71 and 92 percent of the faults detected in each release. Validate predictions against faults found later, and communicate the uncertainty of the estimates to stakeholders.

Common pitfalls

  • Judging a model by precision alone. Menzies et al. (2007) argue that when non-defective modules greatly outnumber defective ones, higher recall often requires accepting lower precision, and that low-precision detectors can still be useful.
  • Treating predicted fault counts or probabilities as measured facts. They are estimates from past releases and should guide, not replace, judgement.
  • Reusing a model fitted to one system without recalibration on local fault records, especially after major architectural or team changes that alter the relationship between metrics and faults.
  • Selecting modules by predicted fault density when the goal is to find the most faults. Ostrand et al. show that the two criteria favour different files.

Frequently asked questions

How much historical data do I need to build a defect prediction model?

The cited studies used multi-release histories: one industrial system had 17 consecutive quarterly releases over 4 years, and another had nine releases over 2 years. The cited sources do not establish a minimum number of modules. Judge data sufficiency by whether each module has reliable fault records across several releases, and test the model's accuracy on held-out data.

Which code metrics are most predictive of defects?

Nagappan et al. found that failure-prone entities are statistically correlated with code complexity measures, but that no single set of complexity metrics is universally the best predictor. Ostrand et al. combined the code of each file with its fault and modification history. The most useful metric set is therefore an empirical question for each system and should be assessed with local data.

Can defect prediction work across projects or programming languages?

Nagappan et al. report that predictors obtained from one project can also be significant for new, similar projects. Transfer to markedly different systems is not shown by the cited sources and should be validated locally. Transfer across programming languages is not examined in the cited studies and should be treated as untested.

How do I handle severely imbalanced data where few modules contain defects?

Use an evaluation that does not rely on accuracy, since a model that labels every module as defect-free can appear accurate. Menzies et al. note that with large non-defective to defective ratios, higher recall often requires accepting lower precision, so choose the operating point by the trade-off that matters for the decision. The cited sources do not evaluate resampling or class-weighting methods, so any such adjustment should be checked on held-out data.

Related methods

Sources

  1. Ostrand, T. J., Weyuker, E. J., & Bell, R. M. (2005). Predicting the location and number of faults in large software systems. IEEE Transactions on Software Engineering, 31(4), 340–355.

    Open DOI reference
  2. Nagappan, N., Ball, T., & Zeller, A. (2006). Mining metrics to predict component failures. In Proceedings of the 28th International Conference on Software Engineering (pp. 452–461).

    Open DOI reference
  3. Menzies, T., Greenwald, J., & Russ, P. (2007). Problems with precision: A response to comments on 'Data mining static code attributes to learn defect predictors'. IEEE Transactions on Software Engineering, 33(9), 637–640.

    Open DOI reference