模糊k-means聚类

接上一篇博文:聚类算法概述

模糊kmeans算法是kmeans聚类模糊形式。与kmeans算法排他性聚类不同,模糊kmeans尝试从数据集中生成有重叠的簇。在研究领域,这也叫做模糊c-means算法,可以把模糊kmeans看作kmeans算法的扩展。

kmeans致力于寻找硬簇(一个数据集点只属于某一个簇)。在一个软聚类算法中,任何点都属于不止一个簇,而且该点到这些簇之间都有一定大小的吸引度。这种吸引度与该点到这个簇中心距离成比例。

mahout中实现部分也是FuzzyKMeansClusterer 和 FuzzyKMeansDriver 一个是in-memory的一个是mapreduce 的。

模糊kmeans有一个参数m ,叫做模糊因子。与kmeans不同的是,模糊因子引入不是把向量分配到最近的中心,而是计算每个点到每个簇的关联度。

假设一个向量V,到k个簇的距离分别为d1,d2。。。dk。向量V到第一簇的关联度计算如下:


这个公式也就是表达意思:如果越接近该向量簇中心,就会得到更高的权重。

mahout中具体实现这个公式的在FuzzyKMeansClusterer 中

package org.apache.mahout.clustering.fuzzykmeans;

import java.util.Collection;
import java.util.List;

import org.apache.mahout.math.DenseVector;
import org.apache.mahout.math.Vector;

public class FuzzyKMeansClusterer {

  private static final double MINIMAL_VALUE = 0.0000000001;
  
  private double m = 2.0; // default value
  
  public Vector computePi(Collection<SoftCluster> clusters, List<Double> clusterDistanceList) {
    Vector pi = new DenseVector(clusters.size());
    for (int i = 0; i < clusters.size(); i++) {
      double probWeight = computeProbWeight(clusterDistanceList.get(i), clusterDistanceList);
      pi.set(i, probWeight);
    }
    return pi;
  }
  
  /** Computes the probability of a point belonging to a cluster */
  public double computeProbWeight(double clusterDistance, Iterable<Double> clusterDistanceList) {
    if (clusterDistance == 0) {
      clusterDistance = MINIMAL_VALUE;
    }
    double denom = 0.0;
    for (double eachCDist : clusterDistanceList) {
      if (eachCDist == 0.0) {
        eachCDist = MINIMAL_VALUE;
      }
      denom += Math.pow(clusterDistance / eachCDist, 2.0 / (m - 1));
    }
    return 1.0 / denom;
  }

  public void setM(double m) {
    this.m = m;
  }
}

而在分布式中FuzzyKMeansDriver  

  /**
   * Iterate over the input vectors to produce cluster directories for each iteration
   *
   * @param input
   *          the directory pathname for input points
   * @param clustersIn
   *          the file pathname for initial cluster centers
   * @param output
   *          the directory pathname for output points
   * @param convergenceDelta
   *          the convergence delta value
   * @param maxIterations
   *          the maximum number of iterations
   * @param m
   *          the fuzzification factor, see
   *          http://en.wikipedia.org/wiki/Data_clustering#Fuzzy_c-means_clustering
   * @param runSequential if true run in sequential execution mode
   *
   * @return the Path of the final clusters directory
   */
  public static Path buildClusters(Configuration conf,
                                   Path input,
                                   Path clustersIn,
                                   Path output,
                                   double convergenceDelta,
                                   int maxIterations,
                                   float m,
                                   boolean runSequential)
    throws IOException, InterruptedException, ClassNotFoundException {
    
    List<Cluster> clusters = Lists.newArrayList();
    FuzzyKMeansUtil.configureWithClusterInfo(conf, clustersIn, clusters);
    
    if (conf == null) {
      conf = new Configuration();
    }
    
    if (clusters.isEmpty()) {
      throw new IllegalStateException("No input clusters found in " + clustersIn + ". Check your -c argument.");
    }
    
    Path priorClustersPath = new Path(output, Cluster.INITIAL_CLUSTERS_DIR);   
    ClusteringPolicy policy = new FuzzyKMeansClusteringPolicy(m, convergenceDelta);
    ClusterClassifier prior = new ClusterClassifier(clusters, policy);
    prior.writeToSeqFiles(priorClustersPath);
    
    if (runSequential) {
      ClusterIterator.iterateSeq(conf, input, priorClustersPath, output, maxIterations);
    } else {
      ClusterIterator.iterateMR(conf, input, priorClustersPath, output, maxIterations);
    }
    return output;
  }


转载于:https://www.cnblogs.com/huruzun/p/5423889.html

模糊K-means聚类算法是一种改进的K-means聚类算法。在传统的K-means算法中,对于每个簇的对象都使用相同的权值,忽略了簇内对象之间的差异性。而模糊K-means算法通过对每个簇内的对象分配不同的权值,更好地反映了对象之间的相似度。 模糊K-means算法的原理是基于模糊集合理论。它引入了隶属度的概念,将每个对象对于每个簇的隶属度表示为一个0到1之间的值,表示对象属于该簇的概率。通过迭代计算,将对象重新分配到具有较高隶属度的簇中,直到算法收敛为止。 相比于传统的K-means算法,模糊K-means算法在处理聚类边界模糊问题方面更加有效。它能够更好地区分簇内对象之间的差异性,并对对象进行更准确的聚类。 在确定模糊K-means算法的聚类数目K时,可以采用一些方法来估计最合适的K值。传统的K-means算法中,K是事先给定的,很难确定最合适的K值。但是在模糊K-means算法中,可以使用方差分析理论和混合F统计量来确定最佳分类数,并使用模糊划分熵来验证最佳分类数的正确性。这些方法可以帮助确定最适合数据集的聚类数目。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [K-means算法与模糊聚类C-means算法](https://blog.csdn.net/qq_43787814/article/details/102883673)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [基于簇内不平衡度量的粗糙??-means 聚类算法](https://download.csdn.net/download/weixin_38571878/14158817)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值