@Override public double meanOrMode(int arg0) { return super.meanOrMode(arg0); }
@Override public double meanOrMode(Attribute att) { return super.meanOrMode(att); }
/** * Returns the mean (mode) for a numeric (nominal) attribute as a * floating-point value. Returns 0 if the attribute is neither nominal nor * numeric. If all values are missing it returns zero. * * @param att the attribute * @return the mean or the mode */ public/* @pure@ */double meanOrMode(Attribute att) { return meanOrMode(att.index()); }
/** * Returns the mean (mode) for a numeric (nominal) attribute as a * floating-point value. Returns 0 if the attribute is neither nominal nor * numeric. If all values are missing it returns zero. * * @param att the attribute * @return the mean or the mode */ public/* @pure@ */double meanOrMode(Attribute att) { return meanOrMode(att.index()); }
Instance inst; double r, diff1, diff2, num = 0.0, sx = 0.0, sy = 0.0; double mx = m_trainInstances.meanOrMode(m_trainInstances.attribute(att1)); double my = m_trainInstances.meanOrMode(m_trainInstances.attribute(att2));
m_globalMeansOrModes[i] = m_instances.meanOrMode(i);
m_globalMeansOrModes[i] = m_instances.meanOrMode(i);
double[] xBar = new double[m_Dimension]; for (int i = 0; i < exi.numAttributes(); i++) { xBar[i] = exi.meanOrMode(i);
/** * Returns the R-squared value for a linear regression model, where sum of * squared residuals is already calculated. This works for either a simple or * a multiple linear regression model. * * @param data (the data set) * @param ssr (sum of squared residuals) * @return R^2 value * @throws Exception if there is a missing class value in data */ public static double calculateRSquared(Instances data, double ssr) throws Exception { // calculate total sum of squares (derivation of y from mean) double yMean = data.meanOrMode(data.classIndex()); double tss = 0.0; for (int i = 0; i < data.numInstances(); i++) { tss += (data.instance(i).value(data.classIndex()) - yMean) * (data.instance(i).value(data.classIndex()) - yMean); } // calculate R-squared value and return double rsq = 1 - (ssr / tss); return rsq; }
/** * Returns the R-squared value for a linear regression model, where sum of * squared residuals is already calculated. This works for either a simple or * a multiple linear regression model. * * @param data (the data set) * @param ssr (sum of squared residuals) * @return R^2 value * @throws Exception if there is a missing class value in data */ public static double calculateRSquared(Instances data, double ssr) throws Exception { // calculate total sum of squares (derivation of y from mean) double yMean = data.meanOrMode(data.classIndex()); double tss = 0.0; for (int i = 0; i < data.numInstances(); i++) { tss += (data.instance(i).value(data.classIndex()) - yMean) * (data.instance(i).value(data.classIndex()) - yMean); } // calculate R-squared value and return double rsq = 1 - (ssr / tss); return rsq; }
/** * * @param ex the given test exemplar * @return the classification * @throws Exception if the exemplar could not be classified successfully */ @Override public double classifyInstance(Instance ex) throws Exception { // Instance ex = new Exemplar(e); Instances exi = ex.relationalValue(1); double[] n = new double[m_Dimension]; double[] xBar = new double[m_Dimension]; for (int i = 0; i < exi.numAttributes(); i++) { xBar[i] = exi.meanOrMode(i); } for (int w = 0, t = 0; w < m_Dimension; w++, t++) { // if((t==m_ClassIndex) || (t==m_IdIndex)) // t++; for (int u = 0; u < exi.numInstances(); u++) { if (!exi.instance(u).isMissing(t)) { n[w] += exi.instance(u).weight(); } } } double logOdds = likelihoodRatio(n, xBar); return (logOdds > m_Cutoff) ? 1 : 0; }
if (input.attribute(i).isNumeric() && (input.classIndex() != i)) { m_Means[i] = input.meanOrMode(i); m_StdDevs[i] = Math.sqrt(input.variance(i));
/** * Signify that this batch of input to the filter is finished. * If the filter requires all instances prior to filtering, * output() may now be called to retrieve the filtered instances. * * @return true if there are instances pending output * @throws IllegalStateException if no input structure has been defined */ public boolean batchFinished() { if (getInputFormat() == null) throw new IllegalStateException("No input instance format defined"); if (m_Means == null) { Instances input = getInputFormat(); m_Means = new double[input.numAttributes()]; for (int i = 0; i < input.numAttributes(); i++) { if (input.attribute(i).isNumeric() && (input.classIndex() != i)) { m_Means[i] = input.meanOrMode(i); } } // Convert pending input instances for (int i = 0; i < input.numInstances(); i++) convertInstance(input.instance(i)); } // Free memory flushInput(); m_NewBatch = true; return (numPendingOutput() != 0); }
if (input.attribute(i).isNumeric() && (input.classIndex() != i)) { m_Means[i] = input.meanOrMode(i); m_StdDevs[i] = Math.sqrt(input.variance(i));
/** * Signify that this batch of input to the filter is finished. * If the filter requires all instances prior to filtering, * output() may now be called to retrieve the filtered instances. * * @return true if there are instances pending output * @throws IllegalStateException if no input structure has been defined */ public boolean batchFinished() { if (getInputFormat() == null) throw new IllegalStateException("No input instance format defined"); if (m_Means == null) { Instances input = getInputFormat(); m_Means = new double[input.numAttributes()]; for (int i = 0; i < input.numAttributes(); i++) { if (input.attribute(i).isNumeric() && (input.classIndex() != i)) { m_Means[i] = input.meanOrMode(i); } } // Convert pending input instances for (int i = 0; i < input.numInstances(); i++) convertInstance(input.instance(i)); } // Free memory flushInput(); m_NewBatch = true; return (numPendingOutput() != 0); }
double[] sSq = new double[m_Dimension]; for (int i = 0; i < exi.numAttributes(); i++) { xBar[i] = exi.meanOrMode(i); sSq[i] = exi.variance(i);
m_stdDevs = new double[m_trainInstances.numAttributes()]; for (int i = 0; i < m_trainInstances.numAttributes(); i++) { m_means[i] = m_trainInstances.meanOrMode(i); m_stdDevs[i] = Math.sqrt(Utils.variance(m_trainInstances.attributeToDoubleArray(i)));
m_stdDevs = new double[m_trainInstances.numAttributes()]; for (int i = 0; i < m_trainInstances.numAttributes(); i++) { m_means[i] = m_trainInstances.meanOrMode(i); m_stdDevs[i] = Math.sqrt(Utils.variance(m_trainInstances.attributeToDoubleArray(i)));
public void testTypical() { Instances result = useFilter(); // Number of attributes and instances shouldn't change assertEquals(m_Instances.numAttributes(), result.numAttributes()); assertEquals(m_Instances.numInstances(), result.numInstances()); // Check conversion is OK for (int j = 0; j < result.numAttributes(); j++) { if (result.attribute(j).isNumeric()) { double mean = result.meanOrMode(j); assertTrue("Mean should be 0", Utils.eq(mean, 0)); double stdDev = Math.sqrt(result.variance(j)); assertTrue("StdDev should be 1 (or 0)", Utils.eq(stdDev, 0) || Utils.eq(stdDev, 1)); } } }
public void testTypical() { Instances result = useFilter(); // Number of attributes and instances shouldn't change assertEquals(m_Instances.numAttributes(), result.numAttributes()); assertEquals(m_Instances.numInstances(), result.numInstances()); // Check conversion is OK for (int j = 0; j < result.numAttributes(); j++) { if (result.attribute(j).isNumeric()) { double mean = result.meanOrMode(j); assertTrue("Mean should be 0", Utils.eq(mean, 0)); double stdDev = Math.sqrt(result.variance(j)); assertTrue("StdDev should be 1 (or 0)", Utils.eq(stdDev, 0) || Utils.eq(stdDev, 1)); } } }