Skip to content

Commit

Permalink
Fix RMSE calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
iemre committed May 4, 2019
1 parent 46e407b commit 7f5021e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion AbstractExperiment.m
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ function calculatePredictiveAccuracy(obj)
end

obj.result.MAE = totalError / predictionCount;
obj.result.RMSE = totalSquaredError / predictionCount;
obj.result.RMSE = sqrt(totalSquaredError / predictionCount);
display(obj.result);
end

Expand Down
14 changes: 13 additions & 1 deletion tests/AbstractExperimentTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,19 @@ function shouldSetDefaultMinAndMaxRatingsCorrectly(testCase)

testCase.verifyEqual(exp.maxRating, 5);
testCase.verifyEqual(exp.minRating, 1);
end
end

function shouldCalculateRmseAndMaeCorrectly(testCase)
baseSet = [4 0 3 5; 0 5 4 0; 5 4 2 0; 2 4 0 3; 3 4 5 0];
testSet = [0 2 0 0; 1 0 0 0; 0 0 0 3; 0 0 1 0; 0 0 0 2];
knnTest = ItemBasedKNN.createNewWithDatasets(baseSet, testSet);
knnTest.setSimilarityCalculatorTo(Similarity.COSINE);
knnTest.k = 2;
knnTest.calculatePredictiveAccuracy;

testCase.verifyEqual(knnTest.result.MAE, 1.9250, 'AbsTol', 0.001);
testCase.verifyEqual(knnTest.result.RMSE, 2.1106, 'AbsTol', 0.001);
end

end

Expand Down
2 changes: 1 addition & 1 deletion tests/ItemBasedKNNTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function shouldCalculatePredictionCorrectlyUsingCosine(testCase)
baseSet = [4 0 3 5; 0 5 4 0; 5 4 2 0; 2 4 0 3; 3 4 5 0];
testSet = zeros(5, 4);
knnTest = ItemBasedKNN.createNewWithDatasets(baseSet, testSet);
knnTest.setSimilarityCalculatorTo(Similarity.COSINE)
knnTest.setSimilarityCalculatorTo(Similarity.COSINE);
knnTest.k = 2;
prediction = knnTest.makePrediction(3, 4);

Expand Down

0 comments on commit 7f5021e

Please sign in to comment.