/** * Parses a given list of options. * <p/> * * <!-- options-start --> Valid options are: * <p/> * * <pre> * -S <num> * Specify the random number seed (default 42) * </pre> * * <!-- options-end --> * * @param options the list of options as an array of strings * @throws Exception if an option is not supported */ @Override public void setOptions(String[] options) throws Exception { String seedString = Utils.getOption('S', options); if (seedString.length() != 0) { setRandomSeed(Integer.parseInt(seedString)); } else { setRandomSeed(42); } if (getInputFormat() != null) { setInputFormat(getInputFormat()); } }
/** * Parses a given list of options. * <p/> * * <!-- options-start --> Valid options are: * <p/> * * <pre> * -S <num> * Specify the random number seed (default 42) * </pre> * * <!-- options-end --> * * @param options the list of options as an array of strings * @throws Exception if an option is not supported */ @Override public void setOptions(String[] options) throws Exception { String seedString = Utils.getOption('S', options); if (seedString.length() != 0) { setRandomSeed(Integer.parseInt(seedString)); } else { setRandomSeed(42); } if (getInputFormat() != null) { setInputFormat(getInputFormat()); } }
/** * Split the dataset into p% train an (100-p)% test set * * @param data Input data * @param p train percentage * @return Array of instances: (0) Train, (1) Test * @throws Exception Filterapplication went wrong */ public static Instances[] splitTrainVal(Instances data, double p) throws Exception { // Randomize data Randomize rand = new Randomize(); rand.setInputFormat(data); rand.setRandomSeed(42); data = Filter.useFilter(data, rand); // Remove testpercentage from data to get the train set RemovePercentage rp = new RemovePercentage(); rp.setInputFormat(data); rp.setPercentage(p); Instances train = Filter.useFilter(data, rp); // Remove trainpercentage from data to get the test set rp = new RemovePercentage(); rp.setInputFormat(data); rp.setPercentage(p); rp.setInvertSelection(true); Instances test = Filter.useFilter(data, rp); return new Instances[]{train, test}; }
/** * Split the dataset into p% train and (100-p)% testImdb set * * @param data Input data * @param p train percentage * @return Array of instances: (0) Train, (1) Test * @throws Exception Filterapplication went wrong */ public static Instances[] splitTrainTest(Instances data, double p) throws Exception { Randomize rand = new Randomize(); rand.setInputFormat(data); rand.setRandomSeed(42); data = Filter.useFilter(data, rand); RemovePercentage rp = new RemovePercentage(); rp.setInputFormat(data); rp.setPercentage(p); rp.setInvertSelection(true); Instances train = Filter.useFilter(data, rp); rp = new RemovePercentage(); rp.setInputFormat(data); rp.setPercentage(p); Instances test = Filter.useFilter(data, rp); return new Instances[] {train, test}; }