weka.core.Instance.isMissing()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(9.5k)|赞(0)|评价(0)|浏览(117)

本文整理了Java中weka.core.Instance.isMissing()方法的一些代码示例,展示了Instance.isMissing()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Instance.isMissing()方法的具体详情如下:
包路径:weka.core.Instance
类名称:Instance
方法名:isMissing

Instance.isMissing介绍

[英]Tests if a specific value is "missing".
[中]测试特定值是否“缺失”。

代码示例

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

@Override
 boolean evaluate(Instance inst, int lhsAttIndex, String rhsOperand,
  double numericOperand, Pattern regexPattern, boolean rhsIsAttribute,
  int rhsAttIndex) {
  if (rhsIsAttribute) {
   if (inst.isMissing(lhsAttIndex) || inst.isMissing(rhsAttIndex)) {
    return false;
   }
   return (inst.value(lhsAttIndex) < inst.value(rhsAttIndex));
  }
  if (inst.isMissing(lhsAttIndex)) {
   return false;
  }
  return (inst.value(lhsAttIndex) < numericOperand);
 }
},

代码示例来源:origin: net.sf.meka/meka

/** 
 * LabelCardinality - return the label cardinality of dataset D of L labels.
 */
public static final double labelCardinality(Instances D, int L) {
  double sum = 0.0;
  double numInstances = (double)D.numInstances();
  for(int i = 0; i < D.numInstances(); i++) {
    for(int j = 0; j < L; j++) {
    if (!D.instance(i).isMissing(j)) {
      sum += D.instance(i).value(j);
    }
    }
  }
  return (double)sum/ numInstances;
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

@Override
public String branchForInstance(Instance inst) {
 Attribute att = inst.dataset().attribute(m_splitAttNames.get(0));
 if (att == null || inst.isMissing(att)) {
  // TODO -------------
  return null;
 }
 if (inst.value(att) <= m_splitPoint) {
  return "left";
 }
 return "right";
}

代码示例来源:origin: nz.ac.waikato.cms.weka/simpleEducationalLearningSchemes

/**
 * Updates the minimum and maximum values for all the attributes
 * based on a new instance.
 *
 * @param instance the new instance
 */
private void updateMinMax(Instance instance) {
 
 for (int j = 0;j < m_Train.numAttributes(); j++) {
  if ((m_Train.attribute(j).isNumeric()) && (!instance.isMissing(j))) {
 if (Double.isNaN(m_MinArray[j])) {
  m_MinArray[j] = instance.value(j);
  m_MaxArray[j] = instance.value(j);
 } else {
  if (instance.value(j) < m_MinArray[j]) {
   m_MinArray[j] = instance.value(j);
  } else {
   if (instance.value(j) > m_MaxArray[j]) {
    m_MaxArray[j] = instance.value(j);
   }
  }
 }
  }
 }
}

代码示例来源:origin: nz.ac.waikato.cms.weka/distributedWekaBase

@Override
public Instance output() {
 Instance outInst = m_delegate.output();
 if (m_hasStringAtts && outInst != null) {
  for (int i = 0; i < outInst.dataset().numAttributes(); i++) {
   if (outInst.dataset().attribute(i).isString() && !outInst.isMissing(i)) {
    String val = outInst.stringValue(i);
    outInst.attribute(i).setStringValue(val);
    outInst.setValue(i, 0);
   }
  }
 }
 return outInst;
}

代码示例来源:origin: Waikato/weka-trunk

/**
 * Updates the minimum and maximum values for all the attributes based on a
 * new instance.
 * 
 * @param instance the new instance
 */
private void updateMinMax(Instance instance) {
 for (int j = 0; j < m_instances.numAttributes(); j++) {
  if (!instance.isMissing(j)) {
   if (Double.isNaN(m_Min[j])) {
    m_Min[j] = instance.value(j);
    m_Max[j] = instance.value(j);
   } else if (instance.value(j) < m_Min[j]) {
    m_Min[j] = instance.value(j);
   } else if (instance.value(j) > m_Max[j]) {
    m_Max[j] = instance.value(j);
   }
  }
 }
}

代码示例来源:origin: Waikato/weka-trunk

/**
 * Removes all instances with missing values for a particular attribute from
 * the dataset.
 * 
 * @param attIndex the attribute's index (index starts with 0)
 */
// @ requires 0 <= attIndex && attIndex < numAttributes();
public void deleteWithMissing(int attIndex) {
 ArrayList<Instance> newInstances = new ArrayList<Instance>(numInstances());
 for (int i = 0; i < numInstances(); i++) {
  if (!instance(i).isMissing(attIndex)) {
   newInstances.add(instance(i));
  }
 }
 m_Instances = newInstances;
}

代码示例来源:origin: net.sf.meka/meka

/**
 * checks whether the value at the given position is missing
 *
 * @param rowIndex the row index
 * @param columnIndex the column index
 * @return true if the value at the position is missing
 */
public boolean isMissingAt(int rowIndex, int columnIndex) {
  boolean result;
  result = false;
  if ((rowIndex >= 0) && (rowIndex < getRowCount()) && (columnIndex > 0)
    && (columnIndex < getColumnCount())) {
    result = (m_Data.instance(rowIndex).isMissing(columnIndex - 1));
  }
  return result;
}

代码示例来源:origin: Waikato/meka

/** 
 * LabelCardinality - return the label cardinality of dataset D of L labels.
 */
public static final double labelCardinality(Instances D, int L) {
  double sum = 0.0;
  double numInstances = (double)D.numInstances();
  for(int i = 0; i < D.numInstances(); i++) {
    for(int j = 0; j < L; j++) {
    if (!D.instance(i).isMissing(j)) {
      sum += D.instance(i).value(j);
    }
    }
  }
  return (double)sum/ numInstances;
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * Checks if the given instance is compatible with this dataset. Only looks at
 * the size of the instance and the ranges of the values for nominal and
 * string attributes.
 * 
 * @param instance the instance to check
 * @return true if the instance is compatible with the dataset
 */
public/* @pure@ */boolean checkInstance(Instance instance) {
 if (instance.numAttributes() != numAttributes()) {
  return false;
 }
 for (int i = 0; i < numAttributes(); i++) {
  if (instance.isMissing(i)) {
   continue;
  } else if (attribute(i).isNominal() || attribute(i).isString()) {
   if (instance.value(i) != (int) instance.value(i)) {
    return false;
   } else if ((instance.value(i) < 0)
    || (instance.value(i) > attribute(i).numValues() - 1)) {
    return false;
   }
  }
 }
 return true;
}

代码示例来源:origin: Waikato/weka-trunk

@Override
public String branchForInstance(Instance inst) {
 Attribute att = inst.dataset().attribute(m_splitAttNames.get(0));
 if (att == null || inst.isMissing(att)) {
  // TODO -------------
  return null;
 }
 if (inst.value(att) <= m_splitPoint) {
  return "left";
 }
 return "right";
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

@Override
 boolean evaluate(Instance inst, int lhsAttIndex, String rhsOperand,
  double numericOperand, Pattern regexPattern, boolean rhsIsAttribute,
  int rhsAttIndex) {
  if (rhsIsAttribute) {
   if (inst.isMissing(lhsAttIndex) || inst.isMissing(rhsAttIndex)) {
    return false;
   }
   return (inst.value(lhsAttIndex) <= inst.value(rhsAttIndex));
  }
  if (inst.isMissing(lhsAttIndex)) {
   return false;
  }
  return (inst.value(lhsAttIndex) <= numericOperand);
 }
},

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * Updates the minimum and maximum values for all the attributes based on a
 * new instance.
 * 
 * @param instance the new instance
 */
private void updateMinMax(Instance instance) {
 for (int j = 0; j < m_instances.numAttributes(); j++) {
  if (!instance.isMissing(j)) {
   if (Double.isNaN(m_Min[j])) {
    m_Min[j] = instance.value(j);
    m_Max[j] = instance.value(j);
   } else if (instance.value(j) < m_Min[j]) {
    m_Min[j] = instance.value(j);
   } else if (instance.value(j) > m_Max[j]) {
    m_Max[j] = instance.value(j);
   }
  }
 }
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * Removes all instances with missing values for a particular attribute from
 * the dataset.
 * 
 * @param attIndex the attribute's index (index starts with 0)
 */
// @ requires 0 <= attIndex && attIndex < numAttributes();
public void deleteWithMissing(int attIndex) {
 ArrayList<Instance> newInstances = new ArrayList<Instance>(numInstances());
 for (int i = 0; i < numInstances(); i++) {
  if (!instance(i).isMissing(attIndex)) {
   newInstances.add(instance(i));
  }
 }
 m_Instances = newInstances;
}

代码示例来源:origin: Waikato/meka

/**
 * checks whether the value at the given position is missing
 *
 * @param rowIndex the row index
 * @param columnIndex the column index
 * @return true if the value at the position is missing
 */
public boolean isMissingAt(int rowIndex, int columnIndex) {
  boolean result;
  result = false;
  if ((rowIndex >= 0) && (rowIndex < getRowCount()) && (columnIndex > 0)
    && (columnIndex < getColumnCount())) {
    result = (m_Data.instance(rowIndex).isMissing(columnIndex - 1));
  }
  return result;
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * Calculates the distribution, in the dataset, of the indexed nominal
 * attribute values. It also counts the actual number of training instances
 * that contributed (those with non-missing values) to calculate the
 * distribution.
 */
private void generateAttrDistribution() {
 m_Distribution = new int[m_TrainSet.attribute(m_AttrIndex).numValues()];
 int i;
 Instance train;
 for (i = 0; i < m_NumInstances; i++) {
  train = m_TrainSet.instance(i);
  if (!train.isMissing(m_AttrIndex)) {
   m_TotalCount++;
   m_Distribution[(int) train.value(m_AttrIndex)]++;
  }
 }
}

代码示例来源:origin: Waikato/weka-trunk

/**
 * Checks if the given instance is compatible with this dataset. Only looks at
 * the size of the instance and the ranges of the values for nominal and
 * string attributes.
 * 
 * @param instance the instance to check
 * @return true if the instance is compatible with the dataset
 */
public/* @pure@ */boolean checkInstance(Instance instance) {
 if (instance.numAttributes() != numAttributes()) {
  return false;
 }
 for (int i = 0; i < numAttributes(); i++) {
  if (instance.isMissing(i)) {
   continue;
  } else if (attribute(i).isNominal() || attribute(i).isString()) {
   if (instance.value(i) != (int) instance.value(i)) {
    return false;
   } else if ((instance.value(i) < 0)
    || (instance.value(i) > attribute(i).numValues() - 1)) {
    return false;
   }
  }
 }
 return true;
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

@Override
public String branchForInstance(Instance inst) {
 Attribute att = inst.dataset().attribute(m_splitAttNames.get(0));
 if (att == null || inst.isMissing(att)) {
  return null;
 }
 return att.value((int) inst.value(att));
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

@Override
 boolean evaluate(Instance inst, int lhsAttIndex, String rhsOperand,
  double numericOperand, Pattern regexPattern, boolean rhsIsAttribute,
  int rhsAttIndex) {
  if (rhsIsAttribute) {
   if (inst.isMissing(lhsAttIndex) || inst.isMissing(rhsAttIndex)) {
    return false;
   }
   return (inst.value(lhsAttIndex) <= inst.value(rhsAttIndex));
  }
  if (inst.isMissing(lhsAttIndex)) {
   return false;
  }
  return (inst.value(lhsAttIndex) <= numericOperand);
 }
},

代码示例来源:origin: Waikato/weka-trunk

/**
 * checks whether the value at the given position is missing
 * 
 * @param rowIndex the row index
 * @param columnIndex the column index
 * @return true if the value at the position is missing
 */
public boolean isMissingAt(int rowIndex, int columnIndex) {
 boolean result;
 result = false;
 if ((rowIndex >= 0) && (rowIndex < getRowCount()) && isAttribute(columnIndex)) {
  result = (m_Data.instance(rowIndex).isMissing(getAttributeIndex(columnIndex)));
 }
 return result;
}

相关文章