- Python Deep Learning
- Ivan Vasilev Daniel Slater Gianmario Spacagna Peter Roelants Valentino Zocca
- 346字
- 2021-07-02 14:31:01
K-means
K-means is a clustering algorithm that groups the elements of a dataset into k distinct clusters (hence the k in the name). Here is how it works:
- Choose k random points, called centroids, from the feature space, which will represent the center of each of the k clusters.
- Assign each sample of the dataset (that is, each point in the feature space) to the cluster with the closest centroid.
- For each cluster, we recomputed new centroids by taking the mean values of all the points in the cluster.
- With the new centroids, we repeat steps 2 and 3 until the stopping criteria is met.
The preceding method is sensitive to the initial choice of random centroids and it may be a good idea to repeat it with different initial choices. It's also possible for some centroids to not be close to any of the points in the dataset, reducing the number of clusters down from k. Finally, it's worth mentioning that if we used k-means with k=3 on the Iris dataset, we may get different distributions of the samples compared to the distribution of the decision tree that we'd introduced. Once more, this highlights how important it is to carefully choose and use the correct machine learning method for each problem.
Now let's discuss a practical example that uses k-means clustering. Let's say a pizza-delivery place wants to open four new franchises in a city, and they need to choose the locations for the sites. We can solve this problem with k-means:
- Find the locations where pizza is ordered from most often and these will be our data points.
- Choose four random points where the site locations will be located.
- By using k-means clustering, we can identify the four best locations that minimize the distance to each delivery place:

- C語言程序設(shè)計實踐教程(第2版)
- Web應(yīng)用系統(tǒng)開發(fā)實踐(C#)
- 案例式C語言程序設(shè)計
- 復(fù)雜軟件設(shè)計之道:領(lǐng)域驅(qū)動設(shè)計全面解析與實戰(zhàn)
- Mastering JavaScript Object-Oriented Programming
- 單片機(jī)C語言程序設(shè)計實訓(xùn)100例:基于STC8051+Proteus仿真與實戰(zhàn)
- Web開發(fā)的貴族:ASP.NET 3.5+SQL Server 2008
- OpenCV 3和Qt5計算機(jī)視覺應(yīng)用開發(fā)
- Linux網(wǎng)絡(luò)程序設(shè)計:基于龍芯平臺
- 精通網(wǎng)絡(luò)視頻核心開發(fā)技術(shù)
- 基于Swift語言的iOS App 商業(yè)實戰(zhàn)教程
- HTML5從入門到精通 (第2版)
- 編程與類型系統(tǒng)
- Python Data Structures and Algorithms
- 劍指大數(shù)據(jù):企業(yè)級數(shù)據(jù)倉庫項目實戰(zhàn)(在線教育版)