Question: I need help with normalization in java, my method is not properly ignoring zeros and im not sure why, here is the method: protected void

I need help with normalization in java, my method is not properly ignoring zeros and im not sure why, here is the method: protected void normalizeRatingsByUser(List ratings){
for (int user =0; user < ratings.get(0).length; user++){
double sum =0;
int count =0;
for (double[] rating : ratings){
if (rating[user]!=0){
sum += rating[user];
count++;
}
}
if (count >0){
double mean = sum / count;
for (double[] rating : ratings){
if (rating[user]!=0){
rating[user]-= mean;
}
}
}
}
} and here is my unit test: @Test
public void testNormalizationIgnoresZeros(){
Project.SongClusterer clusterer = new Project.SongClusterer();
List ratings = Arrays.asList(
new double[]{0,2,0,4},
new double[]{1,0,3,0}
); and here is the output from the test: "Failed to map supported failure 'org.opentest4j.AssertionFailedError: Ratings should be normalized correctly ignoring zeros. ==> array contents differ at index [3], expected: <2.0> but was: <0.0>' with mapper " please help me fix my normalization im unsure why it wont ignore zeros properly and do not use chatgpt GPT-4 can not solve this problem otherwise i wouldnt be here, will upvote if you can help me get it working!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!