Question: I need help properly updating centroids in Java, here is my current method: protected List updateCentroids ( List ratings, double [ ] [ ] centroids,
I need help properly updating centroids in Java, here is my current method:
protected List updateCentroidsList ratings, double centroids, int assignments, int K
double newCentroids new doubleKratingsgetlength;
int counts new intK;
for int i ; i ratings.size; i
int cluster assignmentsi;
countscluster;
for int j ; j ratings.getilength; j
newCentroidsclusterj ratings.getij;
for int i ; i K; i
if countsi
for int j ; j newCentroidsilength; j
newCentroidsij countsi;
centroidsi newCentroidsi;
return Arrays.asListnewCentroids;
and here is the unit test: @Test
public void testCentroidsUpdateCorrectly
Project.SongClusterer clusterer Project.SongClusterer;
List ratings Arrays.asList
new double
new double
new double
;
double initialCentroids ;
int assignments ;
List updatedCentroids clusterer.updateCentroidsratings initialCentroids, assignments, ;
double expectedCentroids ;
for int i ; i updatedCentroids.size; i
assertArrayEqualsexpectedCentroidsi updatedCentroids.geti "Centroids should be updated correctly.";
and finally, when i run it against the test it says "Failed to map supported failure 'org.opentestjAssertionFailedError: Centroids should be updated correctly. array contents differ at index expected: but was: with mapper"
please help me fix this method, and do not use AI gpt does not understand the issue, I will upvote if you can help me get it working properly!
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
