本文整理汇总了C#中Instance.classAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# Instance.classAttribute方法的具体用法?C# Instance.classAttribute怎么用?C# Instance.classAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Instance
的用法示例。
在下文中一共展示了Instance.classAttribute方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: classifyInstance
/// <summary> 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().
///
/// </summary>
/// <param name="instance">the instance to be classified
/// </param>
/// <returns> the predicted most likely class for the instance or
/// Instance.missingValue() if no prediction is made
/// </returns>
/// <exception cref="Exception">if an error occurred during the prediction
/// </exception>
public virtual double classifyInstance(Instance instance)
{
double[] dist = distributionForInstance(instance);
if (dist == null)
{
throw new System.Exception("Null distribution predicted");
}
switch (instance.classAttribute().type())
{
case weka.core.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 Instance.missingValue();
}
case weka.core.Attribute.NUMERIC:
return dist[0];
default:
return Instance.missingValue();
}
}
示例2: distributionForInstance
/// <summary> 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().
///
/// </summary>
/// <param name="instance">the instance to be classified
/// </param>
/// <returns> an array containing the estimated membership
/// probabilities of the test instance in each class
/// or the numeric prediction
/// </returns>
/// <exception cref="Exception">if distribution could not be
/// computed successfully
/// </exception>
public virtual double[] distributionForInstance(Instance instance)
{
double[] dist = new double[instance.numClasses()];
switch (instance.classAttribute().type())
{
case weka.core.Attribute.NOMINAL:
double classification = classifyInstance(instance);
if (Instance.isMissingValue(classification))
{
return dist;
}
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'"
dist[(int) classification] = 1.0;
}
return dist;
case weka.core.Attribute.NUMERIC:
dist[0] = classifyInstance(instance);
return dist;
default:
return dist;
}
}