List of usage examples for weka.filters.unsupervised.attribute Discretize setOptions
@Override public void setOptions(String[] options) throws Exception
From source file:NaiveBayesPckge.NaiveBayesMain.java
public static Instances useFilterDiscritize(Instances dataSet) throws Exception { //set options String[] optionsFilter = new String[4]; //choose the number of intervals, e.g 2: optionsFilter[0] = "-B"; optionsFilter[1] = "6"; //choose the range of attributes on which to apply the filter: optionsFilter[2] = "-R"; optionsFilter[3] = "first-last"; System.out.println("> Filtering dataset using Discretize\n"); //Apply Discretization Discretize discretize = new Discretize(); discretize.setOptions(optionsFilter); discretize.setInputFormat(dataSet);//from www. j a v a2 s . c om Instances newDataTemp = Filter.useFilter(dataSet, discretize); return newDataTemp; }
From source file:org.tigr.microarray.mev.cluster.gui.impl.bn.PrepareArrayDataModule.java
License:Open Source License
/** * The <code>discretize</code> method is given a WEKA Instances object corresponding to the gene expression data * and returns a new WEKA Instances object with the given data discretized into a given number of equal-width bins * * @param data an <code>Instances</code> which is a WEKA Instances object corresponding to the gene expression data * @param numBins a <code>String</code> corresponding to the number of bins in which the data is to be discretized * @return an <code>Instances</code> a new WEKA Instances object with the given data discretized * into a given number of equal-width bins * @exception NullArgumentException if an error occurs if the data is null * @exception OutOfRangeException if an error occurs if the numBins is out of bounds (namely, negative or equal to zero) */// www . ja v a 2 s . c o m public static Instances discretize(Instances data, String numBins) throws NullArgumentException, OutOfRangeException { if (data == null) { throw new NullArgumentException("Parameter data passed to discretize method was null!"); } if (Integer.parseInt(numBins) <= 0) { throw new OutOfRangeException( "numBins is out of range (should be strictly positive!\nnumBins=" + numBins); } try { String[] options = new String[2]; options[0] = "-B"; options[1] = numBins; Discretize discretize = new Discretize(); discretize.setOptions(options); discretize.setInputFormat(data); Instances newData = Filter.useFilter(data, discretize); return newData; } catch (Exception e) { System.out.println(e); e.printStackTrace(); } return null; }