/** * Constructor. */ public MultiClassClassifier() { m_Classifier = new weka.classifiers.functions.Logistic(); }
/** * Main method for testing this class. * * @param argv should contain the command line arguments to the scheme (see * Evaluation) */ public static void main(String[] argv) { runClassifier(new Logistic(), argv); }
public static Classifier getClassifier(WekaClassifier classifier) throws IllegalArgumentException { try { switch (classifier) { case NAIVE_BAYES: return new NaiveBayes(); case J48: J48 j48 = new J48(); j48.setOptions(new String[] { "-C", "0.25", "-M", "2" }); return j48; case SMO: SMO smo = new SMO(); smo.setOptions(Utils.splitOptions("-C 1.0 -L 0.001 -P 1.0E-12 -N 0 -V -1 -W 1 -K \"weka.classifiers.functions.supportVector.PolyKernel -C 250007 -E 1.0\"")); return smo; case LOGISTIC: Logistic logistic = new Logistic(); logistic.setOptions(Utils.splitOptions("-R 1.0E-8 -M -1")); return logistic; default: throw new IllegalArgumentException("Classifier " + classifier + " not found!"); } } catch (Exception e) { throw new IllegalArgumentException(e); } }
this.classifier = new Logistic(); try { this.classifier.buildClassifier(instances); logger.debug("logistic classifier's coefficients: "+Arrays.deepToString(this.classifier.coefficients()));
m_logistic = new Logistic(); m_logistic.buildClassifier(data);
result = this.classifier.classifyInstance(instances.firstInstance()); distribution = this.classifier.distributionForInstance(instances.firstInstance()); instances.firstInstance().setClassValue(result); } catch (Exception e) {
/** * Computes the distribution for a given instance * * @param instance the instance for which distribution is computed * @return the distribution * @throws Exception if the distribution can't be computed successfully */ @Override public double[] distributionForInstance(Instance instance) throws Exception { m_ReplaceMissingValues.input(instance); instance = m_ReplaceMissingValues.output(); m_AttFilter.input(instance); instance = m_AttFilter.output(); m_NominalToBinary.input(instance); instance = m_NominalToBinary.output(); // Extract the predictor columns into an array double[] instDat = new double[m_NumPredictors + 1]; int j = 1; instDat[0] = 1; for (int k = 0; k <= m_NumPredictors; k++) { if (k != m_ClassIndex) { instDat[j++] = instance.value(k); } } double[] distribution = evaluateProbability(instDat); return distribution; }
if (Utils.doubleToString(m_Par[j][k], 8 + getNumDecimalPlaces(), getNumDecimalPlaces()).trim().length() > colWidth) { colWidth = Utils.doubleToString(m_Par[j][k], 8 + getNumDecimalPlaces(), getNumDecimalPlaces()).trim().length(); + ((ORc > 1e10) ? "" + ORc : Utils.doubleToString(ORc, 8 + getNumDecimalPlaces(), getNumDecimalPlaces())); if (t.trim().length() > colWidth) { colWidth = t.trim().length(); temp.append(Utils.padRight(m_structure.attribute(i).name(), attLength)); for (int k = 0; k < m_NumClasses - 1; k++) { temp.append(Utils.padLeft(Utils.doubleToString(m_Par[j][k], 8 + getNumDecimalPlaces(), getNumDecimalPlaces()) .trim(), colWidth)); for (int k = 0; k < m_NumClasses - 1; k++) { temp.append(Utils.padLeft( Utils.doubleToString(m_Par[0][k], 6 + getNumDecimalPlaces(), getNumDecimalPlaces()).trim(), colWidth)); double ORc = Math.exp(m_Par[j][k]); String ORs = " " + ((ORc > 1e10) ? "" + ORc : Utils.doubleToString(ORc, 8 + getNumDecimalPlaces(), getNumDecimalPlaces())); temp.append(Utils.padLeft(ORs.trim(), colWidth));
public void buildClassifier(Instances train) throws Exception { getCapabilities().testWithFail(train);
newInst[1] = Utils.missingValue(); return m_classifiers[0][1].m_logistic .distributionForInstance(new DenseInstance(1, newInst)); newInst[1] = Utils.missingValue(); r[i][j] = m_classifiers[i][j].m_logistic .distributionForInstance(new DenseInstance(1, newInst))[0]; n[i][j] = m_classifiers[i][j].m_sumOfWeights;
public static Classifier getClassifier(WekaClassifier classifier) throws IllegalArgumentException { try { switch (classifier) { case NAIVE_BAYES: return new NaiveBayes(); case J48: J48 j48 = new J48(); j48.setOptions(new String[] { "-C", "0.25", "-M", "2" }); return j48; case SMO: SMO smo = new SMO(); smo.setOptions(Utils.splitOptions("-C 1.0 -L 0.001 -P 1.0E-12 -N 0 -V -1 -W 1 -K \"weka.classifiers.functions.supportVector.PolyKernel -C 250007 -E 1.0\"")); return smo; case LOGISTIC: Logistic logistic = new Logistic(); logistic.setOptions(Utils.splitOptions("-R 1.0E-8 -M -1")); return logistic; default: throw new IllegalArgumentException("Classifier " + classifier + " not found!"); } } catch (Exception e) { throw new IllegalArgumentException(e); } }
this.classifier = new Logistic(); this.classifier.buildClassifier(instances); logger.debug(Arrays.deepToString(this.classifier.coefficients()));
/** * Main method for testing this class. * * @param argv should contain the command line arguments to the scheme (see * Evaluation) */ public static void main(String[] argv) { runClassifier(new Logistic(), argv); }
/** * Computes the distribution for a given instance * * @param instance the instance for which distribution is computed * @return the distribution * @throws Exception if the distribution can't be computed successfully */ @Override public double[] distributionForInstance(Instance instance) throws Exception { m_ReplaceMissingValues.input(instance); instance = m_ReplaceMissingValues.output(); m_AttFilter.input(instance); instance = m_AttFilter.output(); m_NominalToBinary.input(instance); instance = m_NominalToBinary.output(); // Extract the predictor columns into an array double[] instDat = new double[m_NumPredictors + 1]; int j = 1; instDat[0] = 1; for (int k = 0; k <= m_NumPredictors; k++) { if (k != m_ClassIndex) { instDat[j++] = instance.value(k); } } double[] distribution = evaluateProbability(instDat); return distribution; }
if (Utils.doubleToString(m_Par[j][k], 8 + getNumDecimalPlaces(), getNumDecimalPlaces()).trim().length() > colWidth) { colWidth = Utils.doubleToString(m_Par[j][k], 8 + getNumDecimalPlaces(), getNumDecimalPlaces()).trim().length(); + ((ORc > 1e10) ? "" + ORc : Utils.doubleToString(ORc, 8 + getNumDecimalPlaces(), getNumDecimalPlaces())); if (t.trim().length() > colWidth) { colWidth = t.trim().length(); temp.append(Utils.padRight(m_structure.attribute(i).name(), attLength)); for (int k = 0; k < m_NumClasses - 1; k++) { temp.append(Utils.padLeft(Utils.doubleToString(m_Par[j][k], 8 + getNumDecimalPlaces(), getNumDecimalPlaces()) .trim(), colWidth)); for (int k = 0; k < m_NumClasses - 1; k++) { temp.append(Utils.padLeft( Utils.doubleToString(m_Par[0][k], 6 + getNumDecimalPlaces(), getNumDecimalPlaces()).trim(), colWidth)); double ORc = Math.exp(m_Par[j][k]); String ORs = " " + ((ORc > 1e10) ? "" + ORc : Utils.doubleToString(ORc, 8 + getNumDecimalPlaces(), getNumDecimalPlaces())); temp.append(Utils.padLeft(ORs.trim(), colWidth));
public void buildClassifier(Instances train) throws Exception { getCapabilities().testWithFail(train);
/** * Constructor. */ public MultiClassClassifier() { m_Classifier = new weka.classifiers.functions.Logistic(); }
public static Classifier getClassifier(WekaClassifier classifier) throws IllegalArgumentException { try { switch (classifier) { case NAIVE_BAYES: return new NaiveBayes(); case J48: J48 j48 = new J48(); j48.setOptions(new String[] { "-C", "0.25", "-M", "2" }); return j48; case SMO: SMO smo = new SMO(); smo.setOptions(Utils.splitOptions("-C 1.0 -L 0.001 -P 1.0E-12 -N 0 -V -1 -W 1 -K \"weka.classifiers.functions.supportVector.PolyKernel -C 250007 -E 1.0\"")); return smo; case LOGISTIC: Logistic logistic = new Logistic(); logistic.setOptions(Utils.splitOptions("-R 1.0E-8 -M -1")); return logistic; default: throw new IllegalArgumentException("Classifier " + classifier + " not found!"); } } catch (Exception e) { throw new IllegalArgumentException(e); } }
/** * Default (argument-less) constructor. Will initialize the instance with * a default Weka-classifier (here, that default is, NaiveBayes with Kernel density estimation) * * @throws ClassifierException */ public EDABinaryClassifierFromWeka() throws ClassifierException { this(new Logistic(), null); // logistic regression is generally go good in most situations. //this(new NaiveBayes(), new String[] {"-K"}); }
@Override protected EDAClassifierAbstraction prepareClassifier() throws EDAException { try { return new EDABinaryClassifierFromWeka(new Logistic(), null); } catch (ClassifierException ce) { throw new EDAException("Preparing an instance of Classifier for EDA failed: underlying Classifier raised an exception: ", ce); } }