本文整理汇总了Java中weka.core.Utils.isMissingValue方法的典型用法代码示例。如果您正苦于以下问题:Java Utils.isMissingValue方法的具体用法?Java Utils.isMissingValue怎么用?Java Utils.isMissingValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类weka.core.Utils
的用法示例。
在下文中一共展示了Utils.isMissingValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: applyMissingValueTreatment
import weka.core.Utils; //导入方法依赖的package包/类
/**
* Apply the missing value treatment method for this field.
*
* @param value the incoming value to apply the treatment to
* @return the value after applying the missing value treatment (if any)
* @throws Exception if there is a problem
*/
public double applyMissingValueTreatment(double value) throws Exception {
double newVal = value;
if (m_missingValueTreatmentMethod != Missing.ASIS &&
Utils.isMissingValue(value)) {
if (m_missingValueReplacementNominal != null) {
Attribute att = m_miningSchemaI.attribute(m_index);
int valIndex = att.indexOfValue(m_missingValueReplacementNominal);
if (valIndex < 0) {
throw new Exception("[MiningSchema] Nominal missing value replacement value doesn't "
+ "exist in the mining schema Instances!");
}
newVal = valIndex;
} else {
newVal = m_missingValueReplacementNumeric;
}
}
return newVal;
}
示例2: distributionForInstance
import weka.core.Utils; //导入方法依赖的package包/类
/**
* Predicts the class memberships for a given instance. If an instance is
* unclassified, the returned array elements must be all zero. If the class is
* numeric, the array must consist of only one element, which contains the
* predicted value. Note that a classifier MUST implement either this or
* classifyInstance().
*
* @param instance the instance to be classified
* @return an array containing the estimated membership probabilities of the
* test instance in each class or the numeric prediction
* @exception Exception if distribution could not be computed successfully
*/
@Override
public double[] distributionForInstance(Instance instance) throws Exception {
double[] dist = new double[instance.numClasses()];
switch (instance.classAttribute().type()) {
case Attribute.NOMINAL:
double classification = classifyInstance(instance);
if (Utils.isMissingValue(classification)) {
return dist;
} else {
dist[(int) classification] = 1.0;
}
return dist;
case Attribute.NUMERIC:
case Attribute.DATE:
dist[0] = classifyInstance(instance);
return dist;
default:
return dist;
}
}
示例3: getResult
import weka.core.Utils; //导入方法依赖的package包/类
/**
* Get the result of evaluating the expression. In the case
* of a continuous optype, a real number is returned; in
* the case of a categorical/ordinal optype, the index of the nominal
* value is returned as a double.
*
* @param incoming the incoming parameter values
* @return the result of evaluating the expression
* @throws Exception if there is a problem computing the result
*/
public double getResult(double[] incoming) throws Exception {
double result = 0.0;
if (Utils.isMissingValue(incoming[m_fieldIndex])) {
if (m_mapMissingDefined) {
result = m_mapMissingTo; // return the replacement
} else {
result = incoming[m_fieldIndex]; // just return the missing value
}
} else {
if (m_fieldValueIndex == (int)incoming[m_fieldIndex]) {
result = 1.0;
}
}
return result;
}
示例4: score
import weka.core.Utils; //导入方法依赖的package包/类
/**
* Score the incoming instance
*
* @param instance a vector containing the incoming independent and
* derived independent variables
* @param classAtt the class attribute
* @param rsm the rule selection method (ignored by simple rules)
* @return a probability distribution over the class labels or
* the predicted value (in element zero of the array if the class is numeric)
* @throws Exception if something goes wrong
*/
public double[] score(double[] instance, Attribute classAtt)
throws Exception {
double[] preds;
if (classAtt.isNumeric()) {
preds = new double[1];
preds[0] = m_score;
} else {
preds = new double[classAtt.numValues()];
if (m_scoreDistributions.size() > 0) {
for (TreeModel.ScoreDistribution s : m_scoreDistributions) {
preds[s.getClassLabelIndex()] = s.getConfidence();
}
} else if (!Utils.isMissingValue(m_confidence)) {
preds[classAtt.indexOfValue(m_scoreString)] = m_confidence;
} else {
preds[classAtt.indexOfValue(m_scoreString)] = 1.0;
}
}
return preds;
}
示例5: toString
import weka.core.Utils; //导入方法依赖的package包/类
public String toString(String prefix, int indent) {
StringBuffer temp = new StringBuffer();
for (int i = 0; i < indent; i++) {
prefix += " ";
}
temp.append(prefix + "Simple rule: " + m_predicate + "\n");
temp.append(prefix + " => " + m_scoreString + "\n");
if (!Utils.isMissingValue(m_recordCount)) {
temp.append(prefix + " recordCount: " + m_recordCount + "\n");
}
if (!Utils.isMissingValue(m_nbCorrect)) {
temp.append(prefix + " nbCorrect: " + m_nbCorrect + "\n");
}
if (!Utils.isMissingValue(m_confidence)) {
temp.append(prefix + " confidence: " + m_confidence + "\n");
}
if (!Utils.isMissingValue(m_weight)) {
temp.append(prefix + " weight: " + m_weight + "\n");
}
return temp.toString();
}
示例6: residualReplace
import weka.core.Utils; //导入方法依赖的package包/类
/**
* Replace the class values of the instances from the current iteration
* with residuals ater predicting with the supplied classifier.
*
* @param data the instances to predict
* @param c the classifier to use
* @param useShrinkage whether shrinkage is to be applied to the model's output
* @return a new set of instances with class values replaced by residuals
* @throws Exception if something goes wrong
*/
private Instances residualReplace(Instances data, Classifier c,
boolean useShrinkage) throws Exception {
double pred,residual;
Instances newInst = new Instances(data);
for (int i = 0; i < newInst.numInstances(); i++) {
pred = c.classifyInstance(newInst.instance(i));
if (Utils.isMissingValue(pred)) {
throw new UnassignedClassException("AdditiveRegression: base learner predicted missing value.");
}
if (useShrinkage) {
pred *= getShrinkage();
}
residual = newInst.instance(i).classValue() - pred;
newInst.instance(i).setClassValue(residual);
}
// System.err.print(newInst);
return newInst;
}
示例7: update
import weka.core.Utils; //导入方法依赖的package包/类
@Override
public void update(double attVal, String classVal, double weight) {
if (!Utils.isMissingValue(attVal)) {
GaussianEstimator norm = (GaussianEstimator) m_classLookup.get(classVal);
if (norm == null) {
norm = new GaussianEstimator();
m_classLookup.put(classVal, norm);
m_minValObservedPerClass.put(classVal, attVal);
m_maxValObservedPerClass.put(classVal, attVal);
} else {
if (attVal < m_minValObservedPerClass.get(classVal)) {
m_minValObservedPerClass.put(classVal, attVal);
}
if (attVal > m_maxValObservedPerClass.get(classVal)) {
m_maxValObservedPerClass.put(classVal, attVal);
}
}
norm.addValue(attVal, weight);
}
}
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:22,代码来源:GaussianConditionalSufficientStats.java
示例8: weightedAreaUnderPRC
import weka.core.Utils; //导入方法依赖的package包/类
/**
* Calculates the weighted (by class size) AUPRC.
*
* @return the weighted AUPRC.
*/
public double weightedAreaUnderPRC() {
double[] classCounts = new double[m_NumClasses];
double classCountSum = 0;
for (int i = 0; i < m_NumClasses; i++) {
for (int j = 0; j < m_NumClasses; j++) {
classCounts[i] += m_ConfusionMatrix[i][j];
}
classCountSum += classCounts[i];
}
double auprcTotal = 0;
for (int i = 0; i < m_NumClasses; i++) {
double temp = areaUnderPRC(i);
if (!Utils.isMissingValue(temp)) {
auprcTotal += (temp * classCounts[i]);
}
}
return auprcTotal / classCountSum;
}
示例9: makeDistribution
import weka.core.Utils; //导入方法依赖的package包/类
/**
* Convert a single prediction into a probability distribution with all zero
* probabilities except the predicted value which has probability 1.0.
*
* @param predictedClass the index of the predicted class
* @return the probability distribution
*/
protected double[] makeDistribution(double predictedClass) {
double[] result = new double[m_NumClasses];
if (Utils.isMissingValue(predictedClass)) {
return result;
}
if (m_ClassIsNominal) {
result[(int) predictedClass] = 1.0;
} else {
result[0] = predictedClass;
}
return result;
}
示例10: getNumericAttributeStatsSparse
import weka.core.Utils; //导入方法依赖的package包/类
public static NumericStats getNumericAttributeStatsSparse(
Instances denormalized, int attIndex) {
NumericStats ns = new NumericStats(denormalized.attribute(attIndex).name());
for (int j = 0; j < denormalized.numInstances(); j++) {
double value = denormalized.instance(j).value(attIndex);
if (Utils.isMissingValue(value) || value == 0) {
ns.getStats()[ArffSummaryNumericMetric.MISSING.ordinal()]++;
} else {
ns.getStats()[ArffSummaryNumericMetric.COUNT.ordinal()]++;
ns.getStats()[ArffSummaryNumericMetric.SUM.ordinal()] += value;
ns.getStats()[ArffSummaryNumericMetric.SUMSQ.ordinal()] += value
* value;
if (Double.isNaN(ns.getStats()[ArffSummaryNumericMetric.MIN.ordinal()])) {
ns.getStats()[ArffSummaryNumericMetric.MIN.ordinal()] =
ns.getStats()[ArffSummaryNumericMetric.MAX
.ordinal()] = value;
} else if (value < ns.getStats()[ArffSummaryNumericMetric.MIN.ordinal()]) {
ns.getStats()[ArffSummaryNumericMetric.MIN.ordinal()] = value;
} else if (value > ns.getStats()[ArffSummaryNumericMetric.MAX.ordinal()]) {
ns.getStats()[ArffSummaryNumericMetric.MAX.ordinal()] = value;
}
}
}
ns.computeDerived();
return ns;
}
示例11: dumpTree
import weka.core.Utils; //导入方法依赖的package包/类
protected void dumpTree(int level, StringBuffer text) {
if (m_childNodes.size() > 0) {
for (int i = 0; i < m_childNodes.size(); i++) {
text.append("\n");
/*
* for (int j = 0; j < level; j++) { text.append("| "); }
*/
// output the predicate for this child node
TreeNode child = m_childNodes.get(i);
text.append(child.getPredicate().toString(level, false));
// process recursively
child.dumpTree(level + 1, text);
}
} else {
// leaf
text.append(": ");
if (!Utils.isMissingValue(m_scoreNumeric)) {
text.append(m_scoreNumeric);
} else {
text.append(m_scoreString + " ");
if (m_scoreDistributions.size() > 0) {
text.append("[");
for (ScoreDistribution s : m_scoreDistributions) {
text.append(s);
}
text.append("]");
} else {
text.append(m_scoreString);
}
}
}
}
示例12: difference
import weka.core.Utils; //导入方法依赖的package包/类
/**
* Computes the difference between two given attribute values.
*/
private double difference(int index, double val1, double val2) {
switch (m_trainInstances.attribute(index).type()) {
case Attribute.NOMINAL:
// If attribute is nominal
if (Utils.isMissingValue(val1) || Utils.isMissingValue(val2)) {
return (1.0 - (1.0 / (m_trainInstances.attribute(index).numValues())));
} else if ((int) val1 != (int) val2) {
return 1;
} else {
return 0;
}
case Attribute.NUMERIC:
// If attribute is numeric
if (Utils.isMissingValue(val1) || Utils.isMissingValue(val2)) {
if (Utils.isMissingValue(val1) && Utils.isMissingValue(val2)) {
return 1;
} else {
double diff;
if (Utils.isMissingValue(val2)) {
diff = norm(val1, index);
} else {
diff = norm(val2, index);
}
if (diff < 0.5) {
diff = 1.0 - diff;
}
return diff;
}
} else {
return Math.abs(norm(val1, index) - norm(val2, index));
}
default:
return 0;
}
}
示例13: distributionForInstance
import weka.core.Utils; //导入方法依赖的package包/类
/**
* Calculates the class membership probabilities for the given test
* instance.
*
* @param instance the instance to be classified
* @return preedicted class probability distribution
* @exception Exception if distribution can't be computed successfully
*/
public double[] distributionForInstance(Instance instance) throws Exception {
double [] sums = new double [instance.numClasses()], newProbs;
double numPreds = 0;
for (int i = 0; i < m_NumIterations; i++) {
if (instance.classAttribute().isNumeric() == true) {
double pred = m_Classifiers[i].classifyInstance(instance);
if (!Utils.isMissingValue(pred)) {
sums[0] += pred;
numPreds++;
}
} else {
newProbs = m_Classifiers[i].distributionForInstance(instance);
for (int j = 0; j < newProbs.length; j++)
sums[j] += newProbs[j];
}
}
if (instance.classAttribute().isNumeric() == true) {
if (numPreds == 0) {
sums[0] = Utils.missingValue();
} else {
sums[0] /= numPreds;
}
return sums;
} else if (Utils.eq(Utils.sum(sums), 0)) {
return sums;
} else {
Utils.normalize(sums);
return sums;
}
}
示例14: distributionForInstance
import weka.core.Utils; //导入方法依赖的package包/类
/**
* Calculates the class membership probabilities for the given test
* instance.
*
* @param instance the instance to be classified
* @return preedicted class probability distribution
* @throws Exception if distribution can't be computed successfully
*/
public double[] distributionForInstance(Instance instance) throws Exception {
// default model?
if (m_ZeroR != null) {
return m_ZeroR.distributionForInstance(instance);
}
double[] sums = new double [instance.numClasses()], newProbs;
double numPreds = 0;
for (int i = 0; i < m_NumIterations; i++) {
if (instance.classAttribute().isNumeric() == true) {
double pred = m_Classifiers[i].classifyInstance(instance);
if (!Utils.isMissingValue(pred)) {
sums[0] += pred;
numPreds++;
}
} else {
newProbs = m_Classifiers[i].distributionForInstance(instance);
for (int j = 0; j < newProbs.length; j++)
sums[j] += newProbs[j];
}
}
if (instance.classAttribute().isNumeric() == true) {
if (numPreds == 0) {
sums[0] = Utils.missingValue();
} else {
sums[0] /= numPreds;
}
return sums;
} else if (Utils.eq(Utils.sum(sums), 0)) {
return sums;
} else {
Utils.normalize(sums);
return sums;
}
}
示例15: distributionForInstance
import weka.core.Utils; //导入方法依赖的package包/类
/**
* Calculates the class membership probabilities for the given test instance.
*
* @param instance the instance to be classified
* @return predicted class probability distribution
* @throws Exception if instance could not be classified successfully
*/
public double[] distributionForInstance(Instance inst) throws Exception {
// default model?
if (m_ZeroR != null) {
return m_ZeroR.distributionForInstance(inst);
}
double[] Fs = new double[m_NumClasses];
double[] pred = new double[m_NumClasses];
Instance instance = (Instance) inst.copy();
instance.setDataset(m_NumericClassData);
for (int i = 0; i < m_NumGenerated; i++) {
double predSum = 0;
for (int j = 0; j < m_NumClasses; j++) {
double tempPred =
m_Shrinkage * m_Classifiers.get(i)[j].classifyInstance(instance);
if (Utils.isMissingValue(tempPred)) {
throw new UnassignedClassException(
"LogitBoost: base learner predicted missing value.");
}
pred[j] = tempPred;
if (m_NumClasses == 2) {
pred[1] = -tempPred; // Can treat 2 classes as special case
break;
}
predSum += pred[j];
}
predSum /= m_NumClasses;
for (int j = 0; j < m_NumClasses; j++) {
Fs[j] += (pred[j] - predSum) * (m_NumClasses - 1) / m_NumClasses;
}
}
return probs(Fs);
}