List of usage examples for weka.core Instance numAttributes
public int numAttributes();
From source file:de.ugoe.cs.cpdp.dataprocessing.TransferComponentAnalysis.java
License:Apache License
/** * <p>/*from w w w. jav a 2s .c o m*/ * calculates the linear kernel function between two instances * </p> * * @param x1 * first instance * @param x2 * second instance * @return kernel value */ private double linearKernel(Instance x1, Instance x2) { double value = 0.0d; for (int j = 0; j < x1.numAttributes(); j++) { if (j != x1.classIndex()) { value += x1.value(j) * x2.value(j); } } return value; }
From source file:de.ugoe.cs.cpdp.util.WekaUtils.java
License:Apache License
/** * <p>/* w w w . j a v a2 s . c o m*/ * Adoption of the Hamming difference to numerical values, i.e., basically a count of different * metric values. * </p> * * @param inst1 * first instance to be compared * @param inst2 * second instance to be compared * @return the distance */ public static double hammingDistance(Instance inst1, Instance inst2) { double distance = 0.0; for (int j = 0; j < inst1.numAttributes(); j++) { if (j != inst1.classIndex()) { if (inst1.value(j) != inst2.value(j)) { distance += 1.0; } } } return distance; }
From source file:de.ugoe.cs.cpdp.util.WekaUtils.java
License:Apache License
/** * <p>// w ww.j a v a 2s . c o m * Returns a double array of the values without the classification. * </p> * * @param instance * the instance * @return double array */ public static double[] instanceValues(Instance instance) { double[] values = new double[instance.numAttributes() - 1]; int k = 0; for (int j = 0; j < instance.numAttributes(); j++) { if (j != instance.classIndex()) { values[k] = instance.value(j); k++; } } return values; }
From source file:de.unidue.langtech.grading.tc.ClusterExemplarTask.java
License:Open Source License
private double distance(Instance i1, Instance i2) { double dist = 0.0; for (int i = 0; i < i1.numAttributes(); i++) { dist += Math.abs(i1.value(i) - i2.value(i)); }//from w w w. j a v a2 s. com return dist / i1.numAttributes(); }
From source file:de.uniheidelberg.cl.swp.mlprocess.AblationTesting.java
License:Apache License
/** * Determines the attribute value for a Instance object and the specified attribute name. * /*from w w w .j a va 2s . c om*/ * @param inst The instance object from which the value is extracted. * @param featureName The name of the attribute. * @return A double representation of the value used by WEKA. */ private double getAttributeValue(Instance inst, String featureName) { for (int i = 0; i < inst.numAttributes(); i++) { if (inst.attribute(i).name().equals(featureName)) return inst.value(i); } return 0; }
From source file:de.uniheidelberg.cl.swp.mlprocess.MLProcess.java
License:Apache License
/** * Creates the classifications of the test-{@link CoreferencePair}s by using the classifier * trained on the test-{@link CoreferencePair}s. * /*from www . j ava 2 s . co m*/ * @param testCorefs {@link CoreferencePair}s extraced from the test corpus by the ACR-Systems. * @return {@link CoreferencePair} which are predicted by our classifier to be correct. */ private List<CoreferencePair> createPrediction(Map<String, List<CoreferencePair>> testCorefs) throws Exception { List<CoreferencePair> predictions = new ArrayList<CoreferencePair>(); for (String s : testCorefs.keySet()) { for (final CoreferencePair cp : testCorefs.get(s)) { Instance ini = ic.addCorefInstance(cp, s); ini.setDataset(ic.getInstances()); /* use the classifier to select a label */ if (wr.labelUnknownInstance(ini) == 0.0) { cp.setAcrSystem(ini.stringValue(ini.numAttributes() - 2)); predictions.add(cp); } } } predictions = removeDuplicates(predictions); return predictions; }
From source file:dkpro.similarity.experiments.sts2013.filter.LogFilter.java
License:Open Source License
@Override protected Instance process(Instance inst) throws Exception { Instance newInst = new DenseInstance(inst.numAttributes()); newInst.setValue(0, inst.value(0));/*from w w w . j a va 2s .c o m*/ for (int i = 1; i < inst.numAttributes() - 1; i++) { double newVal = Math.log(inst.value(i) + 1); newInst.setValue(i, newVal); } newInst.setValue(inst.numAttributes() - 1, inst.value(inst.numAttributes() - 1)); return newInst; }
From source file:edu.drexel.psal.jstylo.verifiers.WLSVM.java
License:Open Source License
/** * Converts an ARFF Instance into a string in the sparse format accepted by * LIBSVM// w ww. j ava2s. co m * * @param instance * @return */ protected String InstanceToSparse(Instance instance) { String line = new String(); int c = (int) instance.classValue(); if (c == 0) c = -1; line = c + " "; for (int j = 1; j < instance.numAttributes(); j++) { if (j - 1 == instance.classIndex()) { continue; } if (instance.isMissing(j - 1)) continue; if (instance.value(j - 1) != 0) line += " " + j + ":" + instance.value(j - 1); } // LOG.info(line); return (line + "\n"); }
From source file:edu.oregonstate.eecs.mcplan.abstraction.WekaUtil.java
License:Open Source License
public static double[] unlabeledFeatures(final Instance i) { assert (i.dataset() != null); assert (i.dataset().classIndex() == i.numAttributes() - 1); final double[] phi = new double[i.numAttributes() - 1]; for (int j = 0; j < i.numAttributes() - 1; ++j) { phi[j] = i.value(j);//from ww w . j a va 2 s .c o m } return phi; }
From source file:edu.oregonstate.eecs.mcplan.ml.WekaGlue.java
License:Open Source License
public static RealVector toRealVector(final Instance inst) { final RealVector v = new ArrayRealVector(inst.numAttributes()); for (int i = 0; i < inst.numAttributes(); ++i) { v.setEntry(i, inst.value(i));/* w w w.j a va 2s . c o m*/ } return v; }