當前位置: 首頁>>代碼示例>>Java>>正文


Java TargetMetaInfo類代碼示例

本文整理匯總了Java中weka.core.pmml.TargetMetaInfo的典型用法代碼示例。如果您正苦於以下問題:Java TargetMetaInfo類的具體用法?Java TargetMetaInfo怎麽用?Java TargetMetaInfo使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


TargetMetaInfo類屬於weka.core.pmml包,在下文中一共展示了TargetMetaInfo類的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: distributionForInstance

import weka.core.pmml.TargetMetaInfo; //導入依賴的package包/類
/**                                                                                                             
 * 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;
}
 
開發者ID:mydzigear,項目名稱:repo.kmeanspp.silhouette_score,代碼行數:80,代碼來源:GeneralRegression.java


注:本文中的weka.core.pmml.TargetMetaInfo類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。