List of usage examples for weka.attributeSelection AttributeSelection toResultsString
public String toResultsString()
From source file:adams.flow.transformer.WekaAttributeSelectionSummary.java
License:Open Source License
/** * Executes the flow item./*from w ww .j a v a 2 s . com*/ * * @return null if everything is fine, otherwise error message */ @Override protected String doExecute() { String result; AttributeSelection eval; boolean crossValidation; WekaAttributeSelectionContainer cont; result = null; if (m_InputToken.getPayload() instanceof AttributeSelection) { eval = (AttributeSelection) m_InputToken.getPayload(); try { eval.CVResultsString(); // throws an exception if no CV performed crossValidation = true; } catch (Exception e) { crossValidation = false; } } else { cont = (WekaAttributeSelectionContainer) m_InputToken.getPayload(); eval = (AttributeSelection) cont.getValue(WekaAttributeSelectionContainer.VALUE_EVALUATION); crossValidation = cont.hasValue(WekaAttributeSelectionContainer.VALUE_FOLD_COUNT); } try { if (crossValidation) m_OutputToken = new Token(eval.CVResultsString()); else m_OutputToken = new Token(eval.toResultsString()); } catch (Exception e) { result = handleException("Failed to generate summary string!", e); } return result; }
From source file:it.poliba.sisinflab.simlib.featureSelection.methods.CHI.java
public void execute(String dataset) { try {// w w w . ja v a 2 s.c o m if (dataset.length() == 0) throw new IllegalArgumentException(); // Load input dataset. DataSource source = new DataSource(dataset); System.out.println("Reading instances..."); Instances data = source.getDataSet(); // Performs a principal components analysis. ChiSquaredAttributeEval chiEvaluator = new ChiSquaredAttributeEval(); // Ranking the attributes. Ranker ranker = new Ranker(); // Specify the number of attributes to select from the ranked list. /*ranker.setThreshold(-1.7976931348623157E308); ranker.setNumToSelect(-1); ranker.setGenerateRanking(true);*/ ranker.setNumToSelect(-1); AttributeSelection selector = new AttributeSelection(); System.out.println("Selecting attributes..."); selector.setSearch(ranker); selector.setEvaluator(chiEvaluator); selector.SelectAttributes(data); PrintStream o = new PrintStream(new File("data/" + "CHIResults" + ".txt")); System.setOut(o); System.out.println(Arrays.toString(selector.rankedAttributes())); System.out.println(Arrays.toString(selector.selectedAttributes())); //System.out.println(selector.CVResultsString()); System.out.println(selector.toResultsString()); System.out.println(); } catch (IllegalArgumentException e) { System.err.println("Error"); } catch (Exception e) { e.printStackTrace(); } }
From source file:it.poliba.sisinflab.simlib.featureSelection.methods.PCA.java
public void execute(String dataset) { try {/* w ww .j a v a 2 s . co m*/ if (dataset.length() == 0) throw new IllegalArgumentException(); // Load input dataset. DataSource source = new DataSource(dataset); Instances data = source.getDataSet(); // Performs a principal components analysis. PrincipalComponents pcaEvaluator = new PrincipalComponents(); // Sets the amount of variance to account for when retaining principal // components. pcaEvaluator.setVarianceCovered(1.0); // Sets maximum number of attributes to include in transformed attribute // names. pcaEvaluator.setMaximumAttributeNames(-1); // Scaled X such that the variance of each feature is 1. boolean scale = true; if (scale) { pcaEvaluator.setCenterData(true); } else { pcaEvaluator.setCenterData(false); } // Ranking the attributes. Ranker ranker = new Ranker(); ranker.setNumToSelect(-1); AttributeSelection selector = new AttributeSelection(); selector.setSearch(ranker); selector.setEvaluator(pcaEvaluator); selector.SelectAttributes(data); // Transform data into eigenvector basis. Instances transformedData = selector.reduceDimensionality(data); PrintStream o = new PrintStream(new File("data/" + "PCAResults" + ".txt")); System.setOut(o); System.out.println(Arrays.toString(selector.rankedAttributes())); System.out.println(Arrays.toString(selector.selectedAttributes())); //System.out.println(selector.CVResultsString()); System.out.println(selector.toResultsString()); System.out.println(); } catch (IllegalArgumentException e) { System.err.println("Error"); } catch (Exception e) { e.printStackTrace(); } }
From source file:miRdup.WekaModule.java
License:Open Source License
public static void attributeSelection(File arff, String outfile) { // load data//w w w. j a va 2 s .c o m try { PrintWriter pw = new PrintWriter(new FileWriter(outfile)); DataSource source = new DataSource(arff.toString()); Instances data = source.getDataSet(); if (data.classIndex() == -1) { data.setClassIndex(data.numAttributes() - 1); } AttributeSelection attrsel = new AttributeSelection(); weka.attributeSelection.InfoGainAttributeEval eval = new weka.attributeSelection.InfoGainAttributeEval(); weka.attributeSelection.Ranker rank = new weka.attributeSelection.Ranker(); rank.setOptions(weka.core.Utils.splitOptions("-T -1.7976931348623157E308 -N -1")); if (Main.debug) { System.out.print("Model options: " + rank.getClass().getName().trim() + " "); } for (String s : rank.getOptions()) { System.out.print(s + " "); } attrsel.setEvaluator(eval); attrsel.setSearch(rank); attrsel.setFolds(10); attrsel.SelectAttributes(data); //attrsel.CrossValidateAttributes(); System.out.println(attrsel.toResultsString()); pw.println(attrsel.toResultsString()); //evaluation.crossValidateModel(classifier, data, 10, new Random(1)); pw.flush(); pw.close(); } catch (Exception e) { e.printStackTrace(); } }