/** * Get classifier for string. * * @return a classifier * @throws Exception if a problem occurs */ protected IterativeClassifier getIterativeClassifier(String name, String[] options) throws Exception { Classifier c = AbstractClassifier.forName(name, options); if (c instanceof IterativeClassifier) { return (IterativeClassifier) c; } else { throw new IllegalArgumentException(name + " is not an IterativeClassifier."); } }
/** * Get classifier for string. * * @return a classifier * @throws Exception if a problem occurs */ protected IterativeClassifier getIterativeClassifier(String name, String[] options) throws Exception { Classifier c = AbstractClassifier.forName(name, options); if (c instanceof IterativeClassifier) { return (IterativeClassifier) c; } else { throw new IllegalArgumentException(name + " is not an IterativeClassifier."); } }
public void createWekaClassifier(String[] options) throws Exception { String classifierName = options[0]; String[] newoptions = options.clone(); newoptions[0] = ""; this.classifier = weka.classifiers.AbstractClassifier.forName(classifierName, newoptions); } }
public void createWekaClassifier(String[] options) throws Exception { String classifierName = options[0]; String[] newoptions = options.clone(); newoptions[0] = ""; this.classifier = weka.classifiers.AbstractClassifier.forName(classifierName, newoptions); if (! (this.classifier instanceof UpdateableClassifier)) { // TODO: Non-Updateable MEKA classifiers could also work here. System.err.println("[ERROR] You must use an Updateable Classifier"); throw new Exception("Only Updateable MEKA classifiers can be used."); } }
public Classifier train(Instances data, File model, List<String> parameters) throws Exception { String algoName = parameters.get(0); List<String> algoParameters = parameters.subList(1, parameters.size()); // build classifier Classifier cl = AbstractClassifier.forName(algoName, algoParameters.toArray(new String[0])); cl.buildClassifier(data); weka.core.SerializationHelper.write(model.getAbsolutePath(), cl); return cl; }
public Classifier train(Instances data, File model, List<String> parameters) throws Exception { String algoName = parameters.get(0); List<String> algoParameters = parameters.subList(1, parameters.size()); // build classifier Classifier cl = AbstractClassifier.forName(algoName, algoParameters.toArray(new String[0])); cl.buildClassifier(data); weka.core.SerializationHelper.write(model.getAbsolutePath(), cl); return cl; }
/** * Performs a (stratified if class is nominal) cross-validation for a * classifier on a set of instances. * * @param classifierString a string naming the class of the classifier * @param data the data on which the cross-validation is to be performed * @param numFolds the number of folds for the cross-validation * @param options the options to the classifier. Any options * @param random the random number generator for randomizing the data accepted * by the classifier will be removed from this array. * @throws Exception if a classifier could not be generated successfully or * the class is not defined */ public void crossValidateModel(String classifierString, Instances data, int numFolds, String[] options, Random random) throws Exception { crossValidateModel(AbstractClassifier.forName(classifierString, options), data, numFolds, random); }
/** * Performs a (stratified if class is nominal) cross-validation for a * classifier on a set of instances. * * @param classifierString a string naming the class of the classifier * @param data the data on which the cross-validation is to be performed * @param numFolds the number of folds for the cross-validation * @param options the options to the classifier. Any options * @param random the random number generator for randomizing the data accepted * by the classifier will be removed from this array. * @throws Exception if a classifier could not be generated successfully or * the class is not defined */ public void crossValidateModel(String classifierString, Instances data, int numFolds, String[] options, Random random) throws Exception { crossValidateModel(AbstractClassifier.forName(classifierString, options), data, numFolds, random); }
private void setTrainedClassifier(weka.classifiers.Classifier tc) throws Exception { // set the template weka.classifiers.Classifier newTemplate = null; String[] options = ((OptionHandler) tc).getOptions(); newTemplate = weka.classifiers.AbstractClassifier.forName(tc.getClass().getName(), options); if (!newTemplate.getClass().equals(m_ClassifierTemplate.getClass())) { throw new Exception("Classifier model " + tc.getClass().getName() + " is not the same type " + "of classifier as this one (" + m_ClassifierTemplate.getClass().getName() + ")"); } setClassifierTemplate(newTemplate); m_Classifier = tc; }
private void setTrainedClassifier(weka.classifiers.Classifier tc) throws Exception { // set the template weka.classifiers.Classifier newTemplate = null; String[] options = ((OptionHandler) tc).getOptions(); newTemplate = weka.classifiers.AbstractClassifier.forName(tc.getClass().getName(), options); if (!newTemplate.getClass().equals(m_ClassifierTemplate.getClass())) { throw new Exception("Classifier model " + tc.getClass().getName() + " is not the same type " + "of classifier as this one (" + m_ClassifierTemplate.getClass().getName() + ")"); } setClassifierTemplate(newTemplate); m_Classifier = tc; }
public Classifier train(Instances data, File model, List<String> parameters) throws Exception { List<String> mlArgs = parameters.subList(1, parameters.size()); MultiLabelClassifier cl = (MultiLabelClassifier) AbstractClassifier .forName((String) parameters.get(0), new String[] {}); if (!mlArgs.isEmpty()) { cl.setOptions(mlArgs.toArray(new String[0])); } cl.buildClassifier(data); if (serializeModel) { weka.core.SerializationHelper.write(model.getAbsolutePath(), cl); } return cl; }
public Classifier train(Instances data, File model, List<String> parameters) throws Exception { List<String> mlArgs = parameters.subList(1, parameters.size()); MultiLabelClassifier cl = (MultiLabelClassifier) AbstractClassifier .forName((String) parameters.get(0), new String[] {}); if (!mlArgs.isEmpty()) { cl.setOptions(mlArgs.toArray(new String[0])); } cl.buildClassifier(data); if (serializeModel) { weka.core.SerializationHelper.write(model.getAbsolutePath(), cl); } return cl; }
public void buildLink(int s[], int j, Instances D) throws Exception { this.j = j; // 2 this.index = s[j]; // s_j if(getDebug()) System.out.print(" "+s[j]); this.exl = Arrays.copyOfRange(s,j+1,s.length); // remove [5,1] Arrays.sort(this.exl); // sort to [1,5] Instances D_j = CCUtils.linkTransform(D,j,this.index,this.exl); if (this.classifier == null) { this.classifier = (AbstractClassifier)AbstractClassifier.forName(getClassifier().getClass().getName(),((AbstractClassifier)getClassifier()).getOptions()); this.classifier.buildClassifier(D_j); } else { // Skip ... (already built) } _template = new Instances(D_j,0); D_j = null; }
public Link2(int chain[], int j, Instances train) throws Exception { this.j = j; this.index = chain[j]; // sort out excludes [4|5,1,0,2,3] this.excld = Arrays.copyOfRange(chain,j+1,chain.length); // sort out excludes [0,1,2,3,5] Arrays.sort(this.excld); //Instances new_train = new Instances(train); Instances new_train = CCUtils.linkTransform(train,j,this.index,this.excld); _template = new Instances(new_train,0); this.classifier = (AbstractClassifier)AbstractClassifier.forName(getClassifier().getClass().getName(),((AbstractClassifier)getClassifier()).getOptions()); this.classifier.buildClassifier(new_train); new_train = null; if(j+1 < chain.length) next = new Link2(chain, ++j, train); }
/** * Process options setting meta classifier. * * @param options the options to parse * @throws Exception if the parsing fails */ protected void processMetaOptions(String[] options) throws Exception { String classifierString = Utils.getOption('M', options); String [] classifierSpec = Utils.splitOptions(classifierString); String classifierName; if (classifierSpec.length == 0) { classifierName = "weka.classifiers.rules.ZeroR"; } else { classifierName = classifierSpec[0]; classifierSpec[0] = ""; } setMetaClassifier(AbstractClassifier.forName(classifierName, classifierSpec)); }
/** * Process options setting meta classifier. * * @param options the options to parse * @throws Exception if the parsing fails */ protected void processMetaOptions(String[] options) throws Exception { String classifierString = Utils.getOption('M', options); String[] classifierSpec = Utils.splitOptions(classifierString); String classifierName; if (classifierSpec.length == 0) { classifierName = "weka.classifiers.rules.ZeroR"; } else { classifierName = classifierSpec[0]; classifierSpec[0] = ""; } setMetaClassifier(AbstractClassifier.forName(classifierName, classifierSpec)); }
@Override public void buildClassifier(Instances D) throws Exception { testCapabilities(D); int N = D.numInstances(); int L = D.classIndex(); h = new Classifier[L]; u = new Random(m_S); D_templates = new Instances[L]; // Build L probabilistic models, each to predict Y_i | X, Y_{-y}; save the templates. for(int j = 0; j < L; j++) { // X = [Y[0],...,Y[j-1],Y[j+1],...,Y[L],X] D_templates[j] = new Instances(D); D_templates[j].setClassIndex(j); // train H[j] : X -> Y h[j] = AbstractClassifier.forName(getClassifier().getClass().getName(),((AbstractClassifier)getClassifier()).getOptions()); h[j].buildClassifier(D_templates[j]); } }
@Override public void buildClassifier(Instances D) throws Exception { testCapabilities(D); int N = D.numInstances(); int L = D.classIndex(); h = new Classifier[L]; m_R = new Random(m_S); D_templates = new Instances[L]; // Build L probabilistic models, each to predict Y_i | X, Y_{-y}; save the templates. for(int j = 0; j < L; j++) { // X = [Y[0],...,Y[j-1],Y[j+1],...,Y[L],X] D_templates[j] = new Instances(D); D_templates[j].setClassIndex(j); // train H[j] : X -> Y h[j] = AbstractClassifier.forName(getClassifier().getClass().getName(),((AbstractClassifier)getClassifier()).getOptions()); h[j].buildClassifier(D_templates[j]); } }
@Override public void buildClassifier(Instances D) throws Exception { testCapabilities(D); int N = D.numInstances(); int L = D.classIndex(); h = new Classifier[L]; m_R = new Random(m_S); D_templates = new Instances[L]; // Build L probabilistic models, each to predict Y_i | X, Y_{-y}; save the templates. for(int j = 0; j < L; j++) { // X = [Y[0],...,Y[j-1],Y[j+1],...,Y[L],X] D_templates[j] = new Instances(D); D_templates[j].setClassIndex(j); // train H[j] : X -> Y h[j] = AbstractClassifier.forName(getClassifier().getClass().getName(),((AbstractClassifier)getClassifier()).getOptions()); h[j].buildClassifier(D_templates[j]); } }
@Override public void buildClassifier(Instances D) throws Exception { testCapabilities(D); FastVector values = new FastVector(4); values.addElement("00"); values.addElement("10"); values.addElement("01"); values.addElement("11"); classAttribute = new Attribute("TheCLass",values); int L = D.classIndex(); h = new Classifier[L][L]; for(int j = 0; j < L; j++) { for(int k = j+1; k < L; k++) { if (getDebug()) System.out.print("."); Instances D_pair = convert(D,j,k); h[j][k] = (AbstractClassifier)AbstractClassifier.forName(getClassifier().getClass().getName(),((AbstractClassifier)getClassifier()).getOptions()); h[j][k].buildClassifier(D_pair); } if (getDebug()) System.out.println(""); } }