Implement a k-means cluster analysis data mining algorithm

Assignment Help Python Programming
Reference no: EM131732373

PROJECTS

Goals

Use file processing and data mining to discover patterns of earthquake activity around the world over the past year; plot results on a world map.

Practice with
- data mining and file processing
- reading, understanding, and revising a program that has mostly been already written. This will require a thorough understanding of the k-means cluster analysis algorithm and file processing.

Background - Data Mining

In this project we continue to study earthquake activity. We will use a file with data once again obtained from the United States Geological Survey website, about earthquakes of magnitude 5 or greater that have occurred across the planet over the past year (since November 1, 2016).

We will implement a k-means cluster analysis data mining algorithm from Ch. 7 of the text and use it to analyze the earthquake data. We will then use Python turtle graphics to graphically report the earthquake clusters discovered by the k-means algorithm on a world map.

Requirements

Functions to read and process earthquake data saved in a file are adapted from Ch. 7 of the text.

Function readFile is based on the function in ch. 7 of the text (p. 255). You will need to revise it to accommodate the earthquake data file analyzed in this project: the earthquake file we are using has a header line, each line has a return (\n) character, the values are comma (not space) separated, and the longitude and latitude are in different fields ("columns") than the data in the text.

(readFile will be very similar to equake_readf from Project 7-2, except that it will return a dictionary rather than a list.)

Functions euclidD, createCentroids, and createClusters are all copied from Ch. 7 of the text. You will need to add docstrings and helpful in-line comments.

Note that the createClusters function includes code to report the results of the cluster analysis (for c in clusters ...). This is helpful for testing createClusters with a small data dictionary (data file), but you may want to comment this out for the large earthquake file.

visualizeQuakes is based on the function in Ch. 7 of the text. visualizeQuakes in this project has k (the number of clusters) and r (the number of times to repeat cluster analysis) as parameters, along with the dataFile parameter. As in the text, visualizeQuakes should call readFile, createCentroids, and createClusters.

visualizeQuakes will also call a new function, eqDraw, to plot the earthquake data on a world map. visualizeQuakes should return None. You will need to write a docstring and add comments to visualizeQuakes.

eqDraw is a new function that will be called by visualizeQuakes to do the work of plotting the results of the k-means analysis on a world map. eqDraw will have three parameters: k, eqDict, the earthquake data dictionary, and eqClusters, the list of clusters generated for the earthquake data by the k-means cluster analysis.

eqDraw will comprise the drawing code that is included in visualizeQuakes in the text. You should change the screensize method arguments to 1800 and 900, to reflect the size of the world map .gif that we will use. You can also use the anonymous turtle from the turtle module (i.e., you do not need to define quakeT). Tip: include speed('fastest').

Finally, define a main function to assign values to k, r, and f, and call visualizeQuakes. main should return None. Include code in your .py file to call the main function.

Testing your code

doctest.testmod will be useful for testing individual functions. Use small, made-up examples to test each individual function before calling it from another function. Start with a short version of the earthquake file (around 15 lines not including the header should be small enough to understand, but large enough to generate results).

Getting Started

Open a new Python editor window. Save it with the name p8f_equakes_vis.py.

Download the earthquake file (earthquakes.txt) and the world map (worldmap1800_900.gif) you will use for plotting earthquake points. Make sure the earthquake and map files are in the same folder as p8f_equakes_vis.py.

This program is somewhat longer than prior programs you have written, but when it is viewed function by function it should not seem so different. A good strategy for implementing a medium-sized project such as this one is to understand the code from the top down, and implement the code from the bottom up, with careful testing of each function at each step.

For example:
Start by carefully reading Ch. 7 of the text and reviewing class notes. When you are comfortable with your understanding of the k-means cluster algorithm, have a closer look at the code that is given in Ch. 7 to implement the algorithm. Type the code into a Python file, one function at a time.

For each auxiliary cluster algorithm function in turn (euclidD, createCentroids and createClusters), write the docstring for the function.

Test each individual function to make sure you understand and trust the function. Create your own small test dictionaries to test the functions. Use simple examples, like individual scores or earthquake magnitudes, at first. Then, try examples with two-dimensional points, such as earthquake longitude and latitudes.

Next, write the function that will access earthquake data, readFile. Note that you wrote a similar function for Project 7-2. You may want to start with that function and revise it to access longitude and latitude data (rather than magnitudes) and store the data into a dictionary (rather than a list).

You may want to create a short version of the earthquake files, for testing readFile. The data in the earthquake files is structured as for project 7-2:
time,latitude,longitude,depth,mag,magType,nst,gap,dmin,rms,net,id,updated,place,type,horizontal Error,depthError,magError,magNst,status,locationSource,magSource
2010-07-28T16:12:05.610Z,43.756,-125.815,10,5.2,mwc,193,143.9,,0.93,us,usp000hh0t,2017-
T16:34:36.951Z,"off the coast of Oregon",earthquake,,,,,reviewed,us,gcmt 1993-12-04T22:15:19.720Z,42.2915,-
122.0086667,4.797,5.1,md,126,113,,0.11,uw,uw10316468,2017-04-
13T22:06:07.852Z,"Oregon",earthquake,0.468,0.56,0.04,7,reviewed,uw,uw

The first line of the file is a header, which gives the meaning of each field (column) of the data. The data itself is comma-separated values, with one value (or the empty string) per field. Use the header to determine how to access latitude and longitude data. Note that when you access the earthquake file to create the dictionary, you will need to skip the header to get to the earthquake data.

Next, start putting it together, by writing visualizeQuakes. First call only readFile. When this is working, add a call to createCentroids, and so on.

When visualizeQuakes is working, write the main function and add a call to main
(main()) to your program.

Programming style is important!
Programs are read much more than they are written. All programs must include a program header at the top of the file with
- project identification
- author
- credit for any and all sources of significant help with the project excluding the class text and CIS 210 instructional staff. This includes programming partners, other texts, online information, etc.
- short, precise file description

Also remember to
- include a docstring in every function (type contract, brief description of the function, examples of use)
- use whitespace between operators and operands
- use descriptive variable names
- add appropriate in-code comments (why, not what).

Attachment:- Assignment_Data.rar

Reference no: EM131732373

Questions Cloud

Depreciation on the equipment to produce the board : Calculating Project OCF. Rolston Music Company is considering the sale of a new sound board used in recording studios. The new board would sell for $27,300.
Discuss a drug into an inactive metabolite : The biochemical alteration of a drug into an inactive metabolite, a more soluble compound, a more potent active metabolite
What is the principle strategy of an exclusive : 1. What is the principle strategy of an exclusive (trade) union in order to increase wages of its members?
Why does the demand for labor slope downward : 1) Why does the demand for labor slope downward? 2) Why does the supply curve slope upward?
Implement a k-means cluster analysis data mining algorithm : CIS 210 - define a main function to assign values to k, r, and f, and call visualizeQuakes. main should return None. Include code in your .py file to call
What is the ocf for the project : Calculating Project OCF. H. Cochran, Inc., is considering a new three-year expansion project that requires an initial fixed asset investment of $1,950,000.
Discuss the health care beliefs of the baltic heritage : Mention and discuss the health care beliefs of the Baltic and Brazilian heritage.Discuss and give at least 2 examples of the care beliefs of these two culture.
Examples of competitive markets : Coffee shops in a large city would appear to be examples of competitive markets: there are numerous relatively small sellers, each seller is a price-taker
Determining the floating exchange rate : Suppose that a country has been using a fixed exchange rate for many years. The they decide to switch to a floating exchange rate.

Reviews

len1732373

11/22/2017 1:10:46 AM

(0) Improve the visualization part of the program. For example, the size of the dots might reflect the magnitude of the earthquake. (This would mean information about the magnitude of the earthquake would need to be stored in the datadict.) (1) We've been looking at earthquake data, but there are many other types of data you may be interested in exploring, e.g., newspapers, electoral votes, bus schedules, etc. The CORGIS project includes many data sets many others (sometimes not as clean) are available on the internet. Find a data set that interests you and analyze the data using your data analysis and data mining functions.

len1732373

11/22/2017 1:10:33 AM

All submitted programs should be a good faith attempt to meet the project specification. In particular, to get credit programs must at a minimum include (1) header (title, author, credits, brief description), (2) complete docstrings (type contract, brief description, examples of use) for every function, and (3) code that can be executed (no syntax errors). 20 pts. possible • 12 pts. – 2 pts. per function - Program has correct structure and conforms with CIS 210 style guidelines, including a file header with project identification, author, credits, and short file description at the top of the program file; each function (readFile, euclidD, createCentroids, createClusters, visualizeQuakes, eqDraw) includes a docstring with type contract, description, and simple examples of function use; each function has a return statement; functions have helpful in-line comments as needed; • 8 pts. – 2 pts. per function - Code for new and revised functions (readFile, visualizeQuakes, eqDraw, and main) runs and returns correct results per project specification.

len1732373

11/22/2017 1:10:27 AM

When you have completed all of the problems, use the Save command from the IDLE File menu to save the Editor window as a file with the name p8f_equakes_vis.py. Submit your file via Canvas. You may re-submit the project until the project deadline (as long as the submission link is available). Only the final submission will be graded. Note: as per CIS 210 class policy (see Syllabus), it is not possible to submit a project after the deadline. Projects that are not submitted by the deadline will receive a default grade of zero. Four project grades will be dropped at the end of the term, to provide the flexibility you need for busy weeks, individual technical difficulties, misunderstandings, etc. You do not need to contact the CIS 210 instructional staff about this; it will happen automatically. Even if you do not submit a project, you should complete the project. Always check the solution posted at the class website.

Write a Review

Python Programming Questions & Answers

  Write a python program to implement the diff command

Without using the system() function to call any bash commands, write a python program that will implement a simple version of the diff command.

  Write a program for checking a circle

Write a program for checking a circle program must either print "is a circle: YES" or "is a circle: NO", appropriately.

  Prepare a python program

Prepare a Python program which evaluates how many stuck numbers there are in a range of integers. The range will be input as two command-line arguments.

  Python atm program to enter account number

Write a simple Python ATM program. Ask user to enter their account number, and print their initail balance. (Just make one up). Ask them if they wish to make deposit or withdrawal.

  Python function to calculate two roots

Write a Python function main() to calculate two roots. You must input a,b and c from keyboard, and then print two roots. Suppose the discriminant D= b2-4ac is positive.

  Design program that asks user to enter amount in python

IN Python Design a program that asks the user to enter the amount that he or she has budget in a month. A loop should then prompt the user to enter his or her expenses for the month.

  Write python program which imports three dictionaries

Write a Python program called hours.py which imports three dictionaries, and uses the data in them to calculate how many hours each person has spent in the lab.

  Write python program to create factors of numbers

Write down a python program which takes two numbers and creates the factors of both numbers and displays the greatest common factor.

  Email spam filter

Analyze the emails and predict whether the mail is a spam or not a spam - Create a training file and copy the text of several mails and spams in to it And create a test set identical to the training set but with different examples.

  Improve the readability and structural design of the code

Improve the readability and structural design of the code by improving the function names, variables, and loops, as well as whitespace. Move functions close to related functions or blocks of code related to your organised code.

  Create a simple and responsive gui

Please use primarily PHP or Python to solve the exercise and create a simple and responsive GUI, using HTML, CSS and JavaScript.Do not use a database.

  The program is to print the time

The program is to print the time in seconds that the iterative version takes, the time in seconds that the recursive version takes, and the difference between the times.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd