程序流程图:
K-means核心功能函数,首先,随机选择K-中心点(中心点坐标为簇中所有点的x坐标的平均值,y坐标的平均值,该点用于记录位置,不属于原始数据集);循环判断中心点是否不变,若是,将二维点对信息写入clustering文件,程序结束。否则,对于每个二维数据点,选择与其距离最近的中心点,将点cluster编号更新为中心点的cluster编号。然后对于K-簇,重新计算K-中心点,进入下一个循环判断。
计算簇中心是否不变可以采用SSE方式,具体实现代码中已给出,或者直接循环运行多次(不推荐)。
/*
K-means Algorithm
15S103182
Ethan
*/
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <ctime>
#include <cstdlib>
#include <limits>
using namespace std;
/* run this program using the console pauser or add your own g