I have a data set of code patches and the bugs they produce. I'm using ordinary least squares to find a line which predicts bugs based on some attributes about the patch, such as the department which produced the code, how many issues were found in design, etc.
One thing is that the patches vary in size, and larger patches will (obviously) create more bugs. I'm trying to think of how I should handle this, and I came up with several options:
- Use patch size (lines of code changed) as an independent variable. The problem with this is that I think I really want to predict defect "density". E.g. the Sales department might cause one bug every 15 lines of code, but the shipping people cause one every 30 lines of code. So I would need a variable like "department * lines of code changed", which I worry is more sensitive to overfitting.
- Break it into samples of equal size. E.g. if a change to 10 lines of code caused 2 bugs, I pretend that this was actually 10 changes, each of which caused .2 bugs.
- Divide through by the size and then weight by the size. i.e. minimize $\sum w_i(\frac{y_i}{w_i} - f(\vec{x_i}))^2$.
Are any of these preferable, or is there another option I should be using? I assume this must be a pretty standard problem to have, but I haven't been able to find anything online.