本文整理匯總了Java中weka.core.Utils.missingValue方法的典型用法代碼示例。如果您正苦於以下問題:Java Utils.missingValue方法的具體用法?Java Utils.missingValue怎麽用?Java Utils.missingValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類weka.core.Utils
的用法示例。
在下文中一共展示了Utils.missingValue方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: distributionForInstance
import weka.core.Utils; //導入方法依賴的package包/類
/**
* Classifies a given instance after filtering.
*
* @param instance the instance to be classified
* @return the class distribution for the given instance
* @throws Exception if instance could not be classified successfully
*/
public double[] distributionForInstance(Instance instance) throws Exception {
Instance newInstance = filterInstance(instance);
if (newInstance == null) {
// filter has consumed the instance (e.g. RemoveWithValues
// may do this). We will indicate no prediction for this
// instance
double[] unclassified = null;
if (instance.classAttribute().isNumeric()) {
unclassified = new double[1];
unclassified[0] = Utils.missingValue();
} else {
// all zeros
unclassified = new double[instance.classAttribute().numValues()];
}
return unclassified;
} else {
return m_Classifier.distributionForInstance(newInstance);
}
}
示例2: getMembershipValues
import weka.core.Utils; //導入方法依賴的package包/類
/**
* Computes an array that has a value for each element in the partition. (If
* the base classifier supports this.)
*/
public double[] getMembershipValues(Instance inst) throws Exception {
if (m_Classifier instanceof PartitionGenerator) {
Instance newInstance = filterInstance(inst);
if (newInstance == null) {
double[] unclassified = new double[numElements()];
for (int i = 0; i < unclassified.length; i++) {
unclassified[i] = Utils.missingValue();
}
return unclassified;
} else {
return ((PartitionGenerator) m_Classifier)
.getMembershipValues(newInstance);
}
} else
throw new Exception("Classifier: " + getClassifierSpec()
+ " cannot generate a partition");
}
示例3: 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
*/
@Override
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;
}
}
示例4: makeInstance
import weka.core.Utils; //導入方法依賴的package包/類
/**
* generates an instance out of the given data
*
* @param tc the statistics
* @param prob the probability
* @return the generated instance
*/
private Instance makeInstance(TwoClassStats tc, double prob) {
int count = 0;
double[] vals = new double[13];
vals[count++] = tc.getTruePositive();
vals[count++] = tc.getFalseNegative();
vals[count++] = tc.getFalsePositive();
vals[count++] = tc.getTrueNegative();
vals[count++] = tc.getFalsePositiveRate();
vals[count++] = tc.getTruePositiveRate();
vals[count++] = tc.getPrecision();
vals[count++] = tc.getRecall();
vals[count++] = tc.getFallout();
vals[count++] = tc.getFMeasure();
double ss = (tc.getTruePositive() + tc.getFalsePositive())
/ (tc.getTruePositive() + tc.getFalsePositive() + tc.getTrueNegative() + tc
.getFalseNegative());
vals[count++] = ss;
double expectedByChance = (ss * (tc.getTruePositive() + tc
.getFalseNegative()));
if (expectedByChance < 1) {
vals[count++] = Utils.missingValue();
} else {
vals[count++] = tc.getTruePositive() / expectedByChance;
}
vals[count++] = prob;
return new DenseInstance(1.0, vals);
}
示例5: missingValueStrategyNullPrediction
import weka.core.Utils; //導入方法依賴的package包/類
/**
* Compute predictions and optionally invoke the null prediction missing
* value handling strategy.
*
* @param instance the incoming vector of attribute and derived field
* values.
* @param classAtt the class attribute.
* @return the predicted probability distribution.
* @throws Exception if something goes wrong.
*/
protected double[] missingValueStrategyNullPrediction(double[] instance,
Attribute classAtt) throws Exception {
double[] preds = null;
boolean strategyInvoked = false;
// look for a child whose predicate evaluates to TRUE
for (TreeNode c : m_childNodes) {
if (c.getPredicate().evaluate(instance) == Predicate.Eval.TRUE) {
preds = c.score(instance, classAtt);
break;
} else if (c.getPredicate().evaluate(instance) == Predicate.Eval.UNKNOWN) {
strategyInvoked = true;
}
}
// no true child found
if (preds == null) {
preds = new double[classAtt.numValues()];
if (!strategyInvoked) {
doNoTrueChild(classAtt, preds);
} else {
// do the strategy
for (int i = 0; i < classAtt.numValues(); i++) {
preds[i] = Utils.missingValue();
}
}
}
return preds;
}
示例6: makeOutputInstance
import weka.core.Utils; //導入方法依賴的package包/類
private Instance makeOutputInstance(Instances output, Instance source) {
double[] newVals = new double[output.numAttributes()];
for (int i = 0; i < newVals.length; i++) {
newVals[i] = Utils.missingValue();
}
for (int i = 0; i < source.numAttributes(); i++) {
if (!source.isMissing(i)) {
Attribute s = source.attribute(i);
int outputIndex = output.attribute(s.name()).index();
if (s.isNumeric()) {
newVals[outputIndex] = source.value(s);
} else if (s.isString()) {
String sVal = source.stringValue(s);
newVals[outputIndex] = output.attribute(outputIndex).addStringValue(
sVal);
} else if (s.isRelationValued()) {
Instances rVal = source.relationalValue(s);
newVals[outputIndex] = output.attribute(outputIndex)
.addRelation(rVal);
} else if (s.isNominal()) {
String nomVal = source.stringValue(s);
newVals[outputIndex] = output.attribute(outputIndex).indexOfValue(
nomVal);
}
}
}
Instance newInst = new DenseInstance(source.weight(), newVals);
newInst.setDataset(output);
return newInst;
}
示例7: getClassValueIndexFromRow
import weka.core.Utils; //導入方法依賴的package包/類
protected double getClassValueIndexFromRow(String[] parsed)
throws DistributedWekaException {
int classIndex = m_trainingHeader.classIndex();
if (classIndex < 0) {
throw new DistributedWekaException("No class index is set!");
}
String classVal = parsed[classIndex].trim();
double classValIndex = Utils.missingValue();
if (!DistributedJobConfig.isEmpty(classVal.trim())
&& !classVal.equals(m_rowHelper.getMissingValue())) {
classValIndex = m_trainingHeader.classAttribute().indexOfValue(classVal);
if (classValIndex < 0) {
// try the default vals in row helper
String defaultClassValue = m_rowHelper.getDefaultValue(classIndex);
if (defaultClassValue == null) {
throw new DistributedWekaException(
"Class value '"
+ classVal
+ "' does not seem to be defined in the header and there is no default value to use!");
}
classValIndex =
m_trainingHeader.classAttribute().indexOfValue(defaultClassValue);
}
}
return classValIndex;
}
開發者ID:mydzigear,項目名稱:repo.kmeanspp.silhouette_score,代碼行數:33,代碼來源:RandomizedDataChunkHadoopMapper.java
示例8: classifyInstance
import weka.core.Utils; //導入方法依賴的package包/類
/**
* Classifies the given test instance. The instance has to belong to a dataset
* when it's being classified. Note that a classifier MUST implement either
* this or distributionForInstance().
*
* @param instance 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
*/
@Override
public double classifyInstance(Instance instance) throws Exception {
double[] dist = distributionForInstance(instance);
if (dist == null) {
throw new Exception("Null distribution predicted");
}
switch (instance.classAttribute().type()) {
case Attribute.NOMINAL:
double max = 0;
int maxIndex = 0;
for (int i = 0; i < dist.length; i++) {
if (dist[i] > max) {
maxIndex = i;
max = dist[i];
}
}
if (max > 0) {
return maxIndex;
} else {
return Utils.missingValue();
}
case Attribute.NUMERIC:
case Attribute.DATE:
return dist[0];
default:
return Utils.missingValue();
}
}
示例9: convertInstance
import weka.core.Utils; //導入方法依賴的package包/類
/**
* Convert an input instance
*
* @param current the input instance to convert
* @return a transformed instance
* @throws Exception if a problem occurs
*/
protected Instance convertInstance(Instance current) throws Exception {
double[] vals = new double[getOutputFormat().numAttributes()];
int index = 0;
for (int j = 0; j < current.numAttributes(); j++) {
if (j != current.classIndex()) {
if (m_unchanged != null
&& m_unchanged.attribute(current.attribute(j).name()) != null) {
vals[index++] = current.value(j);
} else {
Estimator[] estForAtt =
m_estimatorLookup.get(current.attribute(j).name());
for (int k = 0; k < current.classAttribute().numValues(); k++) {
if (current.isMissing(j)) {
vals[index++] = Utils.missingValue();
} else {
double e = estForAtt[k].getProbability(current.value(j));
vals[index++] = e;
}
}
}
}
}
vals[vals.length - 1] = current.classValue();
DenseInstance instNew = new DenseInstance(current.weight(), vals);
return instNew;
}
示例10: areaUnderROC
import weka.core.Utils; //導入方法依賴的package包/類
/**
* Returns the area under ROC for those predictions that have been collected
* in the evaluateClassifier(Classifier, Instances) method. Returns
* Utils.missingValue() if the area is not available.
*
* @param classIndex the index of the class to consider as "positive"
* @return the area under the ROC curve or not a number
*/
public double areaUnderROC(int classIndex) {
// Check if any predictions have been collected
if (m_Predictions == null) {
return Utils.missingValue();
} else {
ThresholdCurve tc = new ThresholdCurve();
Instances result = tc.getCurve(m_Predictions, classIndex);
return ThresholdCurve.getROCArea(result);
}
}
示例11: NumericStats
import weka.core.Utils; //導入方法依賴的package包/類
/**
* Constructs a new NumericStats
*
* @param attributeName the name of the attribute that these statistics are
* for
*/
public NumericStats(String attributeName) {
super(attributeName);
m_stats[ArffSummaryNumericMetric.MIN.ordinal()] = Utils.missingValue();
m_stats[ArffSummaryNumericMetric.MAX.ordinal()] = Utils.missingValue();
m_stats[ArffSummaryNumericMetric.FIRSTQUARTILE.ordinal()] =
Utils.missingValue();
m_stats[ArffSummaryNumericMetric.MEDIAN.ordinal()] = Utils.missingValue();
m_stats[ArffSummaryNumericMetric.THIRDQUARTILE.ordinal()] =
Utils.missingValue();
}
示例12: areaUnderPRC
import weka.core.Utils; //導入方法依賴的package包/類
/**
* Returns the area under precision-recall curve (AUPRC) for those predictions
* that have been collected in the evaluateClassifier(Classifier, Instances)
* method. Returns Utils.missingValue() if the area is not available.
*
* @param classIndex the index of the class to consider as "positive"
* @return the area under the precision-recall curve or not a number
*/
public double areaUnderPRC(int classIndex) {
// Check if any predictions have been collected
if (m_Predictions == null) {
return Utils.missingValue();
} else {
ThresholdCurve tc = new ThresholdCurve();
Instances result = tc.getCurve(m_Predictions, classIndex);
return ThresholdCurve.getPRCArea(result);
}
}
示例13: classifyInstance
import weka.core.Utils; //導入方法依賴的package包/類
/**
* Classifies the given test instance.
*
* @param instance the instance to be classified
* @return the predicted most likely class for the instance or
* Utils.missingValue() if no prediction is made
* @throws Exception if an error occurred during the prediction
*/
@Override
public double classifyInstance(Instance instance) throws Exception {
double result;
double[] dist;
int index;
switch (m_CombinationRule) {
case AVERAGE_RULE:
case PRODUCT_RULE:
case MAJORITY_VOTING_RULE:
case MIN_RULE:
case MAX_RULE:
dist = distributionForInstance(instance);
if (instance.classAttribute().isNominal()) {
index = Utils.maxIndex(dist);
if (dist[index] == 0) {
result = Utils.missingValue();
} else {
result = index;
}
} else if (instance.classAttribute().isNumeric()) {
result = dist[0];
} else {
result = Utils.missingValue();
}
break;
case MEDIAN_RULE:
result = classifyInstanceMedian(instance);
break;
default:
throw new IllegalStateException("Unknown combination rule '"
+ m_CombinationRule + "'!");
}
return result;
}
示例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包/類
/**
* Computes class distribution of an instance using the decision tree.
*
* @param instance the instance to compute the distribution for
* @return the computed class distribution
* @throws Exception if computation fails
*/
public double[] distributionForInstance(Instance instance) throws Exception {
double[] returnedDist = null;
if (m_Attribute > -1) {
// Node is not a leaf
if (instance.isMissing(m_Attribute)) {
// Value is missing
returnedDist = new double[m_Info.numClasses()];
// Split instance up
for (int i = 0; i < m_Successors.length; i++) {
double[] help = m_Successors[i].distributionForInstance(instance);
if (help != null) {
for (int j = 0; j < help.length; j++) {
returnedDist[j] += m_Prop[i] * help[j];
}
}
}
} else if (m_Info.attribute(m_Attribute).isNominal()) {
// For nominal attributes
returnedDist = m_Successors[(int) instance.value(m_Attribute)]
.distributionForInstance(instance);
} else {
// For numeric attributes
if (instance.value(m_Attribute) < m_SplitPoint) {
returnedDist = m_Successors[0].distributionForInstance(instance);
} else {
returnedDist = m_Successors[1].distributionForInstance(instance);
}
}
}
// Node is a leaf or successor is empty?
if ((m_Attribute == -1) || (returnedDist == null)) {
// Is node empty?
if (m_ClassDistribution == null) {
if (getAllowUnclassifiedInstances()) {
double[] result = new double[m_Info.numClasses()];
if (m_Info.classAttribute().isNumeric()) {
result[0] = Utils.missingValue();
}
return result;
} else {
return null;
}
}
// Else return normalized distribution
double[] normalizedDistribution = m_ClassDistribution.clone();
if (m_Info.classAttribute().isNominal()) {
Utils.normalize(normalizedDistribution);
}
return normalizedDistribution;
} else {
return returnedDist;
}
}