public HashSet <HtmlNode> RunOnTestSet() { HashSet <HtmlNode> classifierSelectedNodes = new HashSet <HtmlNode>(); InitTest(); foreach (string featureString in FeaturesUsed) { HashSet <HtmlNode> resNodes = DomPool.TESTRunXpathQuery(useNormalPerformanceQUERY(featureString)); foreach (HtmlNode nd in resNodes) { if (!testAllNodes.Contains(nd)) { continue; } testNodeFeatures[nd].Add(featureString); } } FastVector fvWekaAttributes = GetDataSetAtts(); Instances testSet = new Instances("TestSet", fvWekaAttributes, 10); testSet.setClassIndex(fvWekaAttributes.size() - 1); foreach (HtmlNode currNode in testAllNodes) { Instance item = new SparseInstance(fvWekaAttributes.size()); for (int i = 0; i < fvWekaAttributes.size() - 1; i++) { weka.core.Attribute currFeature = (weka.core.Attribute)fvWekaAttributes.elementAt(i); if (testNodeFeatures[currNode].Contains(currFeature.name())) { item.setValue(currFeature, 1); } else { item.setValue(currFeature, 0); } } //set the class weka.core.Attribute classFeature = (weka.core.Attribute)fvWekaAttributes.elementAt(fvWekaAttributes.size() - 1); //string rightVal = DomPool.TargetNodes.Contains(currNode) ? "yes" : "no"; item.setDataset(testSet); double classifierdv = classifier.classifyInstance(item); string classifierVal = classFeature.value((int)classifierdv); if (classifierVal.Equals("yes")) { classifierSelectedNodes.Add(currNode); } testSet.add(item); } return(classifierSelectedNodes); }
public void Classify() { // Train Dataset yolu ConverterUtils.DataSource source1 = new ConverterUtils.DataSource(TrainPath); Instances train = source1.getDataSet(); if (train.classIndex() == -1) { train.setClassIndex(train.numAttributes() - 1); } //Tahmin edilecek data'nın yolu ConverterUtils.DataSource source2 = new ConverterUtils.DataSource(Application.StartupPath + "\\UrunPredict.arff"); Instances test = source2.getDataSet(); if (test.classIndex() == -1) { test.setClassIndex(train.numAttributes() - 1); } //Sınıflandırma algoritmasının belirlenmesi /* weka.classifiers.lazy.IBk ibk = new weka.classifiers.lazy.IBk(); * //En yakın komşu 'k' değeri 3 olarak belirleniyor * ibk.setKNN(3); * ibk.buildClassifier(train);*/ //NAIVE BAYES ALGORITMASI UYGULAMA NaiveBayes naiveBayes = new NaiveBayes(); naiveBayes.buildClassifier(train); //Sınıflandırma işlemi uygulanıyor double label = naiveBayes.classifyInstance(test.instance(0)); test.instance(0).setClassValue(label); //Yeni sınıflandısrılan verinin train veri setine eklenmesi string AddClassifiedData = txtSicaklik.Text + "," + txtNem.Text + "," + txtYagis.Text + "," + cmbDeniz.Text + "," + test.instance(0).stringValue(4); StreamWriter Kayit = File.AppendText(TrainPath); Kayit.WriteLine("\n" + AddClassifiedData); Kayit.Close(); ShowImageAndInfo(test.instance(0).stringValue(4)); }