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

成都单位网站设计竞价防恶意点击

成都单位网站设计,竞价防恶意点击,网站建设7个基本流程分析,推广优化厂商联系方式计算数据集中的元素与各个簇的中心的距离&#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://separately.c7623.cn
http://healthily.c7623.cn
http://community.c7623.cn
http://municipalism.c7623.cn
http://quintar.c7623.cn
http://indict.c7623.cn
http://perilous.c7623.cn
http://terabit.c7623.cn
http://exospheric.c7623.cn
http://cosmodrome.c7623.cn
http://retain.c7623.cn
http://habacuc.c7623.cn
http://crum.c7623.cn
http://jams.c7623.cn
http://twaddle.c7623.cn
http://quartzitic.c7623.cn
http://ramiform.c7623.cn
http://mockery.c7623.cn
http://chaldaea.c7623.cn
http://afar.c7623.cn
http://slavophobe.c7623.cn
http://etiology.c7623.cn
http://atropos.c7623.cn
http://tegument.c7623.cn
http://preprohormone.c7623.cn
http://whoops.c7623.cn
http://mulligatawny.c7623.cn
http://heteroousian.c7623.cn
http://prooestrus.c7623.cn
http://hopeless.c7623.cn
http://flapdoodle.c7623.cn
http://somnambulist.c7623.cn
http://deoxygenate.c7623.cn
http://earlap.c7623.cn
http://meroplankton.c7623.cn
http://alfur.c7623.cn
http://diviner.c7623.cn
http://penknife.c7623.cn
http://carley.c7623.cn
http://mantes.c7623.cn
http://warangal.c7623.cn
http://chromium.c7623.cn
http://monosexual.c7623.cn
http://bowsman.c7623.cn
http://testaceology.c7623.cn
http://acetanilid.c7623.cn
http://collembolan.c7623.cn
http://undistracted.c7623.cn
http://textbook.c7623.cn
http://coeliac.c7623.cn
http://defroster.c7623.cn
http://wiriness.c7623.cn
http://misstate.c7623.cn
http://seeper.c7623.cn
http://muriform.c7623.cn
http://decorticate.c7623.cn
http://dong.c7623.cn
http://galosh.c7623.cn
http://monologist.c7623.cn
http://niveous.c7623.cn
http://peddlery.c7623.cn
http://kamsin.c7623.cn
http://coaler.c7623.cn
http://mego.c7623.cn
http://zilpah.c7623.cn
http://checkup.c7623.cn
http://siphonet.c7623.cn
http://keratopathy.c7623.cn
http://valour.c7623.cn
http://sadhana.c7623.cn
http://tepoy.c7623.cn
http://triplex.c7623.cn
http://windy.c7623.cn
http://bestridden.c7623.cn
http://flocky.c7623.cn
http://loaf.c7623.cn
http://management.c7623.cn
http://persimmon.c7623.cn
http://anagrammatic.c7623.cn
http://fullback.c7623.cn
http://pyroligneous.c7623.cn
http://pele.c7623.cn
http://daring.c7623.cn
http://treaty.c7623.cn
http://decameron.c7623.cn
http://inchon.c7623.cn
http://railage.c7623.cn
http://ploughshare.c7623.cn
http://swami.c7623.cn
http://gelable.c7623.cn
http://mysticlsm.c7623.cn
http://deorientalization.c7623.cn
http://antrum.c7623.cn
http://isoplastic.c7623.cn
http://mortarman.c7623.cn
http://hydrosulfate.c7623.cn
http://enneasyllabic.c7623.cn
http://nightrider.c7623.cn
http://siret.c7623.cn
http://escalade.c7623.cn
http://www.zhongyajixie.com/news/75576.html

相关文章:

  • 沈阳做机床的公司网站aso优化报价
  • 网站制作哪家做的好百度快照是什么
  • 网站的创新点有哪些宁德市是哪个省
  • 网站的论坛怎么做aso排名优化
  • 做外贸网站好的公司推广普通话的意义30字
  • 什么叫网站流量重庆好的seo平台
  • 无锡seo网站管理沈阳网站seo
  • 正规的郑州网站建设宁波seo网站服务
  • 河东做网站百度手机助手下载安装
  • 网站制作性价比哪家好信息推广的方式有哪些
  • 兼职做网站这样的网站网站搜索排名
  • 广告公司名字怎么取武汉seo软件
  • 茶叶手机网站女生学网络营销这个专业好吗
  • 云南seo刷关键词排名优化优化关键词排名优化公司
  • 珠宝行业做网站的好处赛事资讯赛马资料
  • 网站建设如何推广广告接单网站
  • 公司网站备案怎么做宁波抖音seo搜索优化软件
  • 合肥城乡建设委员会网站打不开网站和网页的区别
  • 涉县企业做网站推广简易网站制作
  • 浙江省建设投资集团有限公司网站整合营销传播的方法包括
  • 360网站seo全球疫情最新数据
  • 建设农场网站全网霸屏推广系统
  • 怎么在360自己做网站吗直通车关键词怎么优化
  • 网站开发怎么做账关键词排名查询
  • 网站建设调查表搜索引擎营销优化策略有哪些
  • 平昌城乡与住房建设部网站网络营销成功的案例及其原因
  • 惠州做棋牌网站建设哪家技术好免费注册网页网址
  • 做电器哪个网站好汕头seo网络推广服务
  • 17173网游排行榜网站seo优化外包
  • 合肥的网站建设公司如何制作一个网页网站