本文整理汇总了Java中weka.clusterers.EM类的典型用法代码示例。如果您正苦于以下问题:Java EM类的具体用法?Java EM怎么用?Java EM使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EM类属于weka.clusterers包,在下文中一共展示了EM类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sortAndpPrintCluster
import weka.clusterers.EM; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private HashMap<Integer, Integer> sortAndpPrintCluster(EM clusterer) {
List<double[]> vals = new ArrayList<double[]>(clusterer.getNumClusters());
for (int c = 0; c < clusterer.getNumClusters(); c++) {
vals.add(new double[]{clusterer.getClusterModelsNumericAtts()[c][0][0], // mean
clusterer.getClusterModelsNumericAtts()[c][0][1], // var
clusterer.getClusterModelsNumericAtts()[c][0][2], // prior
clusterer.getClusterPriors()[c], // priors normalized
c // cluster number
});
}
Collections.sort(vals, new Comparator() {
public int compare(Object o1, Object o2) {
double[] d1 = (double[]) o1;
double[] d2 = (double[]) o2;
return (int) Math.signum(d1[0] - d2[0]);
}
});
for (int c = 0; c < vals.size(); c++) {
logger.trace("Cluster " + c + ":" + vals.get(c)[0] + " Var:" + vals.get(c)[1] + " Z:" + vals.get(c)[2] + " Prior:" + vals.get(c)[3] + " Cluster:" + vals.get(c)[4]);
}
return mergeClusters(vals);
}
示例2: guessNumClusters
import weka.clusterers.EM; //导入依赖的package包/类
private int guessNumClusters(EM clusterer, Instances instances, int start, int end) throws Exception {
ClusterEvaluation eval = new ClusterEvaluation();
int bestNum = start;
double best = Double.POSITIVE_INFINITY;
double bic;
for (int c = start; c <= end; c++) {
clusterer.setNumClusters(c);
clusterer.buildClusterer(instances);
eval.setClusterer(clusterer);
eval.evaluateClusterer(instances);
bic = bic(eval.getLogLikelihood(), c, instances.numInstances());
logger.trace("numCluster " + c + " -> BIC: " + bic);
if (bic < best) {
best = bic;
bestNum = c;
logger.trace("bestNum: " + bestNum);
}
}
return bestNum;
}
示例3: main
import weka.clusterers.EM; //导入依赖的package包/类
public static void main(String args[]) throws Exception{
//load data
Instances data = new Instances(new BufferedReader(new FileReader("data/bank-data.arff")));
// new instance of clusterer
EM model = new EM();
// build the clusterer
model.buildClusterer(data);
System.out.println(model);
double logLikelihood = ClusterEvaluation.crossValidateModel(model, data, 10, new Random(1));
System.out.println(logLikelihood);
}
开发者ID:PacktPublishing,项目名称:Machine-Learning-End-to-Endguide-for-Java-developers,代码行数:17,代码来源:ClusteringTask.java
示例4: createClusterer
import weka.clusterers.EM; //导入依赖的package包/类
/**
*
* @param trainingData
* @param round
* @throws Exception
*/
protected AbstractClusterer createClusterer(MarkovAttributeSet aset, Instances trainingData) throws Exception {
if (trace.val) LOG.trace(String.format("Clustering %d %s instances with %d attributes", trainingData.numInstances(), CatalogUtil.getDisplayName(catalog_proc), aset.size()));
// Create the filter we need so that we only include the attributes in the given MarkovAttributeSet
Filter filter = aset.createFilter(trainingData);
// Using our training set to build the clusterer
int seed = this.rand.nextInt();
// SimpleKMeans inner_clusterer = new SimpleKMeans();
EM inner_clusterer = new EM();
String options[] = {
"-N", Integer.toString(1000), // num_partitions),
"-S", Integer.toString(seed),
"-I", Integer.toString(100),
};
inner_clusterer.setOptions(options);
FilteredClusterer filtered_clusterer = new FilteredClusterer();
filtered_clusterer.setFilter(filter);
filtered_clusterer.setClusterer(inner_clusterer);
AbstractClusterer clusterer = filtered_clusterer;
clusterer.buildClusterer(trainingData);
return (clusterer);
}
示例5: generateClassToCluster
import weka.clusterers.EM; //导入依赖的package包/类
public void generateClassToCluster(){
Remove filter = new Remove();
filter.setAttributeIndices("" + (weather.classIndex() + 1));
try {
filter.setInputFormat(weather);
Instances dataClusterer = Filter.useFilter(weather, filter);
clusterer = new EM();
clusterer.buildClusterer(dataClusterer);
ClusterEvaluation eval = new ClusterEvaluation();
eval.setClusterer(clusterer);
eval.evaluateClusterer(weather);
System.out.println(eval.clusterResultsToString());
} catch (Exception e) {
}
}
示例6: performClustering
import weka.clusterers.EM; //导入依赖的package包/类
@Override
public ClusteringResult performClustering(Instances dataset,
ParameterSet parameters) {
List<Integer> clusters = new ArrayList<Integer>();
String[] options = new String[2];
EM clusterer = new EM();
int numberOfIterations = parameters.getParameter(
EMClustererParameters.numberOfIterations).getValue();
options[0] = "-I";
options[1] = String.valueOf(numberOfIterations);
try {
clusterer.setOptions(options);
clusterer.buildClusterer(dataset);
Enumeration<?> e = dataset.enumerateInstances();
while (e.hasMoreElements()) {
clusters.add(clusterer.clusterInstance((Instance) e
.nextElement()));
}
ClusteringResult result = new ClusteringResult(clusters, null,
clusterer.numberOfClusters(), parameters.getParameter(
EMClustererParameters.visualization).getValue());
return result;
} catch (Exception ex) {
logger.log(Level.SEVERE, null, ex);
return null;
}
}
示例7: getClusterer
import weka.clusterers.EM; //导入依赖的package包/类
/**
* returns a configured cluster algorithm
*/
protected Clusterer getClusterer() {
EM c = new EM();
try {
c.setOptions(new String[0]);
}
catch (Exception e) {
e.printStackTrace();
}
return c;
}
示例8: clusterSubPopulations
import weka.clusterers.EM; //导入依赖的package包/类
/**
* Clustering dispatcher
* @requires the number of SNVs in a group to be bigger than 1
* @param group - SNV group to cluster based on AAF data
* @param alg - algorithm to use for clustering
*/
public Cluster[] clusterSubPopulations(SNVGroup group, ClusteringAlgorithms alg, int minNumClusters) {
switch(alg) {
case FUZZYCMEANS:
return fuzzyCMeans(group.getAlleleFreqBySample(), group.getNumSNVs(),
group.getNumSamples(), minNumClusters,
AAFClusterer.DEFAULT_FUZZIFIER, DistanceMetric.EUCLIDEAN);
case KMEANS:
return kmeans(group.getAlleleFreqBySample(), group.getNumSNVs(), group.getNumSamples(), minNumClusters);
case EM:
return em(group.getAlleleFreqBySample(), group.getNumSNVs(), group.getNumSamples());
default:
return null;
}
}