Question

In C++ program a simple k-means clustering algorithm, kmeans, using the Euclidean distance for 2-dimensional numerical...

In C++ program a simple k-means clustering algorithm, kmeans, using the Euclidean distance for 2-dimensional numerical data. Your program should be executed as follows: kmeans k input.txt where input parameter k > 1 is an integer, specifying the number of clusters. input.txt is an input file containing many 2-dimensional data points in the following format,

274 119

317 144

267 164

233 137

272 99

297 116

268 142

522 286

468 308

441 263


Your program should output a txt file called output.txt, in the following format:
274 119 1

317 144 1

267 164 1

233 137 1

272 99 1

297 116 1

268 142 1

522 286 2

468 308 2

441 263 2

In output.txt, 1 and 2 are cluster labels. Each data point should be labeled using one of the labels from 1 to k. In the above example, there are 10 data points and k = 2

0 0
Add a comment Improve this question Transcribed image text
Answer #1

def EuclideanDistance(x, y):
   S = 0;
   for i in range(len(x)):
       S += math.pow(x[i]-y[i], 2);

   return math.sqrt(S);

Add a comment
Know the answer?
Add Answer to:
In C++ program a simple k-means clustering algorithm, kmeans, using the Euclidean distance for 2-dimensional numerical...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 33 On May 6, Jim Ryan borrowed $14,000 from Lane Bank at 7 % interest. Jim...

    33 On May 6, Jim Ryan borrowed $14,000 from Lane Bank at 7 % interest. Jim plans to repay the loan on March 11. Assume the loan is on ordinary interest. How much will Jim repay on March 11? (Use Days in a year table) (Round your answer to the nearest cent.) Jm repay etbook 7-1 TABLE Exact days-in-a-year calendar (excluding leap year)" Day of month 30 31 30 31 28 31 30 31 31 30 31 31 Dec Mar...

  • need help to complete this java program // add appropriate import statements here. // These imports...

    need help to complete this java program // add appropriate import statements here. // These imports you can leave as is. import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.canvas.Canvas; import javafx.scene.canvas.GraphicsContext; import javafx.scene.paint.Color; import javafx.stage.Stage; /** @author yourAccountNameHere */ public class ConnectTheDots extends Application {            /*     * Do not add code to main(). Add it below in connectTheDots instead.     */     public static void main(String[] args) {         launch(args);     }         /*...

  • In C++ Programming: Using a single for loop, output the even numbers between 2 and 1004...

    In C++ Programming: Using a single for loop, output the even numbers between 2 and 1004 (inclusive) that iterates (loops) exactly 502 times. The outputted numbers be aligned in a table with 10 numbers per row. Each column in the table should be 5 characters wide. Do not nest a loop inside of another loop. Hint: First create and test the code that output the numbers all on one line (the command line will automatically wrap the output to new...

  • If the two signal handling functions in 3000pc were replaced by one function, would there be...

    If the two signal handling functions in 3000pc were replaced by one function, would there be any significant loss of functionality? Briefly explain /* 3000pc.c */ 2 3 4 5 6 7 8 #include <stdio.h> 9 #include <stdlib.h> 10 #include <unistd.h> 11 #include <sys/mman.h> 12 #include <errno.h> 13 #include <string.h> 14 #include <sys/types.h> 15 #include <sys/wait.h> 16 #include <semaphore.h> 17 #include <string.h> 18 #include <time.h> 19 20 #define QUEUESIZE 32 21 #define WORDSIZE 16 22 23 const int wordlist_size =...

  • Please determine the IDENTITY of the unknown compound and explain how each peak / data point...

    Please determine the IDENTITY of the unknown compound and explain how each peak / data point from the following instruments led to that identification. What does the gcms indicate. Thank you very much! (The GCMS data is just a long set of numbers which is why the question appears so long). IR of unknown: NMR unknown Proton Graphs (first is overall graph, others that follow are zoomed in sections): NMR unknown Carbon Graphs (first is overall graph, others that follow...

  • kelly Pitney began her censulting busines, kelly Consulting For egete kelly on April 1, 2019. The...

    kelly Pitney began her censulting busines, kelly Consulting For egete kelly on April 1, 2019. The accoenting cycle Consulting a April, includia financial in this chapter. During Hay kelly Consulting entered inato the follew ing transactiens: Statements, was illestrated May 3 Received cash from clents as an aduance payment for services to be preided and recorded t as onearned fees, 4,500 5, Received cash fram clients on account, 2, 450 9 Paid cash for a news paper advertisement, $225 13....

  • problem: information provided: fill in ALL the empty grey boxes kelly Pitney began her consulting business,...

    problem: information provided: fill in ALL the empty grey boxes kelly Pitney began her consulting business, Kelly Consulting, on April 1, 2015. The accounting cycle - for egete kelly Consulting for April, including financial Statements, was illustrated in this chapter, During Hag Kelly Consulting entered into the following transactions : May 3 . Received cash from clients as an advance payment for services to be provided and recorded it as unearned fees, $ 4,500 5. Received cash from clients on...

  • Code is in C# Your instructor would like to thank to Marty Stepp and Hélène Martin...

    Code is in C# Your instructor would like to thank to Marty Stepp and Hélène Martin at the University of Washington, Seattle, who originally wrote this assignment (for their CSE 142, in Java) This program focuses on classes and objects. Turn in two files named Birthday.cs and Date.cs. You will also need the support file Date.dll; it is contained in the starter project for this assignment. The assignment has two parts: a client program that uses Date objects, and a...

  • HELP needed urgently....Data and question is attacted below..... Thank you in advance there is no data...

    HELP needed urgently....Data and question is attacted below..... Thank you in advance there is no data link fir this data it’s all in photos.... thank you i have already posted the question We were unable to transcribe this imageNo. 2 3 4 5 6 7 8 Working Sector Public Own Public Public Private Public Private Private Own Own Private Public Public Public Private 9 10 11 12 13 Public IS 16 17 18 19 20 21 22 23 24 25...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT