List of usage examples for weka.classifiers.rules ZeroR ZeroR
ZeroR
From source file:mulan.regressor.transformation.TransformationBasedMultiTargetRegressor.java
License:Open Source License
/** * Creates a new instance of {@link TransformationBasedMultiTargetRegressor} with default {@link ZeroR} * base regressor.// w ww . ja v a2s. c om */ public TransformationBasedMultiTargetRegressor() { this(new ZeroR()); }
From source file:nl.bioinf.roelen.thema11.classifier_tools.BoundaryClassifier.java
License:Open Source License
/** * method to build a classifier//from w w w. j a v a 2 s. c om * @param fileLocation the arrf file our attributes are in * @param method the method to use for building our classifier * @return the classifier object that was built */ public static Classifier build(String fileLocation, String method) { //init classifier object Classifier classifier; classifier = null; try { //get data ConverterUtils.DataSource source = new ConverterUtils.DataSource(fileLocation); //SET DATA AND OPTIONS Instances data = source.getDataSet(); //remove the name and position entries, these are not important for classifying data.deleteAttributeAt(data.numAttributes() - 2); data.deleteAttributeAt(data.numAttributes() - 2); data.setClassIndex(data.numAttributes() - 1); //prepare data for classifying String[] options = new String[1]; //unpruned options[0] = "-U"; // unpruned tree //see what method was given switch (method.toUpperCase()) { case "J48": //Build J48 classifier classifier = new J48(); // new instance of tree break; case "OneR": //Build OneR classifier classifier = new OneR(); break; case "ZeroR": //build (useless) ZeroR classifier classifier = new ZeroR(); break; default: //default is building OneR classifier = new OneR(); break; } //set the options and build that thing classifier.setOptions(options); // set the options classifier.buildClassifier(data); // build classifier } catch (Exception ex) { Logger.getLogger(BoundaryClassifier.class.getName()).log(Level.SEVERE, null, ex); } return classifier; }
From source file:sg.edu.nus.comp.nlp.ims.classifiers.CMultiClassesSVM.java
License:Open Source License
@Override public void buildClassifier(Instances p_Instances) throws Exception { Instances newInsts = null;// w w w. ja v a 2s . co m if (this.m_Classifier == null) { throw new IllegalStateException("No base classifier has been set!"); } this.m_ZeroR = new ZeroR(); this.m_ZeroR.buildClassifier(p_Instances); this.m_ClassAttribute = p_Instances.classAttribute(); this.getOutputFormat(p_Instances); int numClassifiers = p_Instances.numClasses(); switch (numClassifiers) { case 1: this.m_Classifiers = null; break; case 2: this.m_Classifiers = Classifier.makeCopies(this.m_Classifier, 1); newInsts = new Instances(this.m_OutputFormat, 0); for (int i = 0; i < p_Instances.numInstances(); i++) { Instance inst = this.filterInstance(p_Instances.instance(i)); inst.setDataset(newInsts); newInsts.add(inst); } this.m_Classifiers[0].buildClassifier(newInsts); break; default: this.m_Classifiers = Classifier.makeCopies(this.m_Classifier, numClassifiers); Hashtable<String, ArrayList<Double>> id2Classes = null; if (this.m_IndexOfID >= 0) { id2Classes = new Hashtable<String, ArrayList<Double>>(); for (int i = 0; i < p_Instances.numInstances(); i++) { Instance inst = p_Instances.instance(i); String id = inst.stringValue(this.m_IndexOfID); if (!id2Classes.containsKey(id)) { id2Classes.put(id, new ArrayList<Double>()); } id2Classes.get(id).add(inst.classValue()); } } for (int classIdx = 0; classIdx < this.m_Classifiers.length; classIdx++) { newInsts = this.genInstances(p_Instances, classIdx, id2Classes); this.m_Classifiers[classIdx].buildClassifier(newInsts); } } }
From source file:test.org.moa.opencl.IBk.java
License:Open Source License
/** * Generates the classifier./*from w w w .j a v a2s . co m*/ * * @param instances set of instances serving as training data * @throws Exception if the classifier has not been generated successfully */ public void buildClassifier(Instances instances) throws Exception { // can classifier handle the data? getCapabilities().testWithFail(instances); // remove instances with missing class instances = new Instances(instances); instances.deleteWithMissingClass(); m_NumClasses = instances.numClasses(); m_ClassType = instances.classAttribute().type(); m_Train = new Instances(instances, 0, instances.numInstances()); // Throw away initial instances until within the specified window size if ((m_WindowSize > 0) && (instances.numInstances() > m_WindowSize)) { m_Train = new Instances(m_Train, m_Train.numInstances() - m_WindowSize, m_WindowSize); } m_NumAttributesUsed = 0.0; for (int i = 0; i < m_Train.numAttributes(); i++) { if ((i != m_Train.classIndex()) && (m_Train.attribute(i).isNominal() || m_Train.attribute(i).isNumeric())) { m_NumAttributesUsed += 1.0; } } m_NNSearch.setInstances(m_Train); // Invalidate any currently cross-validation selected k m_kNNValid = false; m_defaultModel = new ZeroR(); m_defaultModel.buildClassifier(instances); }