Return-Path: X-Original-To: apmail-mahout-commits-archive@www.apache.org Delivered-To: apmail-mahout-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A4575175D2 for ; Thu, 19 Mar 2015 21:21:57 +0000 (UTC) Received: (qmail 66997 invoked by uid 500); 19 Mar 2015 21:21:51 -0000 Delivered-To: apmail-mahout-commits-archive@mahout.apache.org Received: (qmail 66892 invoked by uid 500); 19 Mar 2015 21:21:51 -0000 Mailing-List: contact commits-help@mahout.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@mahout.apache.org Delivered-To: mailing list commits@mahout.apache.org Received: (qmail 66152 invoked by uid 99); 19 Mar 2015 21:21:50 -0000 Received: from eris.apache.org (HELO hades.apache.org) (140.211.11.105) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 19 Mar 2015 21:21:50 +0000 Received: from hades.apache.org (localhost [127.0.0.1]) by hades.apache.org (ASF Mail Server at hades.apache.org) with ESMTP id 87C3FAC0AE7 for ; Thu, 19 Mar 2015 21:21:50 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r944380 [15/24] - in /websites/staging/mahout/trunk/content: ./ developers/ general/ users/basics/ users/classification/ users/clustering/ users/dim-reduction/ users/mapreduce/ users/mapreduce/classification/ users/mapreduce/clustering/ use... Date: Thu, 19 Mar 2015 21:21:47 -0000 To: commits@mahout.apache.org From: buildbot@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20150319212150.87C3FAC0AE7@hades.apache.org> Added: websites/staging/mahout/trunk/content/users/mapreduce/clustering/fuzzy-k-means-commandline.html ============================================================================== --- websites/staging/mahout/trunk/content/users/mapreduce/clustering/fuzzy-k-means-commandline.html (added) +++ websites/staging/mahout/trunk/content/users/mapreduce/clustering/fuzzy-k-means-commandline.html Thu Mar 19 21:21:45 2015 @@ -0,0 +1,366 @@ + + + + + Apache Mahout: Scalable machine learning and data mining + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+
+

+

Running Fuzzy k-Means Clustering from the Command Line

+

Mahout's Fuzzy k-Means clustering can be launched from the same command +line invocation whether you are running on a single machine in stand-alone +mode or on a larger Hadoop cluster. The difference is determined by the +$HADOOP_HOME and $HADOOP_CONF_DIR environment variables. If both are set to +an operating Hadoop cluster on the target machine then the invocation will +run FuzzyK on that cluster. If either of the environment variables are +missing then the stand-alone Hadoop configuration will be invoked instead.

+
./bin/mahout fkmeans <OPTIONS>
+
+ + +
    +
  • In $MAHOUT_HOME/, build the jar containing the job (mvn install) The job +will be generated in $MAHOUT_HOME/core/target/ and it's name will contain +the Mahout version number. For example, when using Mahout 0.3 release, the +job will be mahout-core-0.3.job
  • +
+

+

Testing it on one single machine w/o cluster

+
    +
  • Put the data: cp testdata
  • +
  • +

    Run the Job:

    +

    ./bin/mahout fkmeans -i testdata

    +
  • +
+

+

Running it on the cluster

+
    +
  • (As needed) Start up Hadoop: $HADOOP_HOME/bin/start-all.sh
  • +
  • Put the data: $HADOOP_HOME/bin/hadoop fs -put testdata
  • +
  • +

    Run the Job:

    +

    export HADOOP_HOME= +export HADOOP_CONF_DIR=$HADOOP_HOME/conf +./bin/mahout fkmeans -i testdata

    +
  • +
  • +

    Get the data out of HDFS and have a look. Use bin/hadoop fs -lsr output +to view all outputs.

    +
  • +
+

+

Command line options

+
  --input (-i) input                   Path to job input directory. 
+                           Must be a SequenceFile of    
+                           VectorWritable           
+  --clusters (-c) clusters             The input centroids, as Vectors. 
+                           Must be a SequenceFile of    
+                           Writable, Cluster/Canopy. If k  
+                           is also specified, then a random 
+                           set of vectors will be selected  
+                           and written out to this path 
+                           first                
+  --output (-o) output                 The directory pathname for   
+                           output.              
+  --distanceMeasure (-dm) distanceMeasure      The classname of the     
+                           DistanceMeasure. Default is  
+                           SquaredEuclidean         
+  --convergenceDelta (-cd) convergenceDelta    The convergence delta value. 
+                           Default is 0.5           
+  --maxIter (-x) maxIter               The maximum number of        
+                           iterations.          
+  --k (-k) k                       The k in k-Means.  If specified, 
+                           then a random selection of k 
+                           Vectors will be chosen as the
+                               Centroid and written to the  
+                           clusters input path.     
+  --m (-m) m                       coefficient normalization    
+                           factor, must be greater than 1   
+  --overwrite (-ow)                If present, overwrite the output 
+                           directory before running job 
+  --help (-h)                      Print out help           
+  --numMap (-u) numMap                 The number of map tasks.     
+                           Defaults to 10           
+  --maxRed (-r) maxRed                 The number of reduce tasks.  
+                           Defaults to 2            
+  --emitMostLikely (-e) emitMostLikely         True if clustering should emit   
+                           the most likely point only,  
+                           false for threshold clustering.  
+                           Default is true          
+  --threshold (-t) threshold               The pdf threshold used for   
+                           cluster determination. Default   
+                           is 0 
+  --clustering (-cl)                   If present, run clustering after 
+                           the iterations have taken place
+
+
+
+
+
+
+

+ Copyright © 2014 The Apache Software Foundation, Licensed under + the Apache License, Version 2.0. +
+ Apache and the Apache feather logos are trademarks of The Apache Software Foundation. +

+
+
+ + + + + + Added: websites/staging/mahout/trunk/content/users/mapreduce/clustering/fuzzy-k-means.html ============================================================================== --- websites/staging/mahout/trunk/content/users/mapreduce/clustering/fuzzy-k-means.html (added) +++ websites/staging/mahout/trunk/content/users/mapreduce/clustering/fuzzy-k-means.html Thu Mar 19 21:21:45 2015 @@ -0,0 +1,434 @@ + + + + + Apache Mahout: Scalable machine learning and data mining + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+
+

Fuzzy K-Means

+

Fuzzy K-Means (also called Fuzzy C-Means) is an extension of K-Means +, the popular simple clustering technique. While K-Means discovers hard +clusters (a point belong to only one cluster), Fuzzy K-Means is a more +statistically formalized method and discovers soft clusters where a +particular point can belong to more than one cluster with certain +probability.

+

+

Algorithm

+

Like K-Means, Fuzzy K-Means works on those objects which can be represented +in n-dimensional vector space and a distance measure is defined. +The algorithm is similar to k-means.

+
    +
  • Initialize k clusters
  • +
  • Until converged
      +
    • Compute the probability of a point belong to a cluster for every pair
    • +
    • Recompute the cluster centers using above probability membership values of points to clusters
    • +
    +
  • +
+

+

Design Implementation

+

The design is similar to K-Means present in Mahout. It accepts an input +file containing vector points. User can either provide the cluster centers +as input or can allow canopy algorithm to run and create initial clusters.

+

Similar to K-Means, the program doesn't modify the input directories. And +for every iteration, the cluster output is stored in a directory cluster-N. +The code has set number of reduce tasks equal to number of map tasks. So, +those many part-0

+

Files are created in clusterN directory. The code uses +driver/mapper/combiner/reducer as follows:

+

FuzzyKMeansDriver - This is similar to  KMeansDriver. It iterates over +input points and cluster points for specified number of iterations or until +it is converged.During every iteration i, a new cluster-i directory is +created which contains the modified cluster centers obtained during +FuzzyKMeans iteration. This will be feeded as input clusters in the next +iteration.  Once Fuzzy KMeans is run for specified number of +iterations or until it is converged, a map task is run to output "the point +and the cluster membership to each cluster" pair as final output to a +directory named "points".

+

FuzzyKMeansMapper - reads the input cluster during its configure() method, +then  computes cluster membership probability of a point to each +cluster.Cluster membership is inversely propotional to the distance. +Distance is computed using  user supplied distance measure. Output key +is encoded clusterId. Output values are ClusterObservations containing +observation statistics.

+

FuzzyKMeansCombiner - receives all key:value pairs from the mapper and +produces partial sums of the cluster membership probability times input +vectors for each cluster. Output key is: encoded cluster identifier. Output +values are ClusterObservations containing observation statistics.

+

FuzzyKMeansReducer - Multiple reducers receives certain keys and all values +associated with those keys. The reducer sums the values to produce a new +centroid for the cluster which is output. Output key is: encoded cluster +identifier (e.g. "C14". Output value is: formatted cluster identifier (e.g. +"C14"). The reducer encodes unconverged clusters with a 'Cn' cluster Id and +converged clusters with 'Vn' clusterId.

+

+

Running Fuzzy k-Means Clustering

+

The Fuzzy k-Means clustering algorithm may be run using a command-line +invocation on FuzzyKMeansDriver.main or by making a Java call to +FuzzyKMeansDriver.run().

+

Invocation using the command line takes the form:

+
bin/mahout fkmeans \
+    -i <input vectors directory> \
+    -c <input clusters directory> \
+    -o <output working directory> \
+    -dm <DistanceMeasure> \
+    -m <fuzziness argument >1> \
+    -x <maximum number of iterations> \
+    -k <optional number of initial clusters to sample from input vectors> \
+    -cd <optional convergence delta. Default is 0.5> \
+    -ow <overwrite output directory if present>
+    -cl <run input vector clustering after computing Clusters>
+    -e <emit vectors to most likely cluster during clustering>
+    -t <threshold to use for clustering if -e is false>
+    -xm <execution method: sequential or mapreduce>
+
+ + +

Note: if the -k argument is supplied, any clusters in the -c directory +will be overwritten and -k random points will be sampled from the input +vectors to become the initial cluster centers.

+

Invocation using Java involves supplying the following arguments:

+
    +
  1. input: a file path string to a directory containing the input data set a +SequenceFile(WritableComparable, VectorWritable). The sequence file key +is not used.
  2. +
  3. clustersIn: a file path string to a directory containing the initial +clusters, a SequenceFile(key, SoftCluster | Cluster | Canopy). Fuzzy +k-Means SoftClusters, k-Means Clusters and Canopy Canopies may be used for +the initial clusters.
  4. +
  5. output: a file path string to an empty directory which is used for all +output from the algorithm.
  6. +
  7. measure: the fully-qualified class name of an instance of DistanceMeasure +which will be used for the clustering.
  8. +
  9. convergence: a double value used to determine if the algorithm has +converged (clusters have not moved more than the value in the last +iteration)
  10. +
  11. max-iterations: the maximum number of iterations to run, independent of +the convergence specified
  12. +
  13. m: the "fuzzyness" argument, a double > 1. For m equal to 2, this is +equivalent to normalising the coefficient linearly to make their sum 1. +When m is close to 1, then the cluster center closest to the point is given +much more weight than the others, and the algorithm is similar to k-means.
  14. +
  15. runClustering: a boolean indicating, if true, that the clustering step is +to be executed after clusters have been determined.
  16. +
  17. emitMostLikely: a boolean indicating, if true, that the clustering step +should only emit the most likely cluster for each clustered point.
  18. +
  19. threshold: a double indicating, if emitMostLikely is false, the cluster +probability threshold used for emitting multiple clusters for each point. A +value of 0 will emit all clusters with their associated probabilities for +each vector.
  20. +
  21. runSequential: a boolean indicating, if true, that the algorithm is to +use the sequential reference implementation running in memory.
  22. +
+

After running the algorithm, the output directory will contain: +1. clusters-N: directories containing SequenceFiles(Text, SoftCluster) +produced by the algorithm for each iteration. The Text key is a cluster +identifier string. +1. clusteredPoints: (if runClustering enabled) a directory containing +SequenceFile(IntWritable, WeightedVectorWritable). The IntWritable key is +the clusterId. The WeightedVectorWritable value is a bean containing a +double weight and a VectorWritable vector where the weights are +computed as 1/(1+distance) where the distance is between the cluster center +and the vector using the chosen DistanceMeasure.

+

+

Examples

+

The following images illustrate Fuzzy k-Means clustering applied to a set +of randomly-generated 2-d data points. The points are generated using a +normal distribution centered at a mean location and with a constant +standard deviation. See the README file in the /examples/src/main/java/org/apache/mahout/clustering/display/README.txt + for details on running similar examples.

+

The points are generated as follows:

+
    +
  • 500 samples m=[1.0, 1.0](1.0,-1.0.html) + sd=3.0
  • +
  • 300 samples m=[1.0, 0.0](1.0,-0.0.html) + sd=0.5
  • +
  • 300 samples m=[0.0, 2.0](0.0,-2.0.html) + sd=0.1
  • +
+

In the first image, the points are plotted and the 3-sigma boundaries of +their generator are superimposed.

+

fuzzy

+

In the second image, the resulting clusters (k=3) are shown superimposed upon the sample data. As Fuzzy k-Means is an iterative algorithm, the centers of the clusters in each recent iteration are shown using different colors. Bold red is the final clustering and previous iterations are shown in [orange, yellow, green, blue, violet and gray](orange,-yellow,-green,-blue,-violet-and-gray.html) +. Although it misses a lot of the points and cannot capture the original, +superimposed cluster centers, it does a decent job of clustering this data.

+

fuzzy

+

The third image shows the results of running Fuzzy k-Means on a different +data set which is generated using asymmetrical standard deviations. +Fuzzy k-Means does a fair job handling this data set as well.

+

fuzzy

+

+

References 

+ +
+
+
+
+
+

+ Copyright © 2014 The Apache Software Foundation, Licensed under + the Apache License, Version 2.0. +
+ Apache and the Apache feather logos are trademarks of The Apache Software Foundation. +

+
+
+ + + + + + Added: websites/staging/mahout/trunk/content/users/mapreduce/clustering/hierarchical-clustering.html ============================================================================== --- websites/staging/mahout/trunk/content/users/mapreduce/clustering/hierarchical-clustering.html (added) +++ websites/staging/mahout/trunk/content/users/mapreduce/clustering/hierarchical-clustering.html Thu Mar 19 21:21:45 2015 @@ -0,0 +1,283 @@ + + + + + Apache Mahout: Scalable machine learning and data mining + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+
+

Hierarchical clustering is the process or finding bigger clusters, and also +the smaller clusters inside the bigger clusters.

+

In Apache Mahout, separate algorithms can be used for finding clusters at +different levels.

+

See Top Down Clustering +.

+
+
+
+
+
+

+ Copyright © 2014 The Apache Software Foundation, Licensed under + the Apache License, Version 2.0. +
+ Apache and the Apache feather logos are trademarks of The Apache Software Foundation. +

+
+
+ + + + + +