本文整理汇总了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;
}
示例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);
}
示例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);
}
示例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;
}
示例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;
示例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;
}