Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
source code for k medoid algorithm using java
#1

source code for k medoid algorithm using java

Data Mining is a fairly recent and contemporary topic in computing. However, Data Mining applies many older computational techniques from statistics, machine learning and pattern recognition. This paper explores two most popular clustering techniques are the k-means& k-medoids clustering algorithm. However, k-means algorithm is cluster or to group your objects based on attributes into K number of group and k-medoids is a related to the K-means algorithm. These algorithms are based on the k partition algorithms and both attempt to minimize squared error. In contrast to the K-means algorithm K-medoids chooses data points as centres. The algorithms have been developed in Java, for integration with Weka Machine Learning Software. The algorithms have been run with two dataset Facial palsy and Stemming. It is having been shown that the algorithm is generally faster and more accurate than other clustering algorithms.

Data Mining derives its name from the similarities between searching for valuable business information in a large database (for example, finding linked products in gigabytes of store scanner data) and mining a mountain for a vein of valuable ore.[1] Both process requires either sifting through an immense amount of material. Or intelligently probing it to find exactly where the value resides.

/* vim: set ts=2: */
/**
* Copyright © 2008 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions, and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* 3. Redistributions must acknowledge that this software was
* originally developed by the UCSF Computer Graphics Laboratory
* under support by the NIH National Center for Research Resources,
* grant P41-RR01081.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
package clusterMaker.algorithms.attributeClusterers.kmedoid;

import java.awt.GridLayout;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import javax.swing.JPanel;

// Cytoscape imports
import cytoscape.Cytoscape;
import cytoscape.data.CyAttributes;
import cytoscape.layout.Tunable;
import cytoscape.logger.CyLogger;
import cytoscape.task.TaskMonitor;

import clusterMaker.algorithms.ClusterAlgorithm;
import clusterMaker.algorithms.AbstractClusterAlgorithm;
import clusterMaker.algorithms.attributeClusterers.AbstractAttributeClusterer;
import clusterMaker.algorithms.attributeClusterers.DistanceMetric;
import clusterMaker.algorithms.attributeClusterers.Matrix;
import clusterMaker.ui.ClusterViz;
import clusterMaker.ui.KnnView;

// clusterMaker imports

public class KMedoidCluster extends AbstractAttributeClusterer {
int rNumber = 10;
KnnView knnView = null;

public KMedoidCluster() {
super();
logger = CyLogger.getLogger(KMedoidCluster.class);
initializeProperties();
}

public String getShortName() {return "kmedoid";};
public String getName() {return "K-Medoid cluster";};

public JPanel getSettingsPanel() {
// Everytime we ask for the panel, we want to update our attributes
Tunable attributeTunable = clusterProperties.get("attributeList");
attributeArray = getAllAttributes();
attributeTunable.setLowerBound((Object)attributeArray);

// We also want to update the number our "guestimate" for k and kMax
updateKEstimates();

return clusterProperties.getTunablePanel();
}

public ClusterViz getVisualizer() {
// if (knnView == null)
// knnView = new KnnView();

return new KnnView();
}

public void initializeProperties() {
super.initializeProperties();

/**
* Tuning values
*/

// K
addKTunables();

// Number of iterations
clusterProperties.add(new Tunable("iterations",
"Number of iterations",
Tunable.INTEGER, new Integer(rNumber),
(Object)rNumber, (Object)null, 0));

// The distance metric to use
clusterProperties.add(new Tunable("dMetric",
"Distance Metric",
Tunable.LIST, new Integer(0),
(Object)Matrix.distanceTypes, (Object)null, 0));

clusterProperties.add(new Tunable("attributeListGroup",
"Source for array data",
Tunable.GROUP, new Integer(1));

// The attribute to use to get the weights
attributeArray = getAllAttributes();
clusterProperties.add(new Tunable("attributeList",
"Array sources",
Tunable.LIST, "",
(Object)attributeArray, (Object)null, Tunable.MULTISELECT));

// Whether or not to only cluster selected nodes/edges
clusterProperties.add(new Tunable("selectedOnly",
"Only use selected nodes/edges for cluster",
Tunable.BOOLEAN, new Boolean(selectedOnly));

// Whether or not to cluster attributes as well as nodes
clusterProperties.add(new Tunable("clusterAttributes",
"Cluster attributes as well as nodes",
Tunable.BOOLEAN, new Boolean(clusterAttributes));

// Whether or not to create groups
clusterProperties.add(new Tunable("createGroups",
"Create groups from clusters",
Tunable.BOOLEAN, new Boolean(createGroups));

clusterProperties.initializeProperties();
updateSettings(true);
}

public void updateSettings() {
updateSettings(false);
updateKTunables(false);
}

public void updateSettings(boolean force) {
clusterProperties.updateValues();
super.updateSettings(force);
updateKTunables(force);

Tunable t = clusterProperties.get("iterations");
if ((t != null) && (t.valueChanged() force))
rNumber = ((Integer) t.getValue()).intValue();

t = clusterProperties.get("dMetric");
if ((t != null) && (t.valueChanged() force))
distanceMetric = Matrix.distanceTypes[((Integer) t.getValue()).intValue()];

t = clusterProperties.get("clusterAttributes");
if ((t != null) && (t.valueChanged() force))
clusterAttributes = ((Boolean) t.getValue()).booleanValue();

t = clusterProperties.get("selectedOnly");
if ((t != null) && (t.valueChanged() force))
selectedOnly = ((Boolean) t.getValue()).booleanValue();

t = clusterProperties.get("createGroups");
if ((t != null) && (t.valueChanged() force))
createGroups = ((Boolean) t.getValue()).booleanValue();

t = clusterProperties.get("attributeList");
if ((t != null) && (t.valueChanged() force)) {
dataAttributes = (String) t.getValue();
}
}

public void doCluster(TaskMonitor monitor) {
this.monitor = monitor;
// Sanity check all of our settings
if (debug)
logger.debug("Performing k-medoid cluster with k="+kNumber+" using "+distanceMetric+" and attributes: "+dataAttributes);

if (dataAttributes == null dataAttributes.length() == 0) {
if (monitor != null) {
monitor.setException(null, "Error: no attribute list selected");
logger.warning("Must have an attribute list to use for cluster weighting");
} else
logger.error("Must have an attribute list to use for cluster weighting");
return;
}

// Get our attributes we're going to use for the cluster
String attributeArray[] = getAttributeArray(dataAttributes);
// To make debugging easier, sort the attribute array
Arrays.sort(attributeArray);

KMCluster algorithm = new KMCluster(attributeArray, distanceMetric, logger, monitor);
algorithm.setCreateGroups(createGroups);
algorithm.setIgnoreMissing(true); // KMedoid doesn't handle missing data well
algorithm.setSelectedOnly(selectedOnly);
algorithm.setDebug(debug);
algorithm.setUseSilhouette(useSilhouette);
algorithm.setKMax(kMax);
algorithm.setInitializeNearCenter(initializeNearCenter);
algorithm.setClusterInterface(this);

String resultsString = "K-Medoid results:";

// Cluster the attributes, if requested
if (clusterAttributes && attributeArray.length > 1) {
if (monitor != null)
monitor.setStatus("Clustering attributes");
resultsString = "\nAttributes: " + algorithm.cluster(kNumber, rNumber, true, "kmedoid");
}

// Cluster the nodes
if (monitor != null)
monitor.setStatus("Clustering nodes");
resultsString = "\nNodes: "+algorithm.cluster(kNumber, rNumber, false, "kmedoid");
if (monitor != null)
monitor.setStatus(resultsString);

// Tell any listeners that we're done
pcs.firePropertyChange(ClusterAlgorithm.CLUSTER_COMPUTED, null, this);
}

}
Reply

#2
i required source code of k-medioids algorithm in java for my proect work.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

Powered By MyBB, © 2002-2024 iAndrew & Melroy van den Berg.