Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Given the dataset in Figure 1, please illustrate the k-means algorithm step by s

ID: 3602127 • Letter: G

Question

Given the dataset in Figure 1, please illustrate the k-means algorithm step by step. The number of clusters kis set to k = 2 Figure 1. Dataset For your convenience, many copies of the above figures are given as follows. At the centroid update step, please write the coordinates of the updated centroids and use small circles to indicate their locations; and at the cluster assignment step, please use a big circle to cover all data points belonging to each updated centroid. Step 0 has been done for you. Please complete the remaining steps

Explanation / Answer

#include <iostream>
#include <fstream>
#include <cstring>
#include <cctype>
#include <cstdlib>
using namespace std;

int main()
{
    const char filename[] = "input.txt";
    char buffer[16], winner[32], loser[32];
    int winnerScore, loserScore;

    ifstream fin(filename);
    if (!fin)
    {
        cerr << "Unable to open file " << filename << endl;
        exit(1);
    }

    while (!fin.eof())
    {
        // get winner
        fin >> winner;
        if (fin.eof()) break;

        // get next token. Could be score or 2nd part of winner name
        fin >> buffer;

        // If buffer has a comma, then it's a score
        if (strchr(buffer,','))
        {
            winnerScore = atoi(strtok(buffer,","));
        }
        else
        {
            strcat(winner," ");
            strcat(winner,buffer);
            fin >> buffer;
            winnerScore = atoi(strtok(buffer,","));
        }

        // get loser
        fin >> loser;

        // get next token. Could be score or 2nd part of loser name
        fin >> buffer;

        // If first digit is numeric, then it's a score
        if (isdigit(buffer[0]))
        {
            loserScore = atoi(buffer);
        }
        else
        {
            strcat(loser," ");
            strcat(loser,buffer);
            fin >> buffer;
            loserScore = atoi(buffer);
        }
        cout << winner << " over " << loser << ' ' << winnerScore << " to " << loserScore << endl;
    }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote