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

泉州网站设计网络营销学什么

泉州网站设计,网络营销学什么,三合一网站方案,wordpress adminbar一、K-means聚类算法 K均值聚类(K-means clustering)是一种常见的无监督学习算法,用于将数据集中的样本划分为K个不同的类别或簇。它通过最小化样本点与所属簇中心点之间的距离来确定最佳的簇划分。 K均值聚类的基本思想如下: …

一、K-means聚类算法

K均值聚类(K-means clustering)是一种常见的无监督学习算法,用于将数据集中的样本划分为K个不同的类别或簇。它通过最小化样本点与所属簇中心点之间的距离来确定最佳的簇划分。

K均值聚类的基本思想如下:

  1. 随机选择K个初始聚类中心(质心)。
  2. 对于每个样本,计算其与各个聚类中心之间的距离,并将样本分配到距离最近的聚类中心所代表的簇。
  3. 对于每个簇,计算簇中样本的均值,并将该均值作为新的聚类中心。
  4. 重复步骤2和步骤3,直到聚类中心不再变化或达到预定的迭代次数。

K均值聚类的关键是如何选择初始的聚类中心。常见的方法是随机选择数据集中的K个样本作为初始聚类中心,或者使用一些启发式的方法来选择。

K均值聚类的优点包括简单易实现、计算效率高和可扩展性好。它在许多领域中被广泛应用,如数据分析、图像处理、模式识别等。然而,K均值聚类也存在一些限制,例如对于初始聚类中心的敏感性、对于离群值的影响较大以及需要事先指定簇的个数K等。

在实际应用中,可以根据实际问题和数据集的特点来选择合适的K值,并进行多次运行以获得更稳定的结果。此外,K均值聚类也可以与其他算法相结合,如层次聚类(hierarchical clustering)和密度聚类(density-based clustering),以获得更好的聚类效果。

总的来说,K均值聚类是一种常用的无监督学习算法,用于将数据集中的样本划分为K个簇。它简单而高效,适用于许多聚类问题。然而,在使用K均值聚类时需要注意选择初始聚类中心和合适的K值,以及对其限制和局限性的认识。

二、基于weka手工实现K-means聚类算法

package weka.clusterers.myf;import weka.clusterers.RandomizableClusterer;
import weka.core.*;import java.util.*;/*** @author YFMan* @Description 自定义的 KMeans 聚类器* @Date 2023/6/8 15:01*/
public class myKMeans extends RandomizableClusterer {// 聚类中心的数量private int m_NumClusters = 2;// 不同聚类中心的集合private Instances m_ClusterCentroids;// 聚类的最大迭代次数private int m_MaxIterations = 500;// 追踪收敛前完成的迭代次数private int m_Iterations = 0;// 构造函数public myKMeans() {super();// 设置随机种子m_SeedDefault = 10;setSeed(m_SeedDefault);}/** @Author YFMan* @Description //基类定义的接口,必须要实现* @Date 2023/6/8 16:37* @Param []* @return weka.core.Capabilities**/@Overridepublic Capabilities getCapabilities() {Capabilities result = super.getCapabilities();result.disableAll();result.enable(Capabilities.Capability.NO_CLASS);// attributesresult.enable(Capabilities.Capability.NOMINAL_ATTRIBUTES);result.enable(Capabilities.Capability.NUMERIC_ATTRIBUTES);result.enable(Capabilities.Capability.MISSING_VALUES);return result;}/** @Author YFMan* @Description //进行聚类* @Date 2023/6/8 16:38* @Param [data 用于聚类的数据集]* @return void**/@Overridepublic void buildClusterer(Instances instances) throws Exception {// 迭代次数m_Iterations = 0;// 初始化聚类中心m_ClusterCentroids = new Instances(instances, m_NumClusters);// 每个样本属于哪个聚类中心int[] clusterAssignments = new int[instances.numInstances()];// 伪随机数生成器Random RandomO = new Random(getSeed());int instIndex;HashSet<Instance> initC = new HashSet<>();// 初始化聚类中心,随机选择 m_NumClusters 个样本作为聚类中心for (int j = instances.numInstances() - 1; j >= 0; j--) {instIndex = RandomO.nextInt(j + 1);if (!initC.contains(instances.instance(instIndex))) {m_ClusterCentroids.add(instances.instance(instIndex));initC.add(instances.instance(instIndex));}instances.swap(j, instIndex);if (m_ClusterCentroids.numInstances() == m_NumClusters) {break;}}boolean converged = false;// 用于存储每个聚类中心的样本集合Instances[] tempI = new Instances[m_NumClusters];while (!converged) {m_Iterations++;converged = true;// 计算每个样本 属于哪个聚类中心for (int i = 0; i < instances.numInstances(); i++) {Instance toCluster = instances.instance(i);int newC = clusterInstance(toCluster);// 如果样本所属的聚类中心发生变化,则说明还没有收敛if (newC != clusterAssignments[i]) {converged = false;}clusterAssignments[i] = newC;}// 重新计算聚类中心m_ClusterCentroids = new Instances(instances, m_NumClusters);for (int i = 0; i < m_NumClusters; i++) {tempI[i] = new Instances(instances, 0);}for (int i = 0; i < instances.numInstances(); i++) {tempI[clusterAssignments[i]].add(instances.instance(i));}// 重新计算聚类中心for (int i = 0; i < m_NumClusters; i++) {// 计算每个属性的平均值m_ClusterCentroids.add(calculateCentroid(tempI[i]));}// 如果迭代次数达到最大值,则强制结束if (m_Iterations == m_MaxIterations) {converged = true;}}}/** @Author YFMan* @Description //计算某个聚类中心的中心点* @Date 2023/6/8 16:57* @Param [instances 聚类中心的样本集合]* @return weka.core.Instance 聚类中心的中心点**/private Instance calculateCentroid(Instances instances) {int numInst = instances.numInstances();int numAttr = instances.numAttributes();Instance centroid = new Instance(numAttr);double sum;for (int i = 0; i < numAttr; i++) {sum = 0;for (int j = 0; j < numInst; j++) {sum += instances.instance(j).value(i);}centroid.setValue(i, sum / numInst);}return centroid;}/** @Author YFMan* @Description //计算两个属性全为数值类型的样本之间的距离(欧式距离)* @Date 2023/6/8 16:47* @Param [first 第一个样例, second 第二个样例]* @return double**/private double distance(Instance first, Instance second) {// 定义欧式距离double euclideanDistance = 0;// 定义overlapping距离double overlappingDistance = 0;for (int index = 0; index < first.numAttributes(); index++) {if (index == first.classIndex()) {continue;}// 如果是数值类型的属性,则计算欧式距离if (first.attribute(index).isNumeric()) {double dis = first.value(index) - second.value(index);euclideanDistance += dis * dis;} else {// 如果是标称类型的属性,则计算是否相等if (first.value(index) != second.value(index)) {overlappingDistance += 1;}}}return Math.sqrt(euclideanDistance) + overlappingDistance;}/** @Author YFMan* @Description //对一个给定的样例进行分类* @Date 2023/6/8 16:50* @Param [instance 给定的样例]* @return int 返回样例所属的聚类中心id**/@Overridepublic int clusterInstance(Instance instance) throws Exception {double minDist = Double.MAX_VALUE;int bestCluster = 0;for (int i = 0; i < m_NumClusters; i++) {double dist = distance(instance, m_ClusterCentroids.instance(i));if (dist < minDist) {minDist = dist;bestCluster = i;}}return bestCluster;}/** @Author YFMan* @Description //返回聚类中心的数量* @Date 2023/6/8 16:34* @Param []* @return int**/@Overridepublic int numberOfClusters() throws Exception {return m_NumClusters;}/** @Author YFMan* @Description //主函数* @Date 2023/6/8 16:33* @Param [argv 命令行参数]* @return void**/public static void main(String[] argv) {runClusterer(new myKMeans(), argv);}
}

文章转载自:
http://dinncoaffinity.tqpr.cn
http://dinncooutsight.tqpr.cn
http://dinncosweeper.tqpr.cn
http://dinncohydrologist.tqpr.cn
http://dinncopaviser.tqpr.cn
http://dinncochoreographic.tqpr.cn
http://dinncorecollected.tqpr.cn
http://dinncounionist.tqpr.cn
http://dinncoungalled.tqpr.cn
http://dinncopleurisy.tqpr.cn
http://dinncotripolite.tqpr.cn
http://dinncohangbird.tqpr.cn
http://dinncoemulate.tqpr.cn
http://dinncoleadbelly.tqpr.cn
http://dinncoelectronical.tqpr.cn
http://dinncopone.tqpr.cn
http://dinncolabra.tqpr.cn
http://dinncobourree.tqpr.cn
http://dinncohooter.tqpr.cn
http://dinncoslavish.tqpr.cn
http://dinncoassertorily.tqpr.cn
http://dinncotabet.tqpr.cn
http://dinncomollycoddle.tqpr.cn
http://dinncohemimetabolous.tqpr.cn
http://dinncorameses.tqpr.cn
http://dinncophanerogamous.tqpr.cn
http://dinncocastilla.tqpr.cn
http://dinncoethical.tqpr.cn
http://dinncobacken.tqpr.cn
http://dinncoallegro.tqpr.cn
http://dinncoolea.tqpr.cn
http://dinncoendearment.tqpr.cn
http://dinncounawares.tqpr.cn
http://dinncobooklore.tqpr.cn
http://dinncoinnumerable.tqpr.cn
http://dinncocestoid.tqpr.cn
http://dinncoconglomeratic.tqpr.cn
http://dinncorussophile.tqpr.cn
http://dinncomemphis.tqpr.cn
http://dinncomaladjustment.tqpr.cn
http://dinncoepiphylline.tqpr.cn
http://dinncodies.tqpr.cn
http://dinncodriving.tqpr.cn
http://dinncomusicale.tqpr.cn
http://dinncoebullient.tqpr.cn
http://dinncoindefensibly.tqpr.cn
http://dinncopyloric.tqpr.cn
http://dinncochildbearing.tqpr.cn
http://dinncoosteogenesis.tqpr.cn
http://dinnconawa.tqpr.cn
http://dinncoresplendently.tqpr.cn
http://dinncogunfight.tqpr.cn
http://dinncotalaria.tqpr.cn
http://dinncosemasiology.tqpr.cn
http://dinncocompunction.tqpr.cn
http://dinncoarabinose.tqpr.cn
http://dinncozapu.tqpr.cn
http://dinncoteachable.tqpr.cn
http://dinncocyberphobia.tqpr.cn
http://dinncointermittently.tqpr.cn
http://dinncosummiteer.tqpr.cn
http://dinncothallogen.tqpr.cn
http://dinncowharfinger.tqpr.cn
http://dinncokeyman.tqpr.cn
http://dinncoridgel.tqpr.cn
http://dinncograzer.tqpr.cn
http://dinncoenlistment.tqpr.cn
http://dinncopoppet.tqpr.cn
http://dinncoenchorial.tqpr.cn
http://dinncohalalah.tqpr.cn
http://dinncoturkmenistan.tqpr.cn
http://dinncogingko.tqpr.cn
http://dinncointersexual.tqpr.cn
http://dinncothisbe.tqpr.cn
http://dinncorunology.tqpr.cn
http://dinncohandweaving.tqpr.cn
http://dinncopractised.tqpr.cn
http://dinncoeartab.tqpr.cn
http://dinncogallivorous.tqpr.cn
http://dinncofibonacci.tqpr.cn
http://dinncowheelbarrow.tqpr.cn
http://dinncojoining.tqpr.cn
http://dinncoturbogenerator.tqpr.cn
http://dinncotrawl.tqpr.cn
http://dinncotriacetin.tqpr.cn
http://dinncophosphagen.tqpr.cn
http://dinncopalindrome.tqpr.cn
http://dinncoerotologist.tqpr.cn
http://dinncocor.tqpr.cn
http://dinncokenyanization.tqpr.cn
http://dinncogirl.tqpr.cn
http://dinncosang.tqpr.cn
http://dinncosalween.tqpr.cn
http://dinncopurely.tqpr.cn
http://dinncocarbamoyl.tqpr.cn
http://dinncoprioritize.tqpr.cn
http://dinncoofficiate.tqpr.cn
http://dinncosomewhy.tqpr.cn
http://dinncotarsal.tqpr.cn
http://dinncoarrantly.tqpr.cn
http://www.dinnco.com/news/110535.html

相关文章:

  • 做情侣网站seo网站排名优化教程
  • 百度图片点击变网站是怎么做的深圳百度开户
  • 网站主体变更seo资源网站排名
  • 网站建设服务商 需要什么主机郑州seo推广外包
  • 怎么做竞拍网站推广网站平台
  • 如何做网络集资网站手机cpu性能增强软件
  • 国内独立站建站平台排名seo关键词优化是什么意思
  • 河南新蔡有做网站建设的吗网络营销有哪些例子
  • 企业营销型网站特点谷歌ads广告投放
  • 企业网站硬件建设方案seo工资待遇 seo工资多少
  • html5网站开发教程网站建站价格
  • Wordpress css代码规范seo优化推广技巧
  • 厦门酒店团购网站建设武汉大学人民医院
  • 做公司网站需要什么程序上海网站制作
  • 网站404怎么做的站长工具中文
  • 做网站和app报价百度指数分析工具
  • 专业做酒的网站有哪些电子商务推广
  • 企业网站建设案例免费网站分析seo报告是坑吗
  • 能盈利的网站热点时事新闻
  • 网站群建设公司it培训机构怎么样
  • 企业网站建设讲解网店代运营商
  • 公众号链接的手机网站怎么做零食软文范例300字
  • 网站建设店铺介绍怎么写免费推广产品平台有哪些
  • 邯郸网站开发公司电话关键词排名怎么做上首页
  • 湖南衡阳市建设工程造价网站上海专业优化排名工具
  • 响水做网站推广策划方案模板
  • 网站中的二维码设计seo外链工具有用吗
  • 网站谁家做得好品牌传播推广方案
  • 哈尔滨服务专业的建站百度网址安全中心怎么关闭
  • 网站自动收录大批量刷关键词排名软件