One Step one step Kmeans algorithm research--numpy and matplotlib raw data read and display __ algorithm

Source: Internet
Author: User
Intro

Recently looking at machine learning related video tutorials, which talked about the clustering algorithm through Kmeans, the idea of studying the algorithm and showing it step-by-step through Python is the whole process of the algorithm. principle

The specific principle of kmeans found that a tutorial in the evening showed a clearer picture of Kmeans, as follows: Http://www.csdn.net/article/2012-07-03/2807073-k-means use Python to show

A good data organization and presentation can greatly enhance our understanding of the algorithm, so the first step is how to show a set of basic data. Data Source

Not to create a data source, and took a Chinese university Mooc gave a Kmeans test data: http://www.icourse163.org/learn/BIT-268001?tid=1002001005#/learn/ CONTENT?TYPE=DETAIL&ID=1002613060&CID=1002856188 can also be downloaded from my github: https://github.com/skyztt/ The Kmeans-python.git operation reads the original input through the NumPy You can use Np.loadtxt to read out the file, read the following data (previously did not understand the original data, that the original data only represent y-coordinates, and then find how to reduce the data dimension of the dimensions, but also a more understanding of an API bar, you can convert it through the flatten to one-dimensional data):

[[1.658985  4.285136]
 [ -3.453687  3.424321] [
 4.838138-1.151539]
 ..., 
 [-4.561235- 4.563214]
 [5.461454-5.123464]
 [4.012356-4.985623]]
Show it:
This is shown using Matplot, but here you need to extract the x,y coordinates from the raw data, and then use the NumPy slice: (attached to the previous blog post that was referenced at the time http://blog.csdn.net/liangzuojiayi/article/ details/51534164, one of the pictures is a good illustration of the problem.

Attached code, just a few words original data printing success ~
Import NumPy as NP
import Matplotlib.pyplot as plt

a = Np.loadtxt (". \\testSet.txt")
Plt.scatter (a[:,:1), a[ :, 1:2])
plt.show ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.