Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Using code change types in an analogy-based classifier for short-term defect prediction

Using code change types in an analogy-based classifier for short-term defect prediction

by Josee Tasse

More Decks by PROMISE'13: The 9th International Conference on Predictive Models in Software Engineering

Other Decks in Research

Transcript

  1. Using  code  change  types            

                  in  an  analogy-­‐based  classifier       for  short-­‐term  defect  predic7on   Josée  Tassé  
  2. Current  approaches  –  bug  predic7ons   •  Mostly  long-­‐term:  predic7ons

     on  which  files   will  have  bugs  discovered  a?er  release     •  Few  short-­‐term  ones:   –  Predic7ons  at  the  change  level  [Kim/Whitehead/ Zhang]   –  Maintaining  top  10%  list  of  most  likely  error-­‐prone   files  (most  recently  created/changed/fixed)  [Kim/ Zimmermann/Whitehead/Zeller]   PROMISE'13  -­‐-­‐  Josée  Tassé  
  3. Problem  tackled   •  Idea:  Give  warning  when  a  sudden

     burst  of   modifica7ons  in  one  file  increases  the  chances   of  this  file  being  buggy                                Short-­‐term  predic3on     •  Advantage:  can  take  immediate  ac7on  instead   of  wai7ng  un7l  final  tes7ng  stages   PROMISE'13  -­‐-­‐  Josée  Tassé  
  4. Our  main  driver   •  Changes  sca[ered  in  mul7ple  files

     [Hassan]:   –  Increase  complexity  of  project   –  More  difficult  to  keep  track  of  progress   –  Reduces  understanding  of  the  code                                      Increased  chance  of  bugginess   •  Our  assump7on:  changes  sca[ered  inside   single  file  will  have  similar  effect   PROMISE'13  -­‐-­‐  Josée  Tassé  
  5. Proposed  bug  predictor   •  Based  on:     – 

    Type  of  changes  made  (localized  or  sca[ered,  minor   or  massive)   –  Number  of  changes  within  a  short  period  of  7me   –  File  size   •  Idea:  Tag  a  file  as  error-­‐prone  if  it  went   through  similar  changes  as  another  file  in  the   past,  which  did  end  up  being  buggy  a?er  the   changes   PROMISE'13  -­‐-­‐  Josée  Tassé  
  6. Characterizing  file  change   @@  -­‐437,6  +439,10  @@    

     widgetLabel  =  new  JLabel(jEdit.getProperty("widgetLabel"));          String[]  allWidgets  =  ServiceMng.getServiceNames("StatusWidget");   +  Arrays.sort(allWidgets);   +         +  boolean  valueIsWidget  =  Arrays.binarySearch(allWidgets,  value)  >=0;   +            Vector<String>  widgets  =  new  Vector<String>(allWidgets.length);      Set<String>  usedWidget  =  new  HashSet<String>(listModel.getSize());      for  (int  i  =  0;  i  <  listModel.getSize();  i++)   @@  -­‐445,7  +451,7  @@      }      for  (String  widget  :  allWidgets)      {   -­‐    if  (!usedWidget.contains(widget))   +    if  (!usedWidget.contains(widget)  ||  widget.equals(value))          widgets.add(widget);      }      widgetCombo  =  new  JComboBox(widgets);   PROMISE'13  -­‐-­‐  Josée  Tassé  
  7. Characterizing  file  change   @@  -­‐437,6  +439,10  @@    

     widgetLabel  =  new  JLabel(jEdit.getProperty("widgetLabel"));          String[]  allWidgets  =  ServiceMng.getServiceNames("StatusWidget");   +  Arrays.sort(allWidgets);   +         +  boolean  valueIsWidget  =  Arrays.binarySearch(allWidgets,  value)  >=0;   +            Vector<String>  widgets  =  new  Vector<String>(allWidgets.length);      Set<String>  usedWidget  =  new  HashSet<String>(listModel.getSize());      for  (int  i  =  0;  i  <  listModel.getSize();  i++)   @@  -­‐445,7  +451,7  @@      }      for  (String  widget  :  allWidgets)      {   -­‐    if  (!usedWidget.contains(widget))   +    if  (!usedWidget.contains(widget)  ||  widget.equals(value))          widgets.add(widget);      }      widgetCombo  =  new  JComboBox(widgets);   2  blocks   PROMISE'13  -­‐-­‐  Josée  Tassé  
  8. Characterizing  file  change   @@  -­‐437,6  +439,10  @@    

     widgetLabel  =  new  JLabel(jEdit.getProperty("widgetLabel"));          String[]  allWidgets  =  ServiceMng.getServiceNames("StatusWidget");   +  Arrays.sort(allWidgets);   +         +  boolean  valueIsWidget  =  Arrays.binarySearch(allWidgets,  value)  >=0;   +            Vector<String>  widgets  =  new  Vector<String>(allWidgets.length);      Set<String>  usedWidget  =  new  HashSet<String>(listModel.getSize());      for  (int  i  =  0;  i  <  listModel.getSize();  i++)   @@  -­‐445,7  +451,7  @@      }      for  (String  widget  :  allWidgets)      {   -­‐    if  (!usedWidget.contains(widget))   +    if  (!usedWidget.contains(widget)  ||  widget.equals(value))          widgets.add(widget);      }      widgetCombo  =  new  JComboBox(widgets);   PROMISE'13  -­‐-­‐  Josée  Tassé   4  modified  lines  in  block  1   2  modified  lines  in  block  2   Average  =  3  
  9. Characterizing  file  change   @@  -­‐437,6  +439,10  @@    

     widgetLabel  =  new  JLabel(jEdit.getProperty("widgetLabel"));          String[]  allWidgets  =  ServiceMng.getServiceNames("StatusWidget");   +  Arrays.sort(allWidgets);   +         +  boolean  valueIsWidget  =  Arrays.binarySearch(allWidgets,  value)  >=0;   +            Vector<String>  widgets  =  new  Vector<String>(allWidgets.length);      Set<String>  usedWidget  =  new  HashSet<String>(listModel.getSize());      for  (int  i  =  0;  i  <  listModel.getSize();  i++)   @@  -­‐445,7  +451,7  @@      }      for  (String  widget  :  allWidgets)      {   -­‐    if  (!usedWidget.contains(widget))   +    if  (!usedWidget.contains(widget)  ||  widget.equals(value))          widgets.add(widget);      }      widgetCombo  =  new  JComboBox(widgets);   Block  1:  lines  439  to  448   Block  2:  lines  451  to  457   PROMISE'13  -­‐-­‐  Josée  Tassé  
  10. Characterizing  file  change   @@  -­‐437,6  +439,10  @@    

     widgetLabel  =  new  JLabel(jEdit.getProperty("widgetLabel"));          String[]  allWidgets  =  ServiceMng.getServiceNames("StatusWidget");   +  Arrays.sort(allWidgets);   +         +  boolean  valueIsWidget  =  Arrays.binarySearch(allWidgets,  value)  >=0;   +            Vector<String>  widgets  =  new  Vector<String>(allWidgets.length);      Set<String>  usedWidget  =  new  HashSet<String>(listModel.getSize());      for  (int  i  =  0;  i  <  listModel.getSize();  i++)   @@  -­‐445,7  +451,7  @@      }      for  (String  widget  :  allWidgets)      {   -­‐    if  (!usedWidget.contains(widget))   +    if  (!usedWidget.contains(widget)  ||  widget.equals(value))          widgets.add(widget);      }      widgetCombo  =  new  JComboBox(widgets);   Block  1:  lines  439  to  448   Block  2:  lines  451  to  457   Distance  between  blocks  =  3   PROMISE'13  -­‐-­‐  Josée  Tassé  
  11. Change  Type  metrics   •  Metrics  for  each  file  change:

     nbBlocks,   avgModifs,  avgDist  (standardized  on  [0,1]  scale)   •  Use  clustering  to  find  types  of  changes  à  JEdit:   –  Type  A:  small  modifica7ons  in  single  block   (0.00,    0.17,    0.00)   –  Type  B:  average-­‐size  modifica7ons  in  few  dispersed  blocks   (0.29,    0.24,    0.47)   –  Type  C:  average-­‐size  modif.  in  many  dispersed  blocks   (0.61,    0.24,    0.46)   –  Type  D:  massive  modifica7ons  in  single  block   (0.00,    0.72,    0.00)   PROMISE'13  -­‐-­‐  Josée  Tassé  
  12. Building  “cases”  for  comparison   •  Group  changes  to  single

     file  into  7me  intervals   of  consecu7ve  changes:   changes  occurring  in  consecu7ve  weeks,  with  no   more  than  one  week  with  no  changes  in  between     •  Metrics  for  each  7me  interval  (or  “case”):   –  File  size  in  LOC   –  Number  of  changes  in  the  7me  interval   –  Propor7on  of  each  type  of  change  (Type  A  to  D)   during  the  interval  (e.g.,  [50%,  25%,  0%,  25%]  )   PROMISE'13  -­‐-­‐  Josée  Tassé  
  13. Idea  of  Analogy-­‐based  classifiers   •  Build  a  pool  of

     past  cases  (all  7me  intervals  for   all  files),  for  which  enough  7me  has  past  to   tag  it  “buggy”  or  “bug-­‐free”   •  When  new  change  burst  comes  up,  measure  it   and  compare  it  with  previous  cases   •  If  new  case  is  more  like  past  buggy  cases,  tag   it  as  “buggy”,  otherwise  as  “bug-­‐free”     PROMISE'13  -­‐-­‐  Josée  Tassé  
  14. Comparing  two  cases   (,)=  ​(,)+ℎ(,)+ℎ(,)/3      where  :

      (,)=​|.−.|/max(.,.)      ℎ(,)=​|​​log↓10 ⁠(.) −​​log↓10 ⁠(.) |/​​ log↓10 ⁠()       ℎ(,)=​∑  ℎ    ↑▒|.() −.()| /ℎ    PROMISE'13  -­‐-­‐  Josée  Tassé  
  15. Individual  comparison  approach   •  Construct  a  subset  of  the

     nearest  cases  from   the  pool  (the  ones  within  0.1  of  the  minimum   distance  found)     •  Calculate  the  percentage  of  buggy  cases  in  the   subset     •  Tag  new  case  as  buggy  if  the  percentage  is   significantly  higher  (e.g.  50%  higher)  than  such   percentage  on  the  en7re  pool   PROMISE'13  -­‐-­‐  Josée  Tassé  
  16. Cluster  comparison  approach   •  Build  clusters  of  buggy  cases

     and  bug-­‐free   cases  from  the  pool     •  When  a  new  case  comes  up,  calculate  its   distance  to  each  cluster  (using  same  distance   formula)     •  Use  the  tag  of  the  closest  cluster  as  the  tag  of   the  new  case   PROMISE'13  -­‐-­‐  Josée  Tassé  
  17. Ini7al  evalua7on  -­‐  JEdit   Hit  rate   False  alarm

     rate   Individual  comparison   43%   18%   Cluster  comparison   55%   23%   Naïve  Bayes   23%   6%   BayesNet   11%   3%   OneR   8%   1%   Random  Tree   11%   6%   Random  Forest   9%   4%   Mul7-­‐layer  Perceptron   8%   3%   Indiv.  –  no  change  type   34%   15%   Cluster  –  no  change  type   18%   9%   PROMISE'13  -­‐-­‐  Josée  Tassé  
  18. Ini7al  evalua7on  -­‐  JEdit   Hit  rate   False  alarm

     rate   Individual  comparison   43%   18%   Cluster  comparison   55%   23%   Naïve  Bayes   23%   6%   BayesNet   11%   3%   OneR   8%   1%   Random  Tree   11%   6%   Random  Forest   9%   4%   Mul7-­‐layer  Perceptron   8%   3%   Indiv.  –  no  change  type   34%   15%   Cluster  –  no  change  type   18%   9%   PROMISE'13  -­‐-­‐  Josée  Tassé  
  19. Ini7al  evalua7on  -­‐  JEdit   Hit  rate   False  alarm

     rate   Individual  comparison   43%   18%   Cluster  comparison   55%   23%   Naïve  Bayes   23%   6%   BayesNet   11%   3%   OneR   8%   1%   Random  Tree   11%   6%   Random  Forest   9%   4%   Mul7-­‐layer  Perceptron   8%   3%   Indiv.  –  no  change  type   34%   15%   Cluster  –  no  change  type   18%   9%   PROMISE'13  -­‐-­‐  Josée  Tassé  
  20. Conclusion   •  Novel  approach  for  short-­‐term  predic7on,   using

     types  of  changes  and  past  experience     •  Ini7al  evalua7on  shows:   – Analogy-­‐based  model  beAer  than  other  data   mining  ones  for  such  case   – Change  type  does  help  in  building  a  be[er   predictor   PROMISE'13  -­‐-­‐  Josée  Tassé  
  21. Future  work   •  Further  valida7on     •  Incorpora7on

     of  other  predictor  variables     •  Improved  distance  measurement   PROMISE'13  -­‐-­‐  Josée  Tassé