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


C# Instance.classAttribute方法代码示例

本文整理汇总了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();
				
			}
		}
开发者ID:intille,项目名称:mitessoftware,代码行数:51,代码来源:Classifier.cs

示例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;
				
			}
		}
开发者ID:intille,项目名称:mitessoftware,代码行数:45,代码来源:Classifier.cs


注:本文中的Instance.classAttribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。