当前位置: 首页>>代码示例>>Java>>正文


Java TargetMetaInfo.getPriorProbability方法代码示例

本文整理汇总了Java中weka.core.pmml.TargetMetaInfo.getPriorProbability方法的典型用法代码示例。如果您正苦于以下问题:Java TargetMetaInfo.getPriorProbability方法的具体用法?Java TargetMetaInfo.getPriorProbability怎么用?Java TargetMetaInfo.getPriorProbability使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在weka.core.pmml.TargetMetaInfo的用法示例。


在下文中一共展示了TargetMetaInfo.getPriorProbability方法的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.getPriorProbability方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。