/** Default constructor. */ public FilteredAssociator() { m_Associator = new Apriori(); m_Filter = new MultiFilter(); ((MultiFilter) m_Filter) .setFilters(new Filter[] {new weka.filters.unsupervised.attribute.ReplaceMissingValues()}); m_ClassIndex = -1; }
/** * Parses the options for this object. * * <p> * <!-- options-start --> * Valid options are: * * <p> * * <pre> -D * Turns on output of debugging information.</pre> * * <pre> -A <Haar> * The algorithm to use. * (default: HAAR)</pre> * * <pre> -P <Zero> * The padding to use. * (default: ZERO)</pre> * * <pre> -F <filter specification> * The filter to use as preprocessing step (classname and options). * (default: MultiFilter with ReplaceMissingValues and Normalize)</pre> * * <pre> * Options specific to filter weka.filters.MultiFilter ('-F'): * </pre> * * <pre> -D * Turns on output of debugging information.</pre> * * <pre> -F <classname [options]> * A filter to apply (can be specified multiple times).</pre> * * <!-- options-end --> * * @param options the options to use * @throws Exception if the option setting fails */ public void setOptions(String[] options) throws Exception { String tmpStr; String[] tmpOptions; Filter filter; super.setOptions(options); tmpStr = Utils.getOption("A", options); if (tmpStr.length() != 0) setAlgorithm(new SelectedTag(tmpStr, TAGS_ALGORITHM)); else setAlgorithm(new SelectedTag(ALGORITHM_HAAR, TAGS_ALGORITHM)); tmpStr = Utils.getOption("P", options); if (tmpStr.length() != 0) setPadding(new SelectedTag(tmpStr, TAGS_PADDING)); else setPadding(new SelectedTag(PADDING_ZERO, TAGS_PADDING)); tmpStr = Utils.getOption("F", options); tmpOptions = Utils.splitOptions(tmpStr); if (tmpOptions.length != 0) { tmpStr = tmpOptions[0]; tmpOptions[0] = ""; setFilter((Filter) Utils.forName(Filter.class, tmpStr, tmpOptions)); } else { filter = new MultiFilter(); ((MultiFilter) filter) .setFilters( new Filter[] { new weka.filters.unsupervised.attribute.ReplaceMissingValues(), new weka.filters.unsupervised.attribute.Normalize() }); setFilter(filter); } }
/** default constructor */ public Wavelet() { super(); m_Filter = new MultiFilter(); ((MultiFilter) m_Filter) .setFilters( new Filter[] { new weka.filters.unsupervised.attribute.ReplaceMissingValues(), new weka.filters.unsupervised.attribute.Normalize() }); }
/** Split and return test or train instances. */ Instances split(Instances data, boolean invert, boolean removeAttribute) throws Exception { super.setInvertSelection(invert); super.setNominalIndicesArr(toValueIndexArray(getAttribute(data))); final Filter filter; if (!removeAttribute) filter = this; else { Remove remove = new Remove(); remove.setAttributeIndices(super.getAttributeIndex()); MultiFilter mf = new MultiFilter(); mf.setFilters(new Filter[] {this, remove}); filter = mf; } filter.setInputFormat(data); return Filter.useFilter(data, filter); }
private double[] classify(String test) { String[] lab = { "I.2", "I.3", "I.5", "I.6", "I.2.1", "I.2.6", "I.2.8", "I.3.5", "I.3.6", "I.3.7", "I.5.1", "I.5.2", "I.5.4", "I.6.3", "I.6.5", "I.6.8", }; int NSel = 1000; // Number of selection Filter[] filters = new Filter[2]; double[] x = new double[16]; double[] prd = new double[16]; double clsLabel; Ranker rank = new Ranker(); Evaluation eval = null; StringToWordVector stwv = new StringToWordVector(); weka.filters.supervised.attribute.AttributeSelection featSel = new weka.filters.supervised.attribute.AttributeSelection(); WordTokenizer wtok = new WordTokenizer(); String delim = " \r\n\t.,;:'\"()?!$*-&[]+/|\\"; InfoGainAttributeEval ig = new InfoGainAttributeEval(); String[] stwvOpts; wtok.setDelimiters(delim); Instances[] dataRaw = new Instances[10000]; DataSource[] source = new DataSource[16]; String str; Instances testset = null; DataSource testsrc = null; try { testsrc = new DataSource(test); testset = testsrc.getDataSet(); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } for (int j = 0; j < 16; j++) // 16 element 0-15 { try { str = lab[j]; source[j] = new DataSource( "D:/Users/nma1g11/workspace2/WebScraperFlatNew/dataPernode/new/" + str + ".arff"); dataRaw[j] = source[j].getDataSet(); } catch (Exception e) { e.printStackTrace(); } System.out.println(lab[j]); if (dataRaw[j].classIndex() == -1) dataRaw[j].setClassIndex(dataRaw[j].numAttributes() - 1); } if (testset.classIndex() == -1) testset.setClassIndex(testset.numAttributes() - 1); try { stwvOpts = weka.core.Utils.splitOptions( "-R first-last -W 1000000 -prune-rate -1.0 -C -T -I -N 1 -L -S -stemmer weka.core.stemmers.LovinsStemmer -M 2 "); stwv.setOptions(stwvOpts); stwv.setTokenizer(wtok); rank.setOptions(weka.core.Utils.splitOptions("-T -1.7976931348623157E308 -N 100")); rank.setNumToSelect(NSel); featSel.setEvaluator(ig); featSel.setSearch(rank); } catch (Exception e) { e.printStackTrace(); } filters[0] = stwv; filters[1] = featSel; System.out.println("Loading is Done!"); MultiFilter mfilter = new MultiFilter(); mfilter.setFilters(filters); FilteredClassifier classify = new FilteredClassifier(); classify.setClassifier( new NaiveBayesMultinomial()); ///////// Algorithm of The Classification ///////// classify.setFilter(mfilter); String ss2 = ""; try { Classifier[] clsArr = new Classifier[16]; clsArr = Classifier.makeCopies(classify, 16); String strcls = ""; List<String> clsList = new ArrayList<String>(); String s = null; String newcls = null; String lb = ""; String prev = ""; boolean flag = false; String Ocls = null; int q = 0; for (int i = 0; i < 16; i++) { for (int k = 0; k < testset.numInstances(); k++) { flag = false; s = testset.instance(k).stringValue(1); clsList.add(s); if (lab[i].equals(s)) { flag = true; newcls = s; } } clsArr[i].buildClassifier(dataRaw[i]); eval = new Evaluation(dataRaw[i]); for (int j = 0; j < testset.numInstances(); j++) { Ocls = testset.instance(j).stringValue(1); if (flag && !s.equals(null)) testset.instance(j).setClassValue(lab[i]); // ----------------------------------------- strcls = testset.instance(j).stringValue(1); if (i < 4) { if (strcls.substring(0, 3).equals(lab[i])) testset.instance(j).setClassValue(lab[i]); } else if (lab[i].substring(0, 3).equals(strcls)) testset.instance(j).setClassValue(lab[i]); // ------------------------------------------------ System.out.println( dataRaw[i].classAttribute().value(i) + " --- > Correct%:" + eval.pctCorrect() + " F-measure:" + eval.fMeasure(i)); if (!prev.equals(testset.instance(j).stringValue(0)) || !lab[i].equals(lb)) { clsLabel = clsArr[i].classifyInstance(testset.instance(j)); x = clsArr[i].distributionForInstance(testset.instance(j)); prd[i] = x[i]; System.out.println(" --- > prob: " + clsLabel); System.out.println(" --- > x :" + x[i]); System.out.println(clsLabel + " --> " + testset.classAttribute().value((int) clsLabel)); } testset.instance(j).setClassValue(Ocls); prev = testset.instance(j).stringValue(0); lb = lab[i]; } System.out.println("Done with " + lab[i].replace("99", "") + " !!!!!!!!!!!"); } System.out.println(eval.correct()); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return prd; }