static public double do_test_single(weka.classifiers.Classifier classifier, weka.core.Instances insts_test) { weka.core.Instance currentInst = insts_test.lastInstance(); return(classifier.classifyInstance(currentInst)); }
private void btnDiscover_Click(object sender, EventArgs e) { string type = model.GetType().ToString(); bool flag = false; bool flag2 = false; //input kontrolleri if (nominal != null) { for (int i = 0; i < nominal.Length; i++) { if (nominal[i].SelectedIndex == -1) { flag = true; break; } } } if (numeric != null) { for (int i = 0; i < numeric.Length; i++) { if (String.IsNullOrEmpty(numeric[i].Text)) { flag2 = true; break; } } } if (numAtt == numeric.Length && flag2 == true) { MessageBox.Show("Please select value!", "Error Message!"); } else if (numAtt == nominal.Length && flag == true) { MessageBox.Show("Please select value!", "Error Message!"); } else if ((nominal.Length + numeric.Length) == numAtt && (flag == true || flag2 == true)) { MessageBox.Show("Please select value!", "Error Message!"); } else { weka.core.Instance newIns = new weka.core.Instance(numAtt + 1); newIns.setDataset(insts); int i1 = 0, i2 = 0; for (int i = 0; i < numAtt; i++) { //nominal if (typeAtt[i]) { newIns.setValue(i, nominal[i1].SelectedItem.ToString()); i1++; } //numeric else { newIns.setValue(i, double.Parse(numeric[i2].Text)); i2++; } } weka.core.Instances insts2 = new weka.core.Instances(insts); insts2.add(newIns); if (type == "weka.classifiers.bayes.NaiveBayes") { weka.filters.Filter myDiscretize = new weka.filters.unsupervised.attribute.Discretize(); myDiscretize.setInputFormat(insts2); insts2 = weka.filters.Filter.useFilter(insts2, myDiscretize); } else if (type == "weka.classifiers.functions.Logistic") { weka.filters.Filter myDummy = new weka.filters.unsupervised.attribute.NominalToBinary(); myDummy.setInputFormat(insts2); insts2 = weka.filters.Filter.useFilter(insts2, myDummy); weka.filters.Filter myNormalize = new weka.filters.unsupervised.instance.Normalize(); myNormalize.setInputFormat(insts2); insts2 = weka.filters.Filter.useFilter(insts2, myNormalize); } else if (type == "new weka.classifiers.lazy.IBk") { weka.filters.Filter myDummy = new weka.filters.unsupervised.attribute.NominalToBinary(); myDummy.setInputFormat(insts2); insts2 = weka.filters.Filter.useFilter(insts2, myDummy); weka.filters.Filter myNormalize = new weka.filters.unsupervised.instance.Normalize(); myNormalize.setInputFormat(insts2); insts2 = weka.filters.Filter.useFilter(insts2, myNormalize); } else if (type == "weka.classifiers.trees.J48") { } else if (type == "weka.classifiers.trees.RandomForest") { } else if (type == "weka.classifiers.trees.RandomTree") { } else if (type == "weka.classifiers.functions.MultilayerPerceptron") { weka.filters.Filter myDummy = new weka.filters.unsupervised.attribute.NominalToBinary(); myDummy.setInputFormat(insts2); insts2 = weka.filters.Filter.useFilter(insts2, myDummy); weka.filters.Filter myNormalize = new weka.filters.unsupervised.instance.Normalize(); myNormalize.setInputFormat(insts2); insts2 = weka.filters.Filter.useFilter(insts2, myNormalize); } else if (type == "weka.classifiers.functions.SMO") { weka.filters.Filter myDummy = new weka.filters.unsupervised.attribute.NominalToBinary(); myDummy.setInputFormat(insts2); insts2 = weka.filters.Filter.useFilter(insts2, myDummy); weka.filters.Filter myNormalize = new weka.filters.unsupervised.instance.Normalize(); myNormalize.setInputFormat(insts2); insts2 = weka.filters.Filter.useFilter(insts2, myNormalize); } double index = model.classifyInstance(insts2.lastInstance()); //Model okuma kısmı weka.classifiers.Classifier cls = (weka.classifiers.Classifier)weka.core.SerializationHelper.read("models/mdl.model"); lblResult2.Text = "Result= " + insts2.attribute(insts2.numAttributes() - 1).value(Convert.ToInt16(index)); } }