本文整理了Java中weka.core.Instances.meanOrMode()
方法的一些代码示例,展示了Instances.meanOrMode()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Instances.meanOrMode()
方法的具体详情如下:
包路径:weka.core.Instances
类名称:Instances
方法名:meanOrMode
[英]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.
[中]以浮点值形式返回数值(标称)属性的平均值(模式)。如果属性既不是标称属性也不是数字属性,则返回0。如果缺少所有值,则返回零。
代码示例来源:origin: com.googlecode.obvious/obviousx-weka
@Override
public double meanOrMode(int arg0) {
return super.meanOrMode(arg0);
}
代码示例来源:origin: com.googlecode.obvious/obviousx-weka
@Override
public double meanOrMode(Attribute att) {
return super.meanOrMode(att);
}
代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable
/**
* 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());
}
代码示例来源:origin: Waikato/weka-trunk
/**
* 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());
}
代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable
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));
代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable
m_globalMeansOrModes[i] = m_instances.meanOrMode(i);
代码示例来源:origin: Waikato/weka-trunk
m_globalMeansOrModes[i] = m_instances.meanOrMode(i);
代码示例来源:origin: nz.ac.waikato.cms.weka/multiInstanceLearning
double[] xBar = new double[m_Dimension];
for (int i = 0; i < exi.numAttributes(); i++) {
xBar[i] = exi.meanOrMode(i);
代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable
/**
* 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;
}
代码示例来源:origin: Waikato/weka-trunk
/**
* 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;
}
代码示例来源:origin: nz.ac.waikato.cms.weka/multiInstanceLearning
/**
*
* @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;
}
代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable
if (input.attribute(i).isNumeric() &&
(input.classIndex() != i)) {
m_Means[i] = input.meanOrMode(i);
m_StdDevs[i] = Math.sqrt(input.variance(i));
代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable
/**
* 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);
}
代码示例来源:origin: Waikato/weka-trunk
if (input.attribute(i).isNumeric() &&
(input.classIndex() != i)) {
m_Means[i] = input.meanOrMode(i);
m_StdDevs[i] = Math.sqrt(input.variance(i));
代码示例来源:origin: Waikato/weka-trunk
/**
* 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);
}
代码示例来源:origin: nz.ac.waikato.cms.weka/multiInstanceLearning
double[] sSq = new double[m_Dimension];
for (int i = 0; i < exi.numAttributes(); i++) {
xBar[i] = exi.meanOrMode(i);
sSq[i] = exi.variance(i);
代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable
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)));
代码示例来源:origin: Waikato/weka-trunk
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)));
代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable
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));
}
}
}
代码示例来源:origin: Waikato/weka-trunk
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));
}
}
}
内容来源于网络,如有侵权,请联系作者删除!