public static weka.clusterers.Clusterer CreateCluster() { weka.clusterers.RandomizableClusterer cluster = new weka.clusterers.SimpleKMeans(); cluster.setOptions(weka.core.Utils.splitOptions("-V -M -N 10 -A \"weka.core.EuclideanDistance -R first-last\" -I 500 -O -S 10")); return(cluster); }
public void TestCluster() { //string modelFileName = string.Format("{0}\\cluster.model", m_baseDir); //var cluster = (weka.clusterers.SimpleKMeans)weka.core.SerializationHelper.read(modelFileName); weka.clusterers.SimpleKMeans cluster = new weka.clusterers.SimpleKMeans(); Instances origInstances = WekaUtils.LoadInstances(GetArffFileName(true, "B", "new")); Instances noClassInstances = WekaUtils.RemoveClassAttribute(origInstances); //foreach (Instance i in origInstances) //{ // List<double> d = new List<double>(); // foreach (Instance j in cluster.getClusterCentroids()) // { // d.Add(cluster.getDistanceFunction().distance(i, j)); // } //} for (int c = 5; c <= 200; ++c) { cluster.setOptions(weka.core.Utils.splitOptions(string.Format("-V -M -N {0} -A \"weka.core.EuclideanDistance -R first-last\" -I 500 -O -S 10", c))); cluster.buildClusterer(noClassInstances); double d = cluster.getSquaredError(); WekaUtils.Instance.WriteLog(string.Format("{0}: {1}", c, d)); } }