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


C# Instances.deleteAttributeAt方法代码示例

本文整理汇总了C#中weka.core.Instances.deleteAttributeAt方法的典型用法代码示例。如果您正苦于以下问题:C# Instances.deleteAttributeAt方法的具体用法?C# Instances.deleteAttributeAt怎么用?C# Instances.deleteAttributeAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在weka.core.Instances的用法示例。


在下文中一共展示了Instances.deleteAttributeAt方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: test


//.........这里部分代码省略.........
					if (instances.instance(i).classIsMissing())
					{
						System.Console.Out.WriteLine("\tis missing");
					}
					else
					{
						System.Console.Out.WriteLine();
					}
				}
				
				// Create random weights.
				System.Console.Out.WriteLine("\nCreating random weights for instances.");
				for (i = 0; i < instances.numInstances(); i++)
				{
					instances.instance(i).Weight = random.NextDouble();
				}
				
				// Print all instances and their weights (and the sum of weights).
				System.Console.Out.WriteLine("\nInstances and their weights:\n");
				System.Console.Out.WriteLine(instances.instancesAndWeights());
				System.Console.Out.Write("\nSum of weights: ");
				System.Console.Out.WriteLine(instances.sumOfWeights());
				
				// Insert an attribute
				secondInstances = new Instances(instances);
				Attribute testAtt = new Attribute("Inserted");
				secondInstances.insertAttributeAt(testAtt, 0);
				System.Console.Out.WriteLine("\nSet with inserted attribute:\n");
				//UPGRADE_TODO: Method 'java.io.PrintStream.println' was converted to 'System.Console.Out.WriteLine' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioPrintStreamprintln_javalangObject'"
				System.Console.Out.WriteLine(secondInstances);
				System.Console.Out.WriteLine("\nClass name: " + secondInstances.classAttribute().name());
				
				// Delete the attribute
				secondInstances.deleteAttributeAt(0);
				System.Console.Out.WriteLine("\nSet with attribute deleted:\n");
				//UPGRADE_TODO: Method 'java.io.PrintStream.println' was converted to 'System.Console.Out.WriteLine' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioPrintStreamprintln_javalangObject'"
				System.Console.Out.WriteLine(secondInstances);
				System.Console.Out.WriteLine("\nClass name: " + secondInstances.classAttribute().name());
				
				// Test if headers are equal
				System.Console.Out.WriteLine("\nHeaders equal: " + instances.equalHeaders(secondInstances) + "\n");
				
				// Print data in internal format.
				System.Console.Out.WriteLine("\nData (internal values):\n");
				for (i = 0; i < instances.numInstances(); i++)
				{
					for (j = 0; j < instances.numAttributes(); j++)
					{
						if (instances.instance(i).isMissing(j))
						{
							System.Console.Out.Write("? ");
						}
						else
						{
							System.Console.Out.Write(instances.instance(i).value_Renamed(j) + " ");
						}
					}
					System.Console.Out.WriteLine();
				}
				
				// Just print header
				System.Console.Out.WriteLine("\nEmpty dataset:\n");
				empty = new Instances(instances, 0);
				//UPGRADE_TODO: Method 'java.io.PrintStream.println' was converted to 'System.Console.Out.WriteLine' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioPrintStreamprintln_javalangObject'"
				System.Console.Out.WriteLine(empty);
				System.Console.Out.WriteLine("\nClass name: " + empty.classAttribute().name());
开发者ID:intille,项目名称:mitessoftware,代码行数:67,代码来源:Instances.cs

示例2: buildClassifier

		/// <summary> Builds the boosted classifier</summary>
		public virtual void  buildClassifier(Instances data)
		{
			m_RandomInstance = new Random(m_Seed);
			Instances boostData;
			int classIndex = data.classIndex();
			
			if (data.classAttribute().Numeric)
			{
				throw new Exception("LogitBoost can't handle a numeric class!");
			}
			if (m_Classifier == null)
			{
				throw new System.Exception("A base classifier has not been specified!");
			}
			
			if (!(m_Classifier is WeightedInstancesHandler) && !m_UseResampling)
			{
				m_UseResampling = true;
			}
			if (data.checkForStringAttributes())
			{
				throw new Exception("Cannot handle string attributes!");
			}
			if (m_Debug)
			{
				System.Console.Error.WriteLine("Creating copy of the training data");
			}
			
			m_NumClasses = data.numClasses();
			m_ClassAttribute = data.classAttribute();
			
			// Create a copy of the data 
			data = new Instances(data);
			data.deleteWithMissingClass();
			
			// Create the base classifiers
			if (m_Debug)
			{
				System.Console.Error.WriteLine("Creating base classifiers");
			}
			m_Classifiers = new Classifier[m_NumClasses][];
			for (int j = 0; j < m_NumClasses; j++)
			{
				m_Classifiers[j] = Classifier.makeCopies(m_Classifier, this.NumIterations);
			}
			
			// Do we want to select the appropriate number of iterations
			// using cross-validation?
			int bestNumIterations = this.NumIterations;
			if (m_NumFolds > 1)
			{
				if (m_Debug)
				{
					System.Console.Error.WriteLine("Processing first fold.");
				}
				
				// Array for storing the results
				double[] results = new double[this.NumIterations];
				
				// Iterate throught the cv-runs
				for (int r = 0; r < m_NumRuns; r++)
				{
					
					// Stratify the data
					data.randomize(m_RandomInstance);
					data.stratify(m_NumFolds);
					
					// Perform the cross-validation
					for (int i = 0; i < m_NumFolds; i++)
					{
						
						// Get train and test folds
						Instances train = data.trainCV(m_NumFolds, i, m_RandomInstance);
						Instances test = data.testCV(m_NumFolds, i);
						
						// Make class numeric
						Instances trainN = new Instances(train);
						trainN.ClassIndex = - 1;
						trainN.deleteAttributeAt(classIndex);
						trainN.insertAttributeAt(new weka.core.Attribute("'pseudo class'"), classIndex);
						trainN.ClassIndex = classIndex;
						m_NumericClassData = new Instances(trainN, 0);
						
						// Get class values
						int numInstances = train.numInstances();
						double[][] tmpArray = new double[numInstances][];
						for (int i2 = 0; i2 < numInstances; i2++)
						{
							tmpArray[i2] = new double[m_NumClasses];
						}
						double[][] trainFs = tmpArray;
						double[][] tmpArray2 = new double[numInstances][];
						for (int i3 = 0; i3 < numInstances; i3++)
						{
							tmpArray2[i3] = new double[m_NumClasses];
						}
						double[][] trainYs = tmpArray2;
						for (int j = 0; j < m_NumClasses; j++)
						{
//.........这里部分代码省略.........
开发者ID:intille,项目名称:mitessoftware,代码行数:101,代码来源:LogitBoost.cs


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