+ Dokumentation

#SPM-13: add work documentation 20m Cluster fertig
This commit is contained in:
Johannes Theiner 2019-04-25 16:19:23 +02:00
parent 368af15fd8
commit d9e041c1ae
1 changed files with 15 additions and 2 deletions

View File

@ -10,7 +10,7 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
/** /**
* Cluster Analysis * Cluster Analysis.
* *
* @author Johannes Theiner * @author Johannes Theiner
* @version 0.1 * @version 0.1
@ -24,6 +24,11 @@ public class Cluster implements Analysis<Map<Integer, Map<String, String>>> {
instances = load(file); instances = load(file);
} }
/**
* get result of cluster analysis.
*
* @return Result
*/
@Override @Override
public Map<Integer, Map<String, String>> getResult() { public Map<Integer, Map<String, String>> getResult() {
if(result == null) { if(result == null) {
@ -41,6 +46,7 @@ public class Cluster implements Analysis<Map<Integer, Map<String, String>>> {
e.printStackTrace(); e.printStackTrace();
} }
//creating a single cluster to get average, weka has no way to get that from a bigger one.
SimpleKMeans fullMeans = new SimpleKMeans(); SimpleKMeans fullMeans = new SimpleKMeans();
Instances fullCentroids = null; Instances fullCentroids = null;
try { try {
@ -54,6 +60,7 @@ public class Cluster implements Analysis<Map<Integer, Map<String, String>>> {
} }
assert fullCentroids != null; assert fullCentroids != null;
//creating real cluster
SimpleKMeans kMeans = new SimpleKMeans(); SimpleKMeans kMeans = new SimpleKMeans();
try { try {
kMeans.setNumClusters(5); kMeans.setNumClusters(5);
@ -70,10 +77,16 @@ public class Cluster implements Analysis<Map<Integer, Map<String, String>>> {
ex.printStackTrace(); ex.printStackTrace();
} }
} }
return result; return result;
} }
/**
* puts data into map.
*
* @param centroids cluster analysis result
* @param count current insert count
* @return count increment
*/
private int putIntoMap(Instances centroids, int count) { private int putIntoMap(Instances centroids, int count) {
for (int i = 0; i < centroids.numInstances(); i++) { for (int i = 0; i < centroids.numInstances(); i++) {
Map<String, String> map = new HashMap<>(); Map<String, String> map = new HashMap<>();