List of usage examples for weka.core Instance classAttribute
public Attribute classAttribute();
From source file:br.com.ufu.lsi.rebfnetwork.RBFNetwork.java
License:Open Source License
/** * Computes the distribution for a given instance * * @param instance the instance for which distribution is computed * @return the distribution// www .ja v a 2 s .co m * @throws Exception if the distribution can't be computed successfully */ public double[] distributionForInstance(Instance instance) throws Exception { // default model? if (m_ZeroR != null) { return m_ZeroR.distributionForInstance(instance); } m_standardize.input(instance); m_basisFilter.input(m_standardize.output()); Instance transformed = m_basisFilter.output(); return ((instance.classAttribute().isNominal() ? m_logistic.distributionForInstance(transformed) : m_linear.distributionForInstance(transformed))); }
From source file:classif.Prototyper.java
License:Open Source License
public double classifyInstance(Instance sample) throws Exception { // transform instance to sequence MonoDoubleItemSet[] sequence = new MonoDoubleItemSet[sample.numAttributes() - 1]; int shift = (sample.classIndex() == 0) ? 1 : 0; for (int t = 0; t < sequence.length; t++) { sequence[t] = new MonoDoubleItemSet(sample.value(t + shift)); }/* ww w . j a va2 s . co m*/ Sequence seq = new Sequence(sequence); double minD = Double.MAX_VALUE; String classValue = null; for (ClassedSequence s : prototypes) { double tmpD = seq.distance(s.sequence); if (tmpD < minD) { minD = tmpD; classValue = s.classValue; } } // System.out.println(prototypes.size()); return sample.classAttribute().indexOfValue(classValue); }
From source file:classif.PrototyperEUC.java
License:Open Source License
@Override public double classifyInstance(Instance sample) throws Exception { // transform instance to sequence MonoDoubleItemSet[] sequence = new MonoDoubleItemSet[sample.numAttributes() - 1]; int shift = (sample.classIndex() == 0) ? 1 : 0; for (int t = 0; t < sequence.length; t++) { sequence[t] = new MonoDoubleItemSet(sample.value(t + shift)); }// w w w . j ava 2 s .c om Sequence seq = new Sequence(sequence); double minD = Double.MAX_VALUE; String classValue = null; for (ClassedSequence s : prototypes) { double tmpD = seq.distanceEuc(s.sequence); if (tmpD < minD) { minD = tmpD; classValue = s.classValue; } } // System.out.println(prototypes.size()); // System.out.println(classValue); return sample.classAttribute().indexOfValue(classValue); }
From source file:com.tum.classifiertest.FastRfBagging.java
License:Open Source License
/** * Calculates the class membership probabilities for the given test * instance.//from ww w . j a va2 s. c o m * * @param instance the instance to be classified * * @return preedicted class probability distribution * * @throws Exception if distribution can't be computed successfully */ @Override public double[] distributionForInstance(Instance instance) throws Exception { double[] sums = new double[instance.numClasses()], newProbs; //Log.i("FastRfBagging", " sums length : " + sums.length);//problem is that it is 1 instead of 2. coz instance is not nominal //Log.i("FastRfBagging", "m_NumIterations : " + m_NumIterations); for (int i = 0; i < m_NumIterations; i++) { if (instance.classAttribute().isNumeric()) { sums[0] += m_Classifiers[i].classifyInstance(instance); //Log.i("FastRfBagging", "yesNumeric , sum value : " + sums[0]); } else { newProbs = m_Classifiers[i].distributionForInstance(instance); //Log.i("FastRfBagging", "notNumeric , newProbs length : " + newProbs.length); for (int j = 0; j < newProbs.length; j++) sums[j] += newProbs[j]; } } if (instance.classAttribute().isNumeric()) { sums[0] /= (double) m_NumIterations; return sums; } else if (Utils.eq(Utils.sum(sums), 0)) { return sums; } else { Utils.normalize(sums); return sums; } }
From source file:com.zazhu.BlueHub.BlueHub.java
License:Apache License
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (D)/*from w ww . j ava2 s .co m*/ Log.e(TAG, "+++ ON CREATE +++"); // Set up the window layout requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); setContentView(R.layout.main); getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title); // Set up the custom title mTitle = (TextView) findViewById(R.id.title_left_text); mTitle.setText(R.string.app_name); mTitle = (TextView) findViewById(R.id.title_right_text); // Get local Bluetooth adapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); // If the adapter is null, then Bluetooth is not supported if (mBluetoothAdapter == null) { Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show(); finish(); return; } ImageButton run_button = (ImageButton) findViewById(R.id.run_button); ImageButton stop_button = (ImageButton) findViewById(R.id.stop_button); ImageButton info_button = (ImageButton) findViewById(R.id.info_button); run_button.setEnabled(true); stop_button.setEnabled(false); run_button.setOnClickListener(new OnClickListener() { public void onClick(View v) { // for using threads: http://android-developers.blogspot.com/2009/05/painless-threading.html ImageButton run_button = (ImageButton) findViewById(R.id.run_button); ImageButton stop_button = (ImageButton) findViewById(R.id.stop_button); run_button.setEnabled(false); stop_button.setEnabled(true); // creates the bio-feedback variables final Vibrator vib = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); //boolean acousticFeedback = gui_sharedPrefs.getAcousticFlag(getApplicationContext()); //boolean tactileFeedback = gui_sharedPrefs.getTactileFlag(getApplicationContext()); //char listselection = gui_sharedPrefs.getSensorValue(getApplicationContext()); Log.i("classifier", "Current classifier: " + Character.toString(mCurrentClassifier) + " Preferences: " + gui_sharedPrefs.getSensorValue(BlueHub.this)); if (mCurrentClassifier == gui_sharedPrefs.getSensorValue(BlueHub.this)) { // this is useful for the thread that is doing the classification when the start button is pressed mShouldContinue = true; mTitle.setText("Classifying..."); Thread background = new Thread(new Runnable() { public void run() { while (mShouldContinue & mCurrentClassifier == gui_sharedPrefs.getSensorValue(BlueHub.this)) { try { System.out.println("Sleeping beauty ... for 0.5 s"); Thread.sleep(500); //sleeps for 0.5s // getting the instance from the last data (taking into account the sensor selected) // create a copy to avoid to empty the original queue LinkedList<String> mSensorQueueCopy = new LinkedList<String>(); mSensorQueueCopy.addAll(mSensorQueue); System.out.println(mSensorQueueCopy.toString()); Instance instToBeClassified = processingSenseData(mSensorQueueCopy, gui_sharedPrefs.getSensorValue(getApplicationContext())); System.out.println(instToBeClassified.toString()); // classify double classRes = mCls.classifyInstance(instToBeClassified); System.out.println(String.valueOf(classRes)); System.out.println(instToBeClassified.classAttribute().value((int) classRes)); if (classRes == FOG) { // what kind of feedback was selected if (gui_sharedPrefs.getAcousticFlag(getApplicationContext())) { // TODO here to put sound } else if (gui_sharedPrefs.getTactileFlag(getApplicationContext())) { vib.vibrate(2000); // vibrates for 1s } } } catch (Exception e) { Log.v("Error", e.toString()); } } } }); background.start(); } else { mTitle.setText("Reloading classifier..."); reinitializeUponSensorChange(); run_button.setEnabled(true); stop_button.setEnabled(false); mTitle.setText("Reinitialized, press play to begin."); } } }); stop_button.setOnClickListener(new OnClickListener() { public void onClick(View v) { ImageButton run_button = (ImageButton) findViewById(R.id.run_button); ImageButton stop_button = (ImageButton) findViewById(R.id.stop_button); run_button.setEnabled(true); stop_button.setEnabled(false); //Sinziana's stop classifier code // here is not need to do nothing -- the scenario will change and the classifier code won't run (being in the the run_button loop) mShouldContinue = false; mTitle.setText("Classifier paused!"); } }); info_button.setOnClickListener(new OnClickListener() { public void onClick(View v) { Toast.makeText(getApplicationContext(), "The research leading to these results has received funding from the European Union - Seventh Framework Programme (FP7/2007-2013) under grant agreement n288516 (CuPiD project).", Toast.LENGTH_LONG).show(); //.getSensorValue(getApplicationContext()))); } }); //TODO: check to see if service has already been started by another app Intent intent = new Intent(this, BlueHubService.class); startService(intent); doBindService(); //gui_sharedPrefs prefs = new gui_sharedPrefs(); // read classifier from serialized object // DEFAULT reading -- external readClassifier(INTERNAL); //gui_sharedPrefs.setSensorValue(this, INTERNAL); //Log.i(TAG, "Preference upon creation: " + Character.toString(gui_sharedPrefs.getSensorValue(BlueHub.this))); mCurrentClassifier = INTERNAL; //Toast.makeText(this, "Classifier for internal sensors loaded", Toast.LENGTH_SHORT).show(); // test if I read the classifier System.out.println(mCls.toString()); }
From source file:core.Core.java
public String run() throws Exception { ConverterUtils.DataSource source = new ConverterUtils.DataSource("src/files/powerpuffgirls.arff"); HashMap<String, Classifier> hash = new HashMap<>(); hash.put("J48", new J48()); hash.put("NaiveBayes", new NaiveBayes()); hash.put("IBk=1", new IBk(1)); hash.put("IBk=3", new IBk(3)); hash.put("MultilayerPerceptron", new MultilayerPerceptron()); LibSVM svm = new LibSVM(); hash.put("LibSVM", svm); Instances ins = source.getDataSet(); ins.setClassIndex(4);/*from www. j a va 2 s.com*/ StringBuilder sb = new StringBuilder(); int blossom = 0; int bubbles = 0; Instance test = null; for (Map.Entry<String, Classifier> entry : hash.entrySet()) { Classifier c = entry.getValue(); c.buildClassifier(ins); test = new Instance(5); float[] array = classifyImage(); test.setDataset(ins); test.setValue(0, array[0]); test.setValue(1, array[1]); test.setValue(2, array[2]); test.setValue(3, array[3]); double prob[] = c.distributionForInstance(test); sb.append("<em>"); sb.append(entry.getKey()); sb.append(":</em>"); sb.append("<br/>"); for (int i = 0; i < prob.length; i++) { String value = test.classAttribute().value(i); if (getRoundedValue(prob[i]) >= CUT_NOTE) { if (getClassValue(value)) blossom++; else bubbles++; } sb.append(getClassName(value)); sb.append(": "); sb.append("<strong>"); sb.append(getRoundedValue(prob[i]) < CUT_NOTE ? "Rejeitado!" : getValueFormatted(prob[i])); sb.append("</strong>"); sb.append(" "); } sb.append("<br/>"); System.out.println("blossom: " + blossom); System.out.println("bubbles: " + bubbles); System.out.println("=================\n"); } sb.append(blossom > bubbles ? "<h3> a Florzinha!</h3>" : "<h3> a Lindinha!</h3>"); blossom = 0; bubbles = 0; return sb.toString(); }
From source file:edu.cuny.qc.speech.AuToBI.classifier.WekaClassifier.java
License:Open Source License
/** * Evaluates the weka classifier on a single point. * * @param testing_point The point to evaluate * @return a distribution of the hypotheses. * @throws Exception//from ww w. jav a 2 s . c o m */ public Distribution distributionForInstance(Word testing_point) throws Exception { Instance test_instance = ClassifierUtils.convertWordToInstance(testing_point, features, class_attribute); double[] distribution = weka_classifier.distributionForInstance(test_instance); Distribution d = new Distribution(); for (int i = 0; i < test_instance.classAttribute().numValues(); ++i) { d.put(test_instance.classAttribute().value(i), distribution[i]); } return d; }
From source file:elh.eus.absa.CLI.java
License:Open Source License
/** * Main access to the polarity tagging functionalities. Target based polarity. * * @throws IOException// www . j a va 2 s . c om * input output exception if problems with corpora */ public final void evalATP(final InputStream inputStream) throws IOException, JDOMException { String paramFile = parsedArguments.getString("params"); String corpusFormat = parsedArguments.getString("corpusFormat"); String model = parsedArguments.getString("model"); String lang = parsedArguments.getString("language"); String classnum = parsedArguments.getString("classnum"); boolean ruleBased = parsedArguments.getBoolean("ruleBasedClassifier"); boolean printPreds = parsedArguments.getBoolean("outputPredictions"); //Read corpus sentences CorpusReader reader = new CorpusReader(inputStream, corpusFormat, lang); //Rule-based Classifier. if (ruleBased) { Properties params = new Properties(); params.load(new FileInputStream(new File(paramFile))); String posModelPath = params.getProperty("pos-model"); String lemmaModelPath = params.getProperty("lemma-model"); String kafDir = params.getProperty("kafDir"); /* polarity lexicon. Domain specific polarity lexicon is given priority. * If no domain lexicon is found it reverts to general polarity lexicon. * If no general polarity lexicon is found program exits with error message. */ String lex = params.getProperty("polarLexiconDomain", "none"); if (lex.equalsIgnoreCase("none")) { lex = params.getProperty("polarLexiconGeneral", "none"); if (lex.equalsIgnoreCase("none")) { System.err.println("Elixa Error :: Rule-based classifier is selected but no polarity" + " lexicon has been specified. Either specify one or choose ML classifier"); System.exit(1); } } File lexFile = new File(lex); Evaluator evalDoc = new Evaluator(lexFile, "lemma"); for (String oId : reader.getOpinions().keySet()) { // sentence posTagging String taggedKaf = reader.tagSentenceTab(reader.getOpinion(oId).getsId(), kafDir, posModelPath, lemmaModelPath); //process the postagged sentence with the word count based polarity tagger Map<String, String> results = evalDoc.polarityScoreTab(taggedKaf, lexFile.getName()); String lblStr = results.get("polarity"); String actual = "?"; if (reader.getOpinion(oId).getPolarity() != null) { actual = reader.getOpinion(oId).getPolarity(); } String rId = reader.getOpinion(oId).getsId().replaceFirst("_g$", ""); System.out.println(rId + "\t" + actual + "\t" + lblStr + "\t" + reader.getOpinionSentence(oId)); reader.getOpinion(oId).setPolarity(lblStr); } } //ML Classifier (default) else { Features atpTest = new Features(reader, paramFile, classnum, model); Instances testdata; if (corpusFormat.startsWith("tab") && !corpusFormat.equalsIgnoreCase("tabNotagged")) { testdata = atpTest.loadInstancesTAB(true, "atp"); } else { testdata = atpTest.loadInstances(true, "atp"); } // setting class attribute (entCat|attCat|entAttCat|polarityCat) testdata.setClass(testdata.attribute("polarityCat")); WekaWrapper classify; try { classify = new WekaWrapper(model); System.err.println("evalAtp : going to test the model"); //sort according to the instanceId //traindata.sort(atpTrain.getAttIndexes().get("instanceId")); //Instances testdata = new Instances(traindata); //testdata.deleteAttributeAt(0); //classify.setTestdata(testdata); classify.setTestdata(testdata); classify.testModel(model); if (printPreds) { for (String oId : reader.getOpinions().keySet()) { int iId = atpTest.getOpinInst().get(oId); Instance i = testdata.get(iId - 1); double label = classify.getMLclass().classifyInstance(i); String lblStr = i.classAttribute().value((int) label); String actual = "?"; if (reader.getOpinion(oId).getPolarity() != null) { actual = reader.getOpinion(oId).getPolarity(); } String rId = reader.getOpinion(oId).getsId().replaceFirst("_g$", ""); String oSent = reader.getOpinionSentence(oId); if (corpusFormat.startsWith("tab")) { StringBuilder sb = new StringBuilder(); for (String kk : oSent.split("\n")) { sb.append(kk.split("\\t")[0]); sb.append(" "); } oSent = sb.toString(); } System.out.println(rId + "\t" + actual + "\t" + lblStr + "\t" + oSent + "\t" + reader.getOpinionSentence(oId).replaceAll("\n", " ").replaceAll("\\t", ":::")); reader.getOpinion(oId).setPolarity(lblStr); } } //reader.print2Semeval2015format(model+"tagATP.xml"); //reader.print2conll(model+"tagAtp.conll"); } catch (Exception e) { e.printStackTrace(); } } }
From source file:elh.eus.absa.CLI.java
License:Open Source License
/** * Main access to the polarity tagging functionalities. Target based polarity. * * @throws IOException/*from w ww. j a v a 2s .c o m*/ * input output exception if problems with corpora * @throws JDOMException */ public final void tagATP(final InputStream inputStream) throws IOException, JDOMException { // load training parameters file String paramFile = parsedArguments.getString("params"); String corpusFormat = parsedArguments.getString("corpusFormat"); String model = parsedArguments.getString("model"); String lang = parsedArguments.getString("language"); String classnum = parsedArguments.getString("classnum"); boolean ruleBased = parsedArguments.getBoolean("ruleBasedClassifier"); //Read corpus sentences CorpusReader reader = new CorpusReader(inputStream, corpusFormat, lang); //Rule-based Classifier. if (ruleBased) { Properties params = new Properties(); params.load(new FileInputStream(new File(paramFile))); String posModelPath = params.getProperty("pos-model"); String lemmaModelPath = params.getProperty("lemma-model"); String kafDir = params.getProperty("kafDir"); /* polarity lexicon. Domain specific polarity lexicon is given priority. * If no domain lexicon is found it reverts to general polarity lexicon. * If no general polarity lexicon is found program exits with error message. */ String lex = params.getProperty("polarLexiconDomain", "none"); if (lex.equalsIgnoreCase("none")) { lex = params.getProperty("polarLexiconGeneral", "none"); if (lex.equalsIgnoreCase("none")) { System.err.println("Elixa Error :: Rule-based classifier is selected but no polarity" + " lexicon has been specified. Either specify one or choose ML classifier"); System.exit(1); } } File lexFile = new File(lex); Evaluator evalDoc = new Evaluator(lexFile, "lemma"); for (String oId : reader.getOpinions().keySet()) { // sentence posTagging String taggedKaf = reader.tagSentenceTab(reader.getOpinion(oId).getsId(), kafDir, posModelPath, lemmaModelPath); //process the postagged sentence with the word count based polarity tagger Map<String, String> results = evalDoc.polarityScoreTab(taggedKaf, lexFile.getName()); String lblStr = results.get("polarity"); String actual = "?"; if (reader.getOpinion(oId).getPolarity() != null) { actual = reader.getOpinion(oId).getPolarity(); } String rId = reader.getOpinion(oId).getsId().replaceFirst("_g$", ""); System.out.println(rId + "\t" + actual + "\t" + lblStr + "\t" + reader.getOpinionSentence(oId)); reader.getOpinion(oId).setPolarity(lblStr); } } else { Features atpTrain = new Features(reader, paramFile, classnum, model); Instances traindata; if (corpusFormat.startsWith("tab") && !corpusFormat.equalsIgnoreCase("tabNotagged")) { traindata = atpTrain.loadInstancesTAB(true, "atp"); } else if (lang.equalsIgnoreCase("eu") && (corpusFormat.equalsIgnoreCase("tabNotagged") || corpusFormat.equalsIgnoreCase("ireom"))) { traindata = atpTrain.loadInstancesConll(true, "atp"); } else { traindata = atpTrain.loadInstances(true, "atp"); } // setting class attribute (entCat|attCat|entAttCat|polarityCat) traindata.setClass(traindata.attribute("polarityCat")); WekaWrapper classify; try { classify = new WekaWrapper(model); System.err.println(); //sort according to the instanceId //traindata.sort(atpTrain.getAttIndexes().get("instanceId")); //Instances testdata = new Instances(traindata); //testdata.deleteAttributeAt(0); //classify.setTestdata(testdata); classify.setTestdata(traindata); classify.loadModel(model); for (String oId : reader.getOpinions().keySet()) { int iId = atpTrain.getOpinInst().get(oId); Instance i = traindata.get(iId - 1); double label = classify.getMLclass().classifyInstance(i); String lblStr = i.classAttribute().value((int) label); String actual = "?"; if (reader.getOpinion(oId).getPolarity() != null) { actual = reader.getOpinion(oId).getPolarity(); } String rId = reader.getOpinion(oId).getsId().replaceFirst("_g$", ""); String oSent = reader.getOpinionSentence(oId); if (corpusFormat.startsWith("tab")) { StringBuilder sb = new StringBuilder(); for (String kk : oSent.split("\n")) { sb.append(kk.split("\\t")[0]); sb.append(" "); } oSent = sb.toString(); } System.out.println(rId + "\t" + actual + "\t" + lblStr + "\t" + oSent + "\t" + reader.getOpinionSentence(oId).replaceAll("\n", " ").replaceAll("\\t", ":::")); reader.getOpinion(oId).setPolarity(lblStr); } //reader.print2Semeval2015format(model+"tagATP.xml"); //reader.print2conll(model+"tagAtp.conll"); } catch (Exception e) { e.printStackTrace(); } } }
From source file:GroupProject.DMChartUI.java
/** * Action for the generate button//w w w .j av a 2s . c o m * It reads the user input from the table and the selected options and performs * a classifiecation of the user input * the user can choose linear regression, naive bayes classifier, or j48 trees to classify * */ private void generateButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_generateButtonActionPerformed // TODO add your handling code here: // TODO add your handling code here: //File file = new File("studentTemp.csv"); CSVtoArff converter = new CSVtoArff(); Instances students = null; Instances students2 = null; try { converter.convert("studentTemp.csv", "studentTemp.arff"); } catch (IOException ex) { Logger.getLogger(DMChartUI.class.getName()).log(Level.SEVERE, null, ex); } try { students = new Instances(new BufferedReader(new FileReader("studentTemp.arff"))); students2 = new Instances(new BufferedReader(new FileReader("studentTemp.arff"))); } catch (IOException ex) { Logger.getLogger(DMChartUI.class.getName()).log(Level.SEVERE, null, ex); } //get column to predict values for //int target=students.numAttributes()-1; int target = dataSelector.getSelectedIndex() + 1; System.out.printf("this is the target: %d\n", target); //set target students.setClassIndex(target); students2.setClassIndex(target); //case on which radio button is selected //Linear Regressions if (LRB.isSelected()) { LinearRegression model = null; if (Lmodel != null) { model = Lmodel; } else { buildLinearModel(); model = Lmodel; } System.out.println("im doing linear regression"); equationDisplayArea.setText(model.toString()); System.out.println("im going to get the instance"); Instance prediction2 = getInstance(true); Remove remove = new Remove(); int[] toremove = { 0, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 16, 17 }; remove.setAttributeIndicesArray(toremove); try { remove.setInputFormat(students); } catch (Exception ex) { Logger.getLogger(DMChartUI.class.getName()).log(Level.SEVERE, null, ex); } Instances instNew = null; try { instNew = Filter.useFilter(students, remove); } catch (Exception ex) { Logger.getLogger(DMChartUI.class.getName()).log(Level.SEVERE, null, ex); } prediction2.setDataset(instNew); System.err.print("i got the instance"); double result = 0; try { result = model.classifyInstance(prediction2); } catch (Exception ex) { Logger.getLogger(DMChartUI.class.getName()).log(Level.SEVERE, null, ex); } System.out.printf("the result : %f \n ", result); predictValue.setText(Double.toString(result)); System.out.println("I'm done with Linear Regression"); } //Naive Bayes else if (NBB.isSelected()) { Classifier cModel = null; if (NBmodel != null) { cModel = NBmodel; } else { buildNBClassifier(); cModel = NBmodel; } System.out.println("im doing NB"); //build test Evaluation eTest = null; try { eTest = new Evaluation(students); } catch (Exception ex) { Logger.getLogger(DMChartUI.class.getName()).log(Level.SEVERE, null, ex); } System.out.println("Using NB"); try { eTest.evaluateModel(cModel, students); } catch (Exception ex) { Logger.getLogger(DMChartUI.class.getName()).log(Level.SEVERE, null, ex); } //display the test results to console String strSummary = eTest.toSummaryString(); System.out.println(strSummary); //build instance to predict System.out.println("im going to get the instance"); Instance prediction2 = getInstance(false); prediction2.setDataset(students); System.err.print("i got the instance"); //replace with loop stating the class names //fit text based on name of categories double pred = 0; try { pred = cModel.classifyInstance(prediction2); prediction2.setClassValue(pred); } catch (Exception ex) { Logger.getLogger(DMChartUI.class.getName()).log(Level.SEVERE, null, ex); } //get the predicted value and set predictValue to it predictValue.setText(prediction2.classAttribute().value((int) pred)); System.out.println("I'm done with Naive Bayes"); double[] fDistribution2 = null; try { fDistribution2 = cModel.distributionForInstance(prediction2); } catch (Exception ex) { Logger.getLogger(DMChartUI.class.getName()).log(Level.SEVERE, null, ex); } double max = 0; int maxindex = 0; max = fDistribution2[0]; for (int i = 0; i < fDistribution2.length; i++) { if (fDistribution2[i] > max) { maxindex = i; max = fDistribution2[i]; } System.out.println("the value at " + i + " : " + fDistribution2[i]); System.out.println("the label at " + i + prediction2.classAttribute().value(i)); } prediction2.setClassValue(maxindex); predictValue.setText(prediction2.classAttribute().value(maxindex)); } //J48 Tree else if (JB.isSelected()) { System.out.println("im doing j48 "); Classifier jModel = null; if (Jmodel != null) { jModel = Jmodel; } else { buildJClassifier(); jModel = Jmodel; } //test model Evaluation eTest2 = null; try { eTest2 = new Evaluation(students); } catch (Exception ex) { Logger.getLogger(DMChartUI.class.getName()).log(Level.SEVERE, null, ex); } System.out.println("Using J48 test"); try { eTest2.evaluateModel(jModel, students); } catch (Exception ex) { Logger.getLogger(DMChartUI.class.getName()).log(Level.SEVERE, null, ex); } String strSummary2 = eTest2.toSummaryString(); System.out.println(strSummary2); System.out.println("im going to get the instance"); Instance prediction2 = getInstance(false); prediction2.setDataset(students); System.err.print("i got the instance\n"); double pred = 0; try { pred = jModel.classifyInstance(prediction2); prediction2.setClassValue(pred); System.out.println("i did a prediction"); } catch (Exception ex) { Logger.getLogger(DMChartUI.class.getName()).log(Level.SEVERE, null, ex); } //get the predicted value and set predictValue to it System.out.println("this was pred:" + pred); predictValue.setText(prediction2.classAttribute().value((int) pred)); System.out.println("I'm done with J48"); //replace with loop stating the class names //fit text based on name of categories double[] fDistribution2 = null; try { fDistribution2 = jModel.distributionForInstance(prediction2); } catch (Exception ex) { Logger.getLogger(DMChartUI.class.getName()).log(Level.SEVERE, null, ex); } double max = 0; int maxindex = 0; max = fDistribution2[0]; for (int i = 0; i < fDistribution2.length; i++) { if (fDistribution2[i] > max) { maxindex = i; max = fDistribution2[i]; } System.out.println("the value at " + i + " : " + fDistribution2[i]); System.out.println("the label at " + i + " " + prediction2.classAttribute().value(i)); } prediction2.setClassValue(maxindex); predictValue.setText(prediction2.classAttribute().value(maxindex)); } }