本文整理汇总了C#中Instance.classValue方法的典型用法代码示例。如果您正苦于以下问题:C# Instance.classValue方法的具体用法?C# Instance.classValue怎么用?C# Instance.classValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Instance
的用法示例。
在下文中一共展示了Instance.classValue方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: updateStatsForPredictor
/// <summary> Updates all the statistics about a predictors performance for
/// the current test instance.
///
/// </summary>
/// <param name="predictedValue">the numeric value the classifier predicts
/// </param>
/// <param name="instance">the instance to be classified
/// </param>
/// <throws> Exception if the class of the instance is not </throws>
/// <summary> set
/// </summary>
protected internal virtual void updateStatsForPredictor(double predictedValue, Instance instance)
{
if (!instance.classIsMissing())
{
// Update stats
m_WithClass += instance.weight();
if (Instance.isMissingValue(predictedValue))
{
m_Unclassified += instance.weight();
return ;
}
m_SumClass += instance.weight() * instance.classValue();
m_SumSqrClass += instance.weight() * instance.classValue() * instance.classValue();
m_SumClassPredicted += instance.weight() * instance.classValue() * predictedValue;
m_SumPredicted += instance.weight() * predictedValue;
m_SumSqrPredicted += instance.weight() * predictedValue * predictedValue;
if (m_ErrorEstimator == null)
{
setNumericPriorsFromBuffer();
}
double predictedProb = Math.Max(m_ErrorEstimator.getProbability(predictedValue - instance.classValue()), MIN_SF_PROB);
double priorProb = Math.Max(m_PriorErrorEstimator.getProbability(instance.classValue()), MIN_SF_PROB);
m_SumSchemeEntropy -= Utils.log2(predictedProb) * instance.weight();
m_SumPriorEntropy -= Utils.log2(priorProb) * instance.weight();
m_ErrorEstimator.addValue(predictedValue - instance.classValue(), instance.weight());
updateNumericScores(makeDistribution(predictedValue), makeDistribution(instance.classValue()), instance.weight());
}
else
m_MissingClass += instance.weight();
}
示例2: updateStatsForClassifier
/// <summary> Updates all the statistics about a classifiers performance for
/// the current test instance.
///
/// </summary>
/// <param name="predictedDistribution">the probabilities assigned to
/// each class
/// </param>
/// <param name="instance">the instance to be classified
/// </param>
/// <throws> Exception if the class of the instance is not </throws>
/// <summary> set
/// </summary>
protected internal virtual void updateStatsForClassifier(double[] predictedDistribution, Instance instance)
{
//UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
int actualClass = (int) instance.classValue();
if (!instance.classIsMissing())
{
updateMargins(predictedDistribution, actualClass, instance.weight());
// Determine the predicted class (doesn't detect multiple
// classifications)
int predictedClass = - 1;
double bestProb = 0.0;
for (int i = 0; i < m_NumClasses; i++)
{
if (predictedDistribution[i] > bestProb)
{
predictedClass = i;
bestProb = predictedDistribution[i];
}
}
m_WithClass += instance.weight();
// Determine misclassification cost
if (m_CostMatrix != null)
{
if (predictedClass < 0)
{
// For missing predictions, we assume the worst possible cost.
// This is pretty harsh.
// Perhaps we could take the negative of the cost of a correct
// prediction (-m_CostMatrix.getXmlElement(actualClass,actualClass)),
// although often this will be zero
m_TotalCost += instance.weight() * m_CostMatrix.getMaxCost(actualClass);
}
else
{
m_TotalCost += instance.weight() * m_CostMatrix.getXmlElement(actualClass, predictedClass);
}
}
// Update counts when no class was predicted
if (predictedClass < 0)
{
m_Unclassified += instance.weight();
return ;
}
double predictedProb = System.Math.Max(MIN_SF_PROB, predictedDistribution[actualClass]);
double priorProb = System.Math.Max(MIN_SF_PROB, m_ClassPriors[actualClass] / m_ClassPriorsSum);
if (predictedProb >= priorProb)
{
m_SumKBInfo += (Utils.log2(predictedProb) - Utils.log2(priorProb)) * instance.weight();
}
else
{
m_SumKBInfo -= (Utils.log2(1.0 - predictedProb) - Utils.log2(1.0 - priorProb)) * instance.weight();
}
m_SumSchemeEntropy -= Utils.log2(predictedProb) * instance.weight();
m_SumPriorEntropy -= Utils.log2(priorProb) * instance.weight();
updateNumericScores(predictedDistribution, makeDistribution(instance.classValue()), instance.weight());
// Update other stats
m_ConfusionMatrix[actualClass][predictedClass] += instance.weight();
if (predictedClass != actualClass)
{
m_Incorrect += instance.weight();
}
else
{
m_Correct += instance.weight();
}
}
else
{
m_MissingClass += instance.weight();
}
}
示例3: shift
/// <summary> Shifts given instance from one bag to another one.
///
/// </summary>
/// <exception cref="Exception">if something goes wrong
/// </exception>
public void shift(int from, int to, Instance instance)
{
int classIndex;
double weight;
//UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
classIndex = (int) instance.classValue();
weight = instance.weight();
m_perClassPerBag[from][classIndex] -= weight;
m_perClassPerBag[to][classIndex] += weight;
m_perBag[from] -= weight;
m_perBag[to] += weight;
}
示例4: updatePriors
/// <summary> Updates the class prior probabilities (when incrementally
/// training)
///
/// </summary>
/// <param name="instance">the new training instance seen
/// </param>
/// <throws> Exception if the class of the instance is not </throws>
/// <summary> set
/// </summary>
public virtual void updatePriors(Instance instance)
{
if (!instance.classIsMissing())
{
if (!m_ClassIsNominal)
{
if (!instance.classIsMissing())
{
addNumericTrainClass(instance.classValue(), instance.weight());
}
}
else
{
//UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
m_ClassPriors[(int) instance.classValue()] += instance.weight();
m_ClassPriorsSum += instance.weight();
}
}
}
示例5: addWeights
/// <summary> Adds given instance to all bags weighting it according to given weights.
///
/// </summary>
/// <exception cref="Exception">if something goes wrong
/// </exception>
public void addWeights(Instance instance, double[] weights)
{
int classIndex;
int i;
//UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
classIndex = (int) instance.classValue();
for (i = 0; i < m_perBag.Length; i++)
{
double weight = instance.weight() * weights[i];
m_perClassPerBag[i][classIndex] = m_perClassPerBag[i][classIndex] + weight;
m_perBag[i] = m_perBag[i] + weight;
m_perClass[classIndex] = m_perClass[classIndex] + weight;
totaL = totaL + weight;
}
}