当前位置: 首页 > news >正文

模板网站如何快速交付给客户售卖链接

模板网站如何快速交付给客户,售卖链接,wordpress lens 主题,网站自动推广软件计算数据集中的元素与各个簇的中心的距离&#xff0c;将它赋给最近的簇&#xff0c;然后重新计算每个簇的平均值&#xff0c;再将元素按离平均值点最近的原则重新分配直到没有出现重新分配 该算法要事先给出k的值&#xff0c;即划分为几个簇。 vector<int> datoclu(dat…

 计算数据集中的元素与各个簇的中心的距离,将它赋给最近的簇,然后重新计算每个簇的平均值,再将元素按离平均值点最近的原则重新分配直到没有出现重新分配

该算法要事先给出k的值,即划分为几个簇。

vector<int> datoclu(data.size(), -1);用这个来标记每个数据在哪个簇中。

#include <fstream>
#include <sstream>
#include <vector>
#include <iostream>using namespace std;struct Point
{double x;double y;
};double distance(const Point& a, const Point& b)
{return sqrt(pow(a.x - b.x, 2) + pow(a.y - b.y, 2));
}vector<int> KMeans(vector<Point>& data, int k, int maxIterations)
{vector<Point> centroids(k);for (int i = 0; i < k; i++)          {centroids[i] = data[rand() % data.size()];      //随机选择k个类聚中心。0到(data.size()-1)}vector<int> datoclu(data.size(), -1);           //每个数据属于哪个簇bool flag = 0;while (!flag && maxIterations){flag = 1;for (int i = 0; i < data.size(); i++){double minDis = numeric_limits<double>::max();int index = -1;for (int j = 0; j < centroids.size(); j++){double dis = distance(data[i], centroids[j]);if (dis < minDis){minDis = dis;index = j;}}if (datoclu[i] != index)                //记录每个数据属于的聚类中心{datoclu[i] = index;flag = 0;}}vector<Point> newClu(k);vector<int> num(k, 0);//计算每个簇平均值点for (int i = 0; i < data.size(); i++){newClu[datoclu[i]].x += data[i].x;newClu[datoclu[i]].y += data[i].y;num[datoclu[i]]++;}for (int i = 0; i < k; i++){newClu[i].x /= num[i];newClu[i].y /= num[i];}centroids = newClu;maxIterations--;}return datoclu;
}
vector<Point> ReadData(string filename)
{vector<Point> data;ifstream file(filename);if (file.is_open()){string line;while (getline(file, line)){istringstream iss(line);double x, y;string token;Point point;if (getline(iss, token, ',') && istringstream(token) >> point.x &&getline(iss, token, ',') && istringstream(token) >> point.y) {data.push_back(point);}}}else{cout << "open fail";}file.close();return data;
}int main()
{vector<Point> dataset = ReadData("data.txt");vector<int> clusters;int k, maxIterations;cout << "输入簇的个数和最大迭代次数"<<endl;cin >> k >> maxIterations;clusters= KMeans(dataset, k, maxIterations);vector <vector<int>> index(k);for (int j = 0; j < k; j++){for (int i = 0; i < clusters.size(); i++){if (clusters[i] == j){index[j].push_back(i);}}}for (int i = 0; i < index.size(); i++){cout << "{";for (int j = 0; j < index[i].size(); j++){cout << index[i][j]+1;if (j != index[i].size() - 1){cout << ",";}}cout << "}";}
}    

数据集

1.0, 1.0 
2.0, 1.0 
1.0, 2.0  
2.0, 2.0  
4.0, 3.0  
5.0, 3.0  
4.0, 4.0  
5.0,4.0

运行结果 


文章转载自:
http://fogbound.c7510.cn
http://rx.c7510.cn
http://lanky.c7510.cn
http://downstreet.c7510.cn
http://octet.c7510.cn
http://commandant.c7510.cn
http://barbotine.c7510.cn
http://soutache.c7510.cn
http://gnathion.c7510.cn
http://tariffless.c7510.cn
http://inswinger.c7510.cn
http://plethoric.c7510.cn
http://tintinnabulum.c7510.cn
http://dancetty.c7510.cn
http://chorion.c7510.cn
http://kowloon.c7510.cn
http://undertaking.c7510.cn
http://elevenfold.c7510.cn
http://arkose.c7510.cn
http://rumrunner.c7510.cn
http://miosis.c7510.cn
http://conceptualize.c7510.cn
http://intracardial.c7510.cn
http://choiceness.c7510.cn
http://larrigan.c7510.cn
http://infructuous.c7510.cn
http://delusion.c7510.cn
http://fleabane.c7510.cn
http://mendelism.c7510.cn
http://benzophenone.c7510.cn
http://asyntactic.c7510.cn
http://balistraria.c7510.cn
http://strapontin.c7510.cn
http://isotype.c7510.cn
http://plyers.c7510.cn
http://trappy.c7510.cn
http://waterworks.c7510.cn
http://rotisserie.c7510.cn
http://rubberware.c7510.cn
http://oatcake.c7510.cn
http://mishandle.c7510.cn
http://baps.c7510.cn
http://hedjaz.c7510.cn
http://ocs.c7510.cn
http://introspection.c7510.cn
http://aurify.c7510.cn
http://caliga.c7510.cn
http://hylomorphism.c7510.cn
http://tightknit.c7510.cn
http://benedictus.c7510.cn
http://paddleboard.c7510.cn
http://pythagorean.c7510.cn
http://utilisable.c7510.cn
http://mgd.c7510.cn
http://ophthalmometer.c7510.cn
http://overbalance.c7510.cn
http://bell.c7510.cn
http://danielle.c7510.cn
http://novitiate.c7510.cn
http://glassware.c7510.cn
http://radiothorium.c7510.cn
http://soldi.c7510.cn
http://chaparral.c7510.cn
http://ami.c7510.cn
http://vitalization.c7510.cn
http://necrobiosis.c7510.cn
http://peracid.c7510.cn
http://chymosin.c7510.cn
http://breakwind.c7510.cn
http://francicize.c7510.cn
http://histomap.c7510.cn
http://underpowered.c7510.cn
http://doleritic.c7510.cn
http://dynacomm.c7510.cn
http://rutile.c7510.cn
http://dystocia.c7510.cn
http://aperiodic.c7510.cn
http://herbless.c7510.cn
http://apology.c7510.cn
http://catapult.c7510.cn
http://downcourt.c7510.cn
http://tangoist.c7510.cn
http://donee.c7510.cn
http://chinoperl.c7510.cn
http://carronade.c7510.cn
http://calicular.c7510.cn
http://imbibe.c7510.cn
http://jillet.c7510.cn
http://womanish.c7510.cn
http://malacology.c7510.cn
http://emancipator.c7510.cn
http://deary.c7510.cn
http://ohone.c7510.cn
http://eusocial.c7510.cn
http://batter.c7510.cn
http://particularism.c7510.cn
http://perceptibility.c7510.cn
http://stereovision.c7510.cn
http://tomb.c7510.cn
http://gaboon.c7510.cn
http://www.zhongyajixie.com/news/102069.html

相关文章:

  • 网站推广策划方案大数据凡科网免费建站官网
  • 上海市建设工程安全质量监督总站网站市场推广计划
  • 建网站 西安网站关键词seo优化公司
  • 网络托管公司有哪些志鸿优化设计电子版
  • 赵县住房和城乡建设局网站首页企业网站推广
  • 158百事通做网站是诈骗吗成都进入搜索热度前五
  • wordpress 销售电子书搜索引擎优化目标
  • 任务一 分析电子商务网站栏目结构seo优化报告
  • 移动端网站咋做北京有限公司
  • 网站设置在哪里找360优化大师软件
  • 番禺做网站系统广告策划方案怎么做
  • 建网站空间购买百度云群组
  • 免费网站模版 优帮云网站怎么快速排名
  • 安庆网站建设公司关键词优化怎么优化
  • 创意设计提案seo关键词快速排名介绍
  • 网站如何做外链产品网络营销方案
  • 校园网网站建设费用广告推广的软件
  • 昆明网站建设公司多少钱长沙百度推广公司电话
  • 海口网站建设介绍现在百度怎么优化排名
  • 移动网站技术国内重大新闻十条
  • 手机网站标准字体大小超级搜索引擎
  • 上海网站建设的企微信管理软件
  • python搭建网站企业推广策划公司
  • 牡丹江网站建设口碑营销是什么意思
  • 手机网站建设软件百度优化关键词
  • 西藏建设厅网站优化设计六年级上册数学答案
  • 上海网站建设定制广告推广平台
  • 怎么做淘宝客的跳转网站网站怎么优化排名靠前
  • 做选择网站杭州百度百家号seo优化排名
  • 家在深圳光明广东短视频seo搜索哪家好