Question: You are to create a program using Python that does the following: 1 . Asks the user for the number of clusters. This is the

You are to create a program using Python that does the following:
1. Asks the user for the number of clusters. This is the parameter k that will be used for k-means.
2. Reads the input file (prog2-input-data.txt) and stores the points into a list
3. Applies the k-means algorithm to find the cluster for each point.
4. Displays the points that each cluster contains after each iteration of the algorithm
5. Writes the final cluster assignments to the screen and the output file (prog2-output-data.txt).
YOU CANNOT USE ANY PYTHON PACKAGES FOR THIS PROGRAM (NUMPY, PANDAS, ...)- NO IMPORT STATEMENTS.
Additional Requirements
1. The name of your source code file should be kMeans.py. All your code should be within a single file.
2. Your code should follow good coding practices, including good use of whitespace and use of both inline
and block comments.
3. You need to use meaningful identifier names that conform to standard naming conventions.
4. At the top of each file, you need to put in a block comment with the following information: your name,
date, course name, semester, and assignment name.
5. The output of your program should exactly match the sample program output given at the end. That is,
for same input, it should generate the same output. Note that I may use other test cases for grading your
program and your code needs to work correctly in all cases.
Data File Format
Let N be the number of points and Pi to be the value of point i. The input file should be of the following format:
P1
P2
...
PN
Example:
1.2
2.1
4.56
2.113
2.2
The name of the input file is always:
prog2-input-data.txt
What to Turn In
You will turn in a screenshot of your output and a single kMeans.py file using BlackBoard.
HINTS
Make use of list comprehensions for reading lines from a file and then converting the strings into a list of
floats.
Use pwd() to check the directory where you should place your input file.
Use a dict data structures for storing centroids and clusters. The centroids dict will be a mapping from
cluster number to centroids. The clusters dict will be a mapping from cluster number to a list of points in
the cluster.

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 Databases Questions!