public override void Init(IRepository repository, IEnumerable <string> releases) { base.Init(repository, releases); double dd = repository.SelectionDSL() .Commits().TillRevision(PredictionRelease) .Modifications().InCommits() .CodeBlocks().InModifications().CalculateDefectDensity(PredictionRelease); context.SetCommits(null, PredictionRelease); regression = new LinearRegression(); foreach (var file in GetFilesInRevision(PredictionRelease)) { double ddForFile = repository.SelectionDSL() .Commits().TillRevision(PredictionRelease) .Files().IdIs(file.ID) .Modifications().InCommits().InFiles() .CodeBlocks().InModifications().CalculateDefectDensity(PredictionRelease); if (ddForFile >= dd) { context.SetFiles(e => e.IdIs(file.ID)); regression.AddTrainingData( GetPredictorValuesFor(context)[0], NumberOfFixedDefectsForFile(file.ID) ); } } regression.Train(); }
private void TestLinearRegression() { LinearRegression linearRegression = new LinearRegression(trainingEpochs, learningRate); linearRegression.Train(dataX, dataY); (float[] results, float optimalWeights, float optimalBias) = linearRegression.Predict(testX); //analytical solution coefficientVector=(X'*X)*X'*Y where X is the inputX with ones in the first column and Y is inputY: bias=0.7988 and weight=0.2516 Assert.Equal(0.309068531, optimalWeights, 6); Assert.Equal(0.373608261, optimalBias, 6); }
public override void Init(IRepository repository, IEnumerable<string> releases) { base.Init(repository, releases); double dd = repository.SelectionDSL() .Commits().TillRevision(PredictionRelease) .Modifications().InCommits() .CodeBlocks().InModifications().CalculateDefectDensity(PredictionRelease); context.SetCommits(null, PredictionRelease); regression = new LinearRegression(); foreach (var file in GetFilesInRevision(PredictionRelease)) { double ddForFile = repository.SelectionDSL() .Commits().TillRevision(PredictionRelease) .Files().IdIs(file.ID) .Modifications().InCommits().InFiles() .CodeBlocks().InModifications().CalculateDefectDensity(PredictionRelease); if (ddForFile >= dd) { context.SetFiles(e => e.IdIs(file.ID)); regression.AddTrainingData( GetPredictorValuesFor(context)[0], NumberOfFixedDefectsForFile(file.ID) ); } } regression.Train(); }