Java 类weka.core.pmml.TargetMetaInfo 实例源码

项目:repo.kmeanspp.silhouette_score    文件:GeneralRegression.java   
/**                                                                                                             
 * Classifies the given test instance. The instance has to belong to a                                          
 * dataset when it's being classified.                                                          
 *                                                                                                              
 * @param inst the instance to be classified                                                                
 * @return the predicted most likely class for the instance or                                                  
 * Utils.missingValue() if no prediction is made                                                             
 * @exception Exception if an error occurred during the prediction                                              
 */
public double[] distributionForInstance(Instance inst) throws Exception {
  if (!m_initialized) {
    mapToMiningSchema(inst.dataset());
  }
  double[] preds = null;
  if (m_miningSchema.getFieldsAsInstances().classAttribute().isNumeric()) {
    preds = new double[1];
  } else {
    preds = new double[m_miningSchema.getFieldsAsInstances().classAttribute().numValues()];
  }

  // create an array of doubles that holds values from the incoming
  // instance; in order of the fields in the mining schema. We will
  // also handle missing values and outliers here.
  double[] incoming = m_fieldsMap.instanceToSchema(inst, m_miningSchema);

  // In this implementation we will default to information in the Target element (default
  // value for numeric prediction and prior probabilities for classification). If there is
  // no Target element defined, then an Exception is thrown.

  boolean hasMissing = false;
  for (int i = 0; i < incoming.length; i++) {
    if (i != m_miningSchema.getFieldsAsInstances().classIndex() && 
        Double.isNaN(incoming[i])) {
      hasMissing = true;
      break;
    }
  }

  if (hasMissing) {
    if (!m_miningSchema.hasTargetMetaData()) {
      String message = "[GeneralRegression] WARNING: Instance to predict has missing value(s) but "
        + "there is no missing value handling meta data and no "
        + "prior probabilities/default value to fall back to. No "
        + "prediction will be made (" 
        + ((m_miningSchema.getFieldsAsInstances().classAttribute().isNominal()
            || m_miningSchema.getFieldsAsInstances().classAttribute().isString())
            ? "zero probabilities output)."
            : "NaN output).");
      if (m_log == null) {
        System.err.println(message);
      } else {
        m_log.logMessage(message);
      }

      if (m_miningSchema.getFieldsAsInstances().classAttribute().isNumeric()) {
        preds[0] = Utils.missingValue();
      }
      return preds;
    } else {
      // use prior probablilities/default value
      TargetMetaInfo targetData = m_miningSchema.getTargetMetaData();
      if (m_miningSchema.getFieldsAsInstances().classAttribute().isNumeric()) {
        preds[0] = targetData.getDefaultValue();
      } else {
        Instances miningSchemaI = m_miningSchema.getFieldsAsInstances();
        for (int i = 0; i < miningSchemaI.classAttribute().numValues(); i++) {
          preds[i] = targetData.getPriorProbability(miningSchemaI.classAttribute().value(i));
        }
      }
      return preds;
    }
  } else {
    // construct input parameter vector here
    double[] inputParamVector = incomingParamVector(incoming);
    computeResponses(incoming, inputParamVector, preds);
  }

  return preds;
}
项目:autoweka    文件:GeneralRegression.java   
/**                                                                                                             
 * Classifies the given test instance. The instance has to belong to a                                          
 * dataset when it's being classified.                                                          
 *                                                                                                              
 * @param inst the instance to be classified                                                                
 * @return the predicted most likely class for the instance or                                                  
 * Utils.missingValue() if no prediction is made                                                             
 * @exception Exception if an error occurred during the prediction                                              
 */
public double[] distributionForInstance(Instance inst) throws Exception {
  if (!m_initialized) {
    mapToMiningSchema(inst.dataset());
  }
  double[] preds = null;
  if (m_miningSchema.getFieldsAsInstances().classAttribute().isNumeric()) {
    preds = new double[1];
  } else {
    preds = new double[m_miningSchema.getFieldsAsInstances().classAttribute().numValues()];
  }

  // create an array of doubles that holds values from the incoming
  // instance; in order of the fields in the mining schema. We will
  // also handle missing values and outliers here.
  double[] incoming = m_fieldsMap.instanceToSchema(inst, m_miningSchema);

  // In this implementation we will default to information in the Target element (default
  // value for numeric prediction and prior probabilities for classification). If there is
  // no Target element defined, then an Exception is thrown.

  boolean hasMissing = false;
  for (int i = 0; i < incoming.length; i++) {
    if (i != m_miningSchema.getFieldsAsInstances().classIndex() && 
        Double.isNaN(incoming[i])) {
      hasMissing = true;
      break;
    }
  }

  if (hasMissing) {
    if (!m_miningSchema.hasTargetMetaData()) {
      String message = "[GeneralRegression] WARNING: Instance to predict has missing value(s) but "
        + "there is no missing value handling meta data and no "
        + "prior probabilities/default value to fall back to. No "
        + "prediction will be made (" 
        + ((m_miningSchema.getFieldsAsInstances().classAttribute().isNominal()
            || m_miningSchema.getFieldsAsInstances().classAttribute().isString())
            ? "zero probabilities output)."
            : "NaN output).");
      if (m_log == null) {
        System.err.println(message);
      } else {
        m_log.logMessage(message);
      }

      if (m_miningSchema.getFieldsAsInstances().classAttribute().isNumeric()) {
        preds[0] = Utils.missingValue();
      }
      return preds;
    } else {
      // use prior probablilities/default value
      TargetMetaInfo targetData = m_miningSchema.getTargetMetaData();
      if (m_miningSchema.getFieldsAsInstances().classAttribute().isNumeric()) {
        preds[0] = targetData.getDefaultValue();
      } else {
        Instances miningSchemaI = m_miningSchema.getFieldsAsInstances();
        for (int i = 0; i < miningSchemaI.classAttribute().numValues(); i++) {
          preds[i] = targetData.getPriorProbability(miningSchemaI.classAttribute().value(i));
        }
      }
      return preds;
    }
  } else {
    // construct input parameter vector here
    double[] inputParamVector = incomingParamVector(incoming);
    computeResponses(incoming, inputParamVector, preds);
  }

  return preds;
}
项目:umple    文件:GeneralRegression.java   
/**                                                                                                             
 * Classifies the given test instance. The instance has to belong to a                                          
 * dataset when it's being classified.                                                          
 *                                                                                                              
 * @param inst the instance to be classified                                                                
 * @return the predicted most likely class for the instance or                                                  
 * Utils.missingValue() if no prediction is made                                                             
 * @exception Exception if an error occurred during the prediction                                              
 */
public double[] distributionForInstance(Instance inst) throws Exception {
  if (!m_initialized) {
    mapToMiningSchema(inst.dataset());
  }
  double[] preds = null;
  if (m_miningSchema.getFieldsAsInstances().classAttribute().isNumeric()) {
    preds = new double[1];
  } else {
    preds = new double[m_miningSchema.getFieldsAsInstances().classAttribute().numValues()];
  }

  // create an array of doubles that holds values from the incoming
  // instance; in order of the fields in the mining schema. We will
  // also handle missing values and outliers here.
  double[] incoming = m_fieldsMap.instanceToSchema(inst, m_miningSchema);

  // In this implementation we will default to information in the Target element (default
  // value for numeric prediction and prior probabilities for classification). If there is
  // no Target element defined, then an Exception is thrown.

  boolean hasMissing = false;
  for (int i = 0; i < incoming.length; i++) {
    if (i != m_miningSchema.getFieldsAsInstances().classIndex() && 
        Double.isNaN(incoming[i])) {
      hasMissing = true;
      break;
    }
  }

  if (hasMissing) {
    if (!m_miningSchema.hasTargetMetaData()) {
      String message = "[GeneralRegression] WARNING: Instance to predict has missing value(s) but "
        + "there is no missing value handling meta data and no "
        + "prior probabilities/default value to fall back to. No "
        + "prediction will be made (" 
        + ((m_miningSchema.getFieldsAsInstances().classAttribute().isNominal()
            || m_miningSchema.getFieldsAsInstances().classAttribute().isString())
            ? "zero probabilities output)."
            : "NaN output).");
      if (m_log == null) {
        System.err.println(message);
      } else {
        m_log.logMessage(message);
      }

      if (m_miningSchema.getFieldsAsInstances().classAttribute().isNumeric()) {
        preds[0] = Utils.missingValue();
      }
      return preds;
    } else {
      // use prior probablilities/default value
      TargetMetaInfo targetData = m_miningSchema.getTargetMetaData();
      if (m_miningSchema.getFieldsAsInstances().classAttribute().isNumeric()) {
        preds[0] = targetData.getDefaultValue();
      } else {
        Instances miningSchemaI = m_miningSchema.getFieldsAsInstances();
        for (int i = 0; i < miningSchemaI.classAttribute().numValues(); i++) {
          preds[i] = targetData.getPriorProbability(miningSchemaI.classAttribute().value(i));
        }
      }
      return preds;
    }
  } else {
    // construct input parameter vector here
    double[] inputParamVector = incomingParamVector(incoming);
    computeResponses(incoming, inputParamVector, preds);
  }

  return preds;
}