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


C# Instance.dataset方法代码示例

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


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

示例1: Classify

 public string Classify(double lastTimestamp)
 {
     string predicted_class = null;
     //attempt to generate a feature vector
     if (Extractor.GenerateFeatureVector(lastTimestamp))
     {
         Instance newinstance = new Instance(instances.numAttributes());
         newinstance.Dataset = instances;
         for (int i = 0; (i < this.features.Count); i++)
             newinstance.setValue(instances.attribute(i), Extractor.Features[this.featureIndex[i]]);
         double predicted = classifier.classifyInstance(newinstance);
         predicted_class = newinstance.dataset().classAttribute().value_Renamed((int)predicted);                
     }
     return predicted_class;
 }
开发者ID:intille,项目名称:mitessoftware,代码行数:15,代码来源:DTClassifier.cs

示例2: convertInstance

		/// <summary> Convert a single instance over. The converted instance is 
		/// added to the end of the output queue.
		/// 
		/// </summary>
		/// <param name="instance">the instance to convert
		/// </param>
		private void  convertInstance(Instance instance)
		{
			
			Instance inst = null;
			if (instance is SparseInstance)
			{
				double[] vals = new double[instance.numValues()];
				int[] indices = new int[instance.numValues()];
				int num = 0;
				for (int j = 0; j < instance.numValues(); j++)
				{
					if (instance.isMissingSparse(j) && (getInputFormat().classIndex() != instance.index(j)) && (instance.attributeSparse(j).Nominal || instance.attributeSparse(j).Numeric))
					{
						if (m_ModesAndMeans[instance.index(j)] != 0.0)
						{
							vals[num] = m_ModesAndMeans[instance.index(j)];
							indices[num] = instance.index(j);
							num++;
						}
					}
					else
					{
						vals[num] = instance.valueSparse(j);
						indices[num] = instance.index(j);
						num++;
					}
				}
				if (num == instance.numValues())
				{
					inst = new SparseInstance(instance.weight(), vals, indices, instance.numAttributes());
				}
				else
				{
					double[] tempVals = new double[num];
					int[] tempInd = new int[num];
					Array.Copy(vals, 0, tempVals, 0, num);
					Array.Copy(indices, 0, tempInd, 0, num);
					inst = new SparseInstance(instance.weight(), tempVals, tempInd, instance.numAttributes());
				}
			}
			else
			{
				double[] vals = new double[getInputFormat().numAttributes()];
				for (int j = 0; j < instance.numAttributes(); j++)
				{
					if (instance.isMissing(j) && (getInputFormat().classIndex() != j) && (getInputFormat().attribute(j).Nominal || getInputFormat().attribute(j).Numeric))
					{
						vals[j] = m_ModesAndMeans[j];
					}
					else
					{
						vals[j] = instance.value_Renamed(j);
					}
				}
				inst = new Instance(instance.weight(), vals);
			}
			inst.Dataset = instance.dataset();
			push(inst);
		}
开发者ID:intille,项目名称:mitessoftware,代码行数:65,代码来源:ReplaceMissingValues.cs

示例3: convertInstance

		/// <summary> Convert a single instance over if the class is nominal. The converted 
		/// instance is added to the end of the output queue.
		/// 
		/// </summary>
		/// <param name="instance">the instance to convert
		/// </param>
		private void  convertInstance(Instance instance)
		{
			
			double[] vals = new double[outputFormatPeek().numAttributes()];
			int attSoFar = 0;
			
			for (int j = 0; j < getInputFormat().numAttributes(); j++)
			{
                weka.core.Attribute att = getInputFormat().attribute(j);
				if (!att.Nominal || (j == getInputFormat().classIndex()) || !m_Columns.isInRange(j))
				{
					vals[attSoFar] = instance.value_Renamed(j);
					attSoFar++;
				}
				else
				{
					if (att.numValues() <= 2)
					{
						vals[attSoFar] = instance.value_Renamed(j);
						attSoFar++;
					}
					else
					{
						if (instance.isMissing(j))
						{
							for (int k = 0; k < att.numValues(); k++)
							{
								vals[attSoFar + k] = instance.value_Renamed(j);
							}
						}
						else
						{
							for (int k = 0; k < att.numValues(); k++)
							{
								//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'"
								if (k == (int) instance.value_Renamed(j))
								{
									vals[attSoFar + k] = 1;
								}
								else
								{
									vals[attSoFar + k] = 0;
								}
							}
						}
						attSoFar += att.numValues();
					}
				}
			}
			Instance inst = null;
			if (instance is SparseInstance)
			{
				inst = new SparseInstance(instance.weight(), vals);
			}
			else
			{
				inst = new Instance(instance.weight(), vals);
			}
			copyStringValues(inst, false, instance.dataset(), InputStringIndex, getOutputFormat(), OutputStringIndex);
			inst.Dataset = getOutputFormat();
			push(inst);
		}
开发者ID:intille,项目名称:mitessoftware,代码行数:68,代码来源:NominalToBinary.cs

示例4: evaluateModelOnce

		/// <summary> Evaluates the classifier on a single instance.
		/// 
		/// </summary>
		/// <param name="classifier">machine learning classifier
		/// </param>
		/// <param name="instance">the test instance to be classified
		/// </param>
		/// <returns> the prediction made by the clasifier
		/// </returns>
		/// <throws>  Exception if model could not be evaluated  </throws>
		/// <summary> successfully or the data contains string attributes
		/// </summary>
		public virtual double evaluateModelOnce(Classifier classifier, Instance instance)
		{
			
			Instance classMissing = (Instance) instance.copy();
			double pred = 0;
			classMissing.Dataset = instance.dataset();
			classMissing.setClassMissing();
			if (m_ClassIsNominal)
			{
				double[] dist = classifier.distributionForInstance(classMissing);
				pred = Utils.maxIndex(dist);
				//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'"
				if (dist[(int) pred] <= 0)
				{
					pred = Instance.missingValue();
				}
				updateStatsForClassifier(dist, instance);
			}
			else
			{
				pred = classifier.classifyInstance(classMissing);
				updateStatsForPredictor(pred, instance);
			}
			return pred;
		}
开发者ID:intille,项目名称:mitessoftware,代码行数:37,代码来源:Evaluation.cs

示例5: readDataTimer_Tick


//.........这里部分代码省略.........
                                Extractor.TrainingTime[current_activity] = (int)Extractor.TrainingTime[current_activity] + 200;//Extractor.Configuration.OverlapTime;// get it from configuration
                                string arffSample = Extractor.toString() + "," + current_activity.Replace(' ', '_');
                                this.tw.WriteLine(arffSample);
                                this.label8.Text = Extractor.DiscardedLossRateWindows.ToString();
                                //this.label10.Text = Extractor.DiscardedConsecutiveLossWindows.ToString();
                            }
                        }
                        else
                        {
                           // this.label5.Text = "TR in " + ((int)(this.startActivityTime - Environment.TickCount) / 1000) + " secs";
                           // this.label11.Text = "Training " + current_activity + " in " + ((int)(this.startActivityTime - Environment.TickCount) / 1000) + " secs";
                        }
                    }
                    else // Manual Training
                    {
                    }
                }




                //Classifying

                if (isClassifying==true)
                {
                    double lastTimeStamp = Extractor.StoreMITesWindow();
                    if (Extractor.GenerateFeatureVector(lastTimeStamp))
                    {
                        Instance newinstance = new Instance(instances.numAttributes());
                        newinstance.Dataset = instances;
                        for (int i = 0; (i < Extractor.Features.Length); i++)
                            newinstance.setValue(instances.attribute(i), Extractor.Features[i]);
                        double predicted = classifier.classifyInstance(newinstance);
                        string predicted_activity = newinstance.dataset().classAttribute().value_Renamed((int)predicted);
                       
                        int currentIndex=(int)labelIndex[predicted_activity];
                        labelCounters[currentIndex] = (int)labelCounters[currentIndex] + 1;                        
                        classificationCounter++;

                        if (classificationCounter == Extractor.Configuration.SmoothWindows)
                        {
                            classificationCounter = 0;
                            int mostCount = 0;
                            string mostActivity = "";
                            for (int j=0;(j<labelCounters.Length);j++)
                            {                                
                                if (labelCounters[j] > mostCount)
                                    mostActivity = activityLabels[j];
                                labelCounters[j] = 0;
                            }

                            this.label6.Text = mostActivity;
                            //this.label11.Text = "Fahd is "+mostActivity;
                        }
                    }
                }


                if (activityCountWindowSize > Extractor.Configuration.QualityWindowSize) //write a line to CSV and initialize
                {
                    DateTime now= DateTime.Now;
                    DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0);
                    TimeSpan diff = now.Subtract(origin);                    
                    string timestamp = diff.TotalMilliseconds + "," + now.ToString("yyyy'-'MM'-'dd' 'HH':'mm':'ssK");
                    string master_csv_line = timestamp;
                    string hr_csv_line = timestamp;
开发者ID:intille,项目名称:mitessoftware,代码行数:67,代码来源:MITesDataCollectionForm.cs

示例6: readDataTimer_Tick


//.........这里部分代码省略.........
                    else
                        this.trainingLabel.Text = "Training " + current_activity + " in " + ((int)(this.startActivityTime - Environment.TickCount) / 1000) + " secs";

                }
                else // Manual Training
                {
                }
            }



            #endregion Train in realtime and generate ARFF File

            #region Classifying activities

#if (PocketPC)
            if (isClassifying == true)
            {
                double lastTimeStamp = Extractor.StoreMITesWindow();
                if ((this.sensors.HasBuiltinSensors) && (polledData != null))
                {
                    //aMITesLoggerPLFormat.SaveRawMITesBuiltinData(polledData);
                    //store it in Extractor Buffers as well
                    lastTimeStamp = Extractor.StoreBuiltinData(polledData);
                }

                if (Extractor.GenerateFeatureVector(lastTimeStamp))
                {
                    Instance newinstance = new Instance(instances.numAttributes());
                    newinstance.Dataset = instances;
                    for (int i = 0; (i < Extractor.Features.Length); i++)
                        newinstance.setValue(instances.attribute(i), Extractor.Features[i]);
                    double predicted = classifier.classifyInstance(newinstance);
                    string predicted_activity = newinstance.dataset().classAttribute().value_Renamed((int)predicted);

                    int currentIndex = (int)labelIndex[predicted_activity];
                    labelCounters[currentIndex] = (int)labelCounters[currentIndex] + 1;
                    classificationCounter++;

                    if (classificationCounter == Extractor.Configuration.SmoothWindows)
                    {
                        classificationCounter = 0;
                        int mostCount = 0;
                        string mostActivity = "";
                        for (int j = 0; (j < labelCounters.Length); j++)
                        {
                            if (labelCounters[j] > mostCount)
                            {
                                mostActivity = activityLabels[j];
                                mostCount = labelCounters[j];
                            }
                            labelCounters[j] = 0;
                        }

                        pieChart.SetActivity(mostActivity);
                        if (this.aList.getEmptyPercent() == 1)
                            this.aList.reset();
                        else
                            this.aList.increment(mostActivity);

                        if (previousActivity != mostActivity)
                        {
                            this.activityTimer.stop();
                            this.activityTimer.reset();
                            currentCalories = 0;
                        }
开发者ID:intille,项目名称:mitessoftware,代码行数:67,代码来源:MITesDataCollectionForm.cs


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