List of usage examples for weka.core Instance classIndex
public int classIndex();
From source file:meka.classifiers.multilabel.meta.MetaProblemTransformationMethod.java
License:Open Source License
@Override public double[] distributionForInstance(Instance x) throws Exception { double p[] = new double[x.classIndex()]; for (int i = 0; i < m_NumIterations; i++) { double d[] = m_Classifiers[i].distributionForInstance(x); for (int j = 0; j < d.length; j++) { p[j] += d[j];// w w w . j a v a 2 s .c o m } } // turn votes into a [0,1] confidence for each label for (int j = 0; j < p.length; j++) { p[j] = p[j] / m_NumIterations; } return p; }
From source file:meka.classifiers.multilabel.meta.RandomSubspaceML.java
License:Open Source License
@Override public double[] distributionForInstance(Instance x) throws Exception { int L = x.classIndex(); double p[] = new double[L]; for (int i = 0; i < m_NumIterations; i++) { // Use a template Instance from training, and copy values over // (this is faster than copying x and cutting it to shape) Instance x_ = (Instance) m_InstanceTemplates[i]; MLUtils.copyValues(x_, x, m_IndicesCut[i]); x_.setDataset(m_InstancesTemplates[i]); // TODO, use generic voting scheme somewhere? double d[] = ((ProblemTransformationMethod) m_Classifiers[i]).distributionForInstance(x_); for (int j = 0; j < d.length; j++) { p[j] += d[j];/*from w ww.ja v a2 s . c o m*/ } } return p; }
From source file:meka.classifiers.multilabel.MULAN.java
License:Open Source License
@Override public double[] distributionForInstance(Instance instance) throws Exception { int L = instance.classIndex(); Instance x = F.meka2mulan((Instance) instance.copy(), L); x.setDataset(m_InstancesTemplate);//from ww w. ja v a 2 s . co m double y[] = m_MULAN.makePrediction(x).getConfidences(); return y; }
From source file:meka.classifiers.multilabel.PCC.java
License:Open Source License
@Override public double[] distributionForInstance(Instance xy) throws Exception { int L = xy.classIndex(); double y[] = new double[L]; double conf[] = new double[L]; double w = 0.0; /*/*from w ww . ja v a 2 s . c o m*/ * e.g. K = [3,3,5] * we push y_[] from [0,0,0] to [2,2,4] over all necessary iterations. */ int K[] = getKs(xy.dataset()); if (getDebug()) System.out.println("K[] = " + Arrays.toString(K)); double y_[] = new double[L]; for (int i = 0; i < 1000000; i++) { // limit to 1m double conf_[] = super.probabilityForInstance(xy, y_); double w_ = A.product(conf_); //System.out.println(""+i+" "+Arrays.toString(y_)+" "+w_+" "+Arrays.toString(conf_)+"/"+Arrays.toString(convertConfidenceToProbability(y_,conf_))); if (w_ > w) { if (getDebug()) System.out.println("y' = " + Arrays.toString(y_) + ", :" + w_); y = Arrays.copyOf(y_, y_.length); w = w_; conf = conf_; } if (push(y_, K, 0)) { // Done ! if (getDebug()) System.out.println("Tried all " + (i + 1) + " combinations."); break; } } // If it's multi-label (binary only), return the probabilistic output (else just the values). return (A.max(K) > 2) ? y : convertConfidenceToProbability(conf, y); //return p_y; //y; }
From source file:meka.classifiers.multilabel.PSt.java
License:Open Source License
@Override public double[] distributionForInstance(Instance x) throws Exception { int L = x.classIndex(); // if there is only one class (as for e.g. in some hier. mtds) predict it if (L == 1)/*from ww w . jav a2 s .c o m*/ return new double[] { 1.0 }; Instance x_ = PSUtils.convertInstance(x, L, m_InstancesTemplate); //convertInstance(x,L); //x_.setDataset(m_InstancesTemplate); // Get a classification return PSUtils.recombination_t(m_Classifier.distributionForInstance(x_), L, m_InstancesTemplate); }
From source file:meka.classifiers.multilabel.RAkELd.java
License:Open Source License
@Override public double[] distributionForInstance(Instance x) throws Exception { int L = x.classIndex(); // If there is only one label, predict it //if(L == 1) return new double[]{1.0}; double y[] = new double[L]; //int c[] = new int[L]; // to scale it between 0 and 1 for (int m = 0; m < m_M; m++) { // Transform instance Instance x_m = PSUtils.convertInstance(x, L, m_InstancesTemplates[m]); x_m.setDataset(m_InstancesTemplates[m]); // Get a meta classification int i_m = (int) m_Classifiers[m].classifyInstance(x_m); // e.g., 2 int k_indices[] = mapBack(m_InstancesTemplates[m], i_m); // e.g., [3,8] // Vote with classification for (int i : k_indices) { int index = kMap[m][i]; y[index] += 1.;/*from w ww . java 2 s .c o m*/ } } return y; }
From source file:meka.classifiers.multitarget.BCC.java
License:Open Source License
@Override public double[] distributionForInstance(Instance x) throws Exception { int L = x.classIndex(); double y_long[] = Arrays.copyOf(super.distributionForInstance(x), L * 2); Arrays.fill(y_long, L, y_long.length, 1.0); return y_long; }
From source file:meka.classifiers.multitarget.CCp.java
License:Open Source License
@Override public double[] distributionForInstance(Instance x) throws Exception { int L = x.classIndex(); confidences = new double[L]; root.classify(x);//w w w . ja v a 2 s . com double y[] = new double[L * 2]; for (int j = 0; j < L; j++) { y[j] = x.value(j); y[j + L] = confidences[j]; // <--- this is the extra line } return y; }
From source file:meka.classifiers.multitarget.meta.BaggingMT.java
License:Open Source License
@Override public double[] distributionForInstance(Instance x) throws Exception { int L = x.classIndex(); HashMap<Integer, Double> votes[] = new HashMap[L]; for (int j = 0; j < L; j++) { votes[j] = new HashMap<Integer, Double>(); }/*from w w w .j av a 2 s . c om*/ for (int m = 0; m < m_NumIterations; m++) { double c[] = ((ProblemTransformationMethod) m_Classifiers[m]).distributionForInstance(x); // votes[j] = votes[j] + P(j|x) @TODO: only if c.length > L for (int j = 0; j < L; j++) { Double w = votes[j].containsKey((int) c[j]) ? votes[j].get((int) c[j]) + c[j + L] : c[j + L]; votes[j].put((int) c[j], w); } } double y[] = SuperLabelUtils.convertVotesToDistributionForInstance(votes); return y; }
From source file:meka.classifiers.multitarget.meta.EnsembleMT.java
License:Open Source License
@Override public double[] distributionForInstance(Instance x) throws Exception { int L = x.classIndex(); HashMap<Integer, Double> votes[] = new HashMap[L]; for (int j = 0; j < L; j++) { votes[j] = new HashMap<Integer, Double>(); }/* w w w .j av a2s.c o m*/ double y[] = new double[L]; for (int m = 0; m < m_NumIterations; m++) { double c[] = ((ProblemTransformationMethod) m_Classifiers[m]).distributionForInstance(x); // votes[j] = votes[j] + P(j|x) @TODO: only if c.length > L for (int j = 0; j < L; j++) { Double w = votes[j].containsKey((int) c[j]) ? votes[j].get((int) c[j]) + c[j + L] : c[j + L]; votes[j].put((int) c[j], w); } } for (int j = 0; j < L; j++) { // get the class with max weight y[j] = (Integer) MLUtils.maxItem(votes[j]); } return y; }