本文整理汇总了C#中weka.core.Instances类的典型用法代码示例。如果您正苦于以下问题:C# Instances类的具体用法?C# Instances怎么用?C# Instances使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Instances类属于weka.core命名空间,在下文中一共展示了Instances类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Classify
public static string Classify(bool useRubine, float duration, bool righthandedness, List<float> SpeakerAngles, PointCollection pointHist, StylusPointCollection S, List<List<int>> hist, List<List<int>> ihist)
{
// Convert all parameters to format used in GestureTests
List<Vector2> InterpretedPoints = new List<Vector2>();
List<Vector2> StylusPoints = new List<Vector2>();
List<Vector2> VelocityHistory = new List<Vector2>();
List<Vector2> InverseVelocityHistory = new List<Vector2>();
foreach(Point P in pointHist)
InterpretedPoints.Add(new Vector2((float)P.X,(float)P.Y));
foreach(StylusPoint P in S)
StylusPoints.Add(new Vector2((float)P.X,(float)P.Y));
for (int i = 0; i < hist[0].Count; i++)
{
VelocityHistory.Add(new Vector2(hist[0][i], hist[1][i]));
InverseVelocityHistory.Add(new Vector2(ihist[0][i], ihist[1][i]));
}
// Create a new Sample, compute the features, and classify
GS = new GestureSample(GestureTests.Types.GestureType.unknown, righthandedness,duration,SpeakerAngles,InterpretedPoints,StylusPoints,VelocityHistory,InverseVelocityHistory);
GS.ComputeFeatures(GestureFeatures.PointsStroke);
if (useRubine)
return EC.Recognizer.Classify(GS).ToString();
WriteARFF();
Instances test = new Instances(new java.io.FileReader("outfile.arff"));
test.setClassIndex(0);
double clsLabel = cls.classifyInstance(test.instance(0));
test.instance(0).setClassValue(clsLabel);
// Return the appropriate label
return ((GestureType2D)((int)clsLabel+1)).ToString();
}
示例2: EndTrainingSession
public void EndTrainingSession()
{
Stream s = new MemoryStream ();
TextWriter tw = new StreamWriter (s);
AbstractBasicTextVector.WriteInstancesArff (tw, vectors, "c45recommender", tags, results);
tw.Flush ();
s.Position = 0;
Instances source = new Instances (new InputStreamReader (new InputStreamWrapper (s)));
tw.Close ();
s.Close ();
Instances[] derived = new Instances[this.not];
classifiers = new AbstractClassifier[this.not];
int[] args = new int[this.not - 1];
int l = source.numAttributes () - this.not;
for (int i = 0; i < this.not-1; i++) {
args [i] = i + l + 1;
}
for (int i = 0; i < this.not; i++) {
Remove rem = new Remove ();
rem.setAttributeIndicesArray (args);
rem.setInputFormat (source);
derived [i] = Filter.useFilter (source, rem);
classifiers [i] = GenerateClassifier ();
derived [i].setClassIndex (derived [i].numAttributes () - 1);
classifiers [i].buildClassifier (derived [i]);
if (i < this.not - 1) {
args [i] = l + i;
}
}
datasets = derived;
}
示例3: setInputFormat
/// <summary> Sets the format of the input instances.
///
/// </summary>
/// <param name="instanceInfo">an Instances object containing the input instance
/// structure (any instances contained in the object are ignored - only the
/// structure is required).
/// </param>
/// <returns> true if the outputFormat may be collected immediately
/// </returns>
/// <exception cref="Exception">if the inputFormat can't be set successfully
/// </exception>
public override bool setInputFormat(Instances instanceInfo)
{
base.setInputFormat(instanceInfo);
m_removeFilter = null;
return false;
}
示例4: EvaluateIncrementalBatches
public void EvaluateIncrementalBatches(int batchSize)
{
//Randomize Filter
Randomize randomizeFilter = new Randomize();
randomizeFilter.setInputFormat(this.data);
//RemoveRange Filter
//number of classes
int numClasses = this.data.attribute(this.data.numAttributes() - 1).numValues();
Instances[] classInstances = new Instances[numClasses];
for (int i = 1; (i <= numClasses); i++)
{
//RemoveWithValues Filter
RemoveWithValues removeValuesFilter = new RemoveWithValues();
removeValuesFilter.setInputFormat(this.data);
// removeValuesFilter.set_AttributeIndex("last");
// removeValuesFilter.
removeValuesFilter.set_MatchMissingValues(false);
removeValuesFilter.set_NominalIndices("1-1");
classInstances[i] = Filter.useFilter(this.data, removeValuesFilter);
}
}
示例5: buildClassifier
/// <summary> Generates the classifier.
///
/// </summary>
/// <param name="instances">set of instances serving as training data
/// </param>
/// <exception cref="Exception">if the classifier has not been generated successfully
/// </exception>
public override void buildClassifier(Instances instances)
{
double sumOfWeights = 0;
m_Class = instances.classAttribute();
m_ClassValue = 0;
switch (instances.classAttribute().type())
{
case weka.core.Attribute.NUMERIC:
m_Counts = null;
break;
case weka.core.Attribute.NOMINAL:
m_Counts = new double[instances.numClasses()];
for (int i = 0; i < m_Counts.Length; i++)
{
m_Counts[i] = 1;
}
sumOfWeights = instances.numClasses();
break;
default:
throw new System.Exception("ZeroR can only handle nominal and numeric class" + " attributes.");
}
System.Collections.IEnumerator enu = instances.enumerateInstances();
//UPGRADE_TODO: Method 'java.util.Enumeration.hasMoreElements' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilEnumerationhasMoreElements'"
while (enu.MoveNext())
{
//UPGRADE_TODO: Method 'java.util.Enumeration.nextElement' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilEnumerationnextElement'"
Instance instance = (Instance) enu.Current;
if (!instance.classIsMissing())
{
if (instances.classAttribute().Nominal)
{
//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'"
m_Counts[(int) instance.classValue()] += instance.weight();
}
else
{
m_ClassValue += instance.weight() * instance.classValue();
}
sumOfWeights += instance.weight();
}
}
if (instances.classAttribute().Numeric)
{
if (Utils.gr(sumOfWeights, 0))
{
m_ClassValue /= sumOfWeights;
}
}
else
{
m_ClassValue = Utils.maxIndex(m_Counts);
Utils.normalize(m_Counts, sumOfWeights);
}
}
示例6: Build
public void Build()
{
this.featureIndex = new int[this.features.Count];
for(int i=0;(i< this.features.Count);i++)
{
for (int j = 0; (j < Extractor.ArffAttributeLabels.Length); j++)
if (((string)this.features[i]).Equals(Extractor.ArffAttributeLabels[j]))
{
this.featureIndex[i] = j;
break;
}
}
instances = new Instances(new StreamReader(this.filename));
instances.Class = instances.attribute(this.features.Count);
classifier = new J48();
classifier.buildClassifier(instances);
//setup the feature vector
//fvWekaAttributes = new FastVector(this.features.Count + 1);
//for (i = 0; (i < this.features.Count); i++)
// fvWekaAttributes.addElement(new weka.core.Attribute(this.features[i]));
//Setup the class attribute
//FastVector fvClassVal = new FastVector();
//for (i = 0; (i < this.classes.Count); i++)
// fvClassVal.addElement(this.classes[i]);
//weka.core.Attribute ClassAttribute = new weka.core.Attribute("activity", fvClassVal);
}
示例7: setInputFormat
/// <summary> Sets the format of the input instances.
///
/// </summary>
/// <param name="instanceInfo">an Instances object containing the input
/// instance structure (any instances contained in the object are
/// ignored - only the structure is required).
/// </param>
/// <returns> true if the outputFormat may be collected immediately
/// </returns>
/// <exception cref="Exception">if the input format can't be set
/// successfully
/// </exception>
public virtual bool setInputFormat(Instances instanceInfo)
{
base.setInputFormat(instanceInfo);
setOutputFormat(instanceInfo);
m_ModesAndMeans = null;
return true;
}
示例8: parse
public ArffStore parse()
{
ArffStore arffStore = new ArffStore();
instances = new Instances(new StreamReader(this.filename));
//foreach (weka.core.Attribute attribute in instances.enumerateAttributes())
// arffStore.Features.Add(attribute.name);
return arffStore;
}
示例9: setInputFormat
/// <summary> Sets the format of the input instances.
///
/// </summary>
/// <param name="instanceInfo">an Instances object containing the input
/// instance structure (any instances contained in the object are
/// ignored - only the structure is required).
/// </param>
/// <returns> true if the outputFormat may be collected immediately
/// </returns>
/// <exception cref="Exception">if the input format can't be set
/// successfully
/// </exception>
public override bool setInputFormat(Instances instanceInfo)
{
base.setInputFormat(instanceInfo);
m_Columns.Upper = instanceInfo.numAttributes() - 1;
setOutputFormat();
m_Indices = null;
return true;
}
示例10: classifyTest
// Test the classification result of each map that a user played,
// with the data available as if they were playing through it
public static void classifyTest(String dataString, String playerID)
{
String results = "";
try {
java.io.StringReader stringReader = new java.io.StringReader(dataString);
java.io.BufferedReader buffReader = new java.io.BufferedReader(stringReader);
/* NOTE THAT FOR NAIVE BAYES ALL WEIGHTS CAN BE = 1*/
//weka.core.converters.ConverterUtils.DataSource source = new weka.core.converters.ConverterUtils.DataSource("iris.arff");
weka.core.Instances data = new weka.core.Instances(buffReader); //source.getDataSet();
// setting class attribute if the data format does not provide this information
// For example, the XRFF format saves the class attribute information as well
if (data.classIndex() == -1)
data.setClassIndex(data.numAttributes() - 1);
weka.classifiers.Classifier cl;
for (int i = 3; i < data.numInstances(); i++) {
cl = new weka.classifiers.bayes.NaiveBayes();
//cl = new weka.classifiers.trees.J48();
//cl = new weka.classifiers.lazy.IB1();
//cl = new weka.classifiers.functions.MultilayerPerceptron();
((weka.classifiers.functions.MultilayerPerceptron)cl).setHiddenLayers("12");
weka.core.Instances subset = new weka.core.Instances(data,0,i);
cl.buildClassifier(subset);
weka.classifiers.Evaluation eval = new weka.classifiers.Evaluation(subset);
eval.crossValidateModel(cl, subset, 3, new java.util.Random(1));
results = results + eval.pctCorrect(); // For accuracy measurement
/* For Mathews Correlation Coefficient */
//double TP = eval.numTruePositives(1);
//double FP = eval.numFalsePositives(1);
//double TN = eval.numTrueNegatives(1);
//double FN = eval.numFalseNegatives(1);
//double correlationCoeff = ((TP*TN)-(FP*FN))/Math.Sqrt((TP+FP)*(TP+FN)*(TN+FP)*(TN+FN));
//results = results + correlationCoeff;
if (i != data.numInstances()-1)
results = results + ", ";
if(i == data.numInstances()-1)
Debug.Log("Player: " + playerID + ", Num Maps: " + data.numInstances() + ", AUC: " + eval.areaUnderROC(1));
}
} catch (java.lang.Exception ex)
{
Debug.LogError(ex.getMessage());
}
// Write values to file for a matlab read
// For accuracy
StreamWriter writer = new StreamWriter("DataForMatlab/"+playerID+"_CrossFoldValidations_NeuralNet.txt");
//StreamWriter writer = new StreamWriter("DataForMatlab/"+playerID+"_CrossFoldCorrCoeff.txt"); // For mathews cc
writer.WriteLine(results);
writer.Close();
Debug.Log(playerID + " has been written to file");
}
示例11: BinC45ModelSelection
public BinC45ModelSelection(XmlNode model,Instances allData)
{
foreach (XmlAttribute xAttribute in model.Attributes)
{
if (xAttribute.Name == Constants.MIN_NO_OBJ_ATTRIBUTE)
this.m_minNoObj = Convert.ToInt32(xAttribute.Value);
}
m_allData = allData;
}
示例12: Evaluator
public Evaluator(string arffFile)
{
this.data = new Instances(new StreamReader(arffFile));
this.data.ClassIndex = this.data.numAttributes() - 1;
this.numExamples = this.data.m_Instances.size();
this.classCount = this.data.attribute(this.data.numAttributes() - 1).numValues();
// this.trainingSizeMatrix=new double[
}
示例13: VectorClassif
public VectorClassif(int nbTags)
{
tagsNb = nbTags;
ArrayList nomi = new ArrayList();
nomi.add("0");
nomi.add("1");
ArrayList attr = new ArrayList();
weka.core.Attribute stringAttr = new weka.core.Attribute("todoString", (List)null);
attr.add(stringAttr);
for (int i = 1; i <= nbTags; i++) {
attr.add(new weka.core.Attribute("label" + i, nomi));
}
oDataSet = new Instances("Todo-Instances", attr, 500);
}
示例14: EndTrainingSession
public void EndTrainingSession()
{
Console.WriteLine("End");
stv = new StringToWordVector();
stv.setAttributeNamePrefix("#");
stv.setLowerCaseTokens(true);
stv.setOutputWordCounts(true);
stv.setInputFormat(oDataSet);
stv.setStemmer(new weka.core.stemmers.LovinsStemmer());
stv.setIDFTransform(true);
dataSet = Filter.useFilter(oDataSet, stv);
MultiLabelInstances mli = new MultiLabelInstances(dataSet, loadLabelsMeta(dataSet, tagsNb));
BinaryRelevance br = new mulan.classifier.transformation.BinaryRelevance(new NaiveBayes());
lps = new mulan.classifier.meta.RAkEL(br);
br.setDebug(true);
lps.setDebug(true);
lps.build(mli);
}
示例15: Distribution
/// <summary> Creates a distribution with only one bag according
/// to instances in source.
///
/// </summary>
/// <exception cref="Exception">if something goes wrong
/// </exception>
public Distribution(Instances source)
{
m_perClassPerBag = new double[1][];
for (int i = 0; i < 1; i++)
{
m_perClassPerBag[i] = new double[0];
}
m_perBag = new double[1];
totaL = 0;
m_perClass = new double[source.numClasses()];
m_perClassPerBag[0] = new double[source.numClasses()];
System.Collections.IEnumerator enu = source.enumerateInstances();
//UPGRADE_TODO: Method 'java.util.Enumeration.hasMoreElements' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilEnumerationhasMoreElements'"
while (enu.MoveNext())
{
//UPGRADE_TODO: Method 'java.util.Enumeration.nextElement' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilEnumerationnextElement'"
add(0, (Instance) enu.Current);
}
}