本文整理汇总了C#中weka.core.Instances.delete方法的典型用法代码示例。如果您正苦于以下问题:C# Instances.delete方法的具体用法?C# Instances.delete怎么用?C# Instances.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类weka.core.Instances
的用法示例。
在下文中一共展示了Instances.delete方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: toPrintClassifications
/// <summary> Prints the predictions for the given dataset into a String variable.
///
/// </summary>
/// <param name="classifier the">classifier to use
/// </param>
/// <param name="train the">training data
/// </param>
/// <param name="testFileName the">name of the test file
/// </param>
/// <param name="classIndex the">class index
/// </param>
/// <param name="attributesToOutput the">indices of the attributes to output
/// </param>
/// <returns> the generated predictions for the attribute range
/// </returns>
/// <throws> Exception if test file cannot be opened </throws>
protected internal static System.String toPrintClassifications(Classifier classifier, Instances train, System.String testFileName, int classIndex, Range attributesToOutput)
{
System.Text.StringBuilder text = new System.Text.StringBuilder();
if (testFileName.Length != 0)
{
System.IO.StreamReader testReader = null;
try
{
//UPGRADE_TODO: The differences in the expected value of parameters for constructor 'java.io.BufferedReader.BufferedReader' may cause compilation errors. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'"
//UPGRADE_WARNING: At least one expression was used more than once in the target code. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1181'"
//UPGRADE_TODO: Constructor 'java.io.FileReader.FileReader' was converted to 'System.IO.StreamReader' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'"
testReader = new System.IO.StreamReader(new System.IO.StreamReader(testFileName, System.Text.Encoding.Default).BaseStream, new System.IO.StreamReader(testFileName, System.Text.Encoding.Default).CurrentEncoding);
}
catch (System.Exception e)
{
//UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
throw new System.Exception("Can't open file " + e.Message + '.');
}
Instances test = new Instances(testReader, 1);
if (classIndex != - 1)
{
test.ClassIndex = classIndex - 1;
}
else
{
test.ClassIndex = test.numAttributes() - 1;
}
int i = 0;
while (test.readInstance(testReader))
{
Instance instance = test.instance(0);
Instance withMissing = (Instance) instance.copy();
withMissing.Dataset = test;
double predValue = ((Classifier) classifier).classifyInstance(withMissing);
if (test.classAttribute().Numeric)
{
if (Instance.isMissingValue(predValue))
{
text.Append(i + " missing ");
}
else
{
text.Append(i + " " + predValue + " ");
}
if (instance.classIsMissing())
{
text.Append("missing");
}
else
{
text.Append(instance.classValue());
}
text.Append(" " + attributeValuesString(withMissing, attributesToOutput) + "\n");
}
else
{
if (Instance.isMissingValue(predValue))
{
text.Append(i + " missing ");
}
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'"
text.Append(i + " " + test.classAttribute().value_Renamed((int) predValue) + " ");
}
if (Instance.isMissingValue(predValue))
{
text.Append("missing ");
}
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'"
text.Append(classifier.distributionForInstance(withMissing)[(int) predValue] + " ");
}
text.Append(instance.toString(instance.classIndex()) + " " + attributeValuesString(withMissing, attributesToOutput) + "\n");
}
test.delete(0);
i++;
}
testReader.Close();
}
return text.ToString();
}
示例2: evaluateModel
//.........这里部分代码省略.........
throw;
}
finally
{
objectStream.Close();
//fs.Close();
}
objectInputStream.Close();
}
// backup of fully setup classifier for cross-validation
classifierBackup = Classifier.makeCopy(classifier);
// Build the classifier if no object file provided
if ((classifier is UpdateableClassifier) && (testFileName.Length != 0) && (costMatrix == null) && (trainFileName.Length != 0))
{
// Build classifier incrementally
trainingEvaluation.Priors = train;
testingEvaluation.Priors = train;
trainTimeStart = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;
if (objectInputFileName.Length == 0)
{
classifier.buildClassifier(train);
}
while (train.readInstance(trainReader))
{
trainingEvaluation.updatePriors(train.instance(0));
testingEvaluation.updatePriors(train.instance(0));
((UpdateableClassifier) classifier).updateClassifier(train.instance(0));
train.delete(0);
}
trainTimeElapsed = (System.DateTime.Now.Ticks - 621355968000000000) / 10000 - trainTimeStart;
trainReader.Close();
}
else if (objectInputFileName.Length == 0)
{
// Build classifier in one go
tempTrain = new Instances(train);
trainingEvaluation.Priors = tempTrain;
testingEvaluation.Priors = tempTrain;
trainTimeStart = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;
classifier.buildClassifier(tempTrain);
trainTimeElapsed = (System.DateTime.Now.Ticks - 621355968000000000) / 10000 - trainTimeStart;
}
// Save the classifier if an object output file is provided
if (objectOutputFileName.Length != 0)
{
//UPGRADE_TODO: Constructor 'java.io.FileOutputStream.FileOutputStream' was converted to 'System.IO.FileStream.FileStream' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioFileOutputStreamFileOutputStream_javalangString'"
System.IO.Stream os = new System.IO.FileStream(objectOutputFileName, System.IO.FileMode.Create);
if (objectOutputFileName.EndsWith(".gz"))
{
//UPGRADE_ISSUE: Constructor 'java.util.zip.GZIPOutputStream.GZIPOutputStream' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javautilzipGZIPOutputStream'"
os = new ICSharpCode.SharpZipLib.GZip.GZipOutputStream(os);
}
//UPGRADE_TODO: Class 'java.io.ObjectOutputStream' was converted to 'System.IO.BinaryWriter' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioObjectOutputStream'"
System.IO.BinaryWriter objectOutputStream = new System.IO.BinaryWriter(os);
//UPGRADE_TODO: Method 'java.io.ObjectOutputStream.writeObject' was converted to 'SupportClass.Serialize' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioObjectOutputStreamwriteObject_javalangObject'"
//SupportClass.Serialize(objectOutputStream, classifier);
BinaryFormatter bformatter = new BinaryFormatter();
示例3: 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)
{
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 thisData = new weka.core.Instances(buffReader); //source.getDataSet();
if (thisData.classIndex() == -1)
thisData.setClassIndex(thisData.numAttributes() - 1);
weka.core.Instances thisUniqueData = new weka.core.Instances(thisData);
if (thisUniqueData.classIndex() == -1)
thisUniqueData.setClassIndex(thisUniqueData.numAttributes() - 1);
thisUniqueData.delete();
if (allUniqueData == null) {
allUniqueData = new weka.core.Instances(thisData);
if (allUniqueData.classIndex() == -1)
allUniqueData.setClassIndex(allUniqueData.numAttributes() - 1);
allUniqueData.delete();
}
weka.core.InstanceComparator com = new weka.core.InstanceComparator(false);
for (int i = 0; i < thisData.numInstances(); i++)
{
bool dup = false;
for (int j = 0; j < allUniqueData.numInstances(); j++)
{
if (com.compare(thisData.instance(i),allUniqueData.instance(j)) == 0)
{
Debug.Log("Duplicate found!");
dup = true;
break;
}
}
if (!dup)
allUniqueData.add(thisData.instance(i));
else
dupInstances++;
}
for (int i = 0; i < thisData.numInstances(); i++)
{
bool dup = false;
for (int j = 0; j < thisUniqueData.numInstances(); j++)
{
if (com.compare(thisData.instance(i),thisUniqueData.instance(j)) == 0)
{
Debug.Log("Duplicate found!");
dup = true;
break;
}
}
if (!dup)
thisUniqueData.add(thisData.instance(i));
else
dupInstancesSamePlayer++;
}
//Debug.Log("All Data Instance Count = " + thisData.numInstances());
//Debug.Log("Unique Data Instance Count = " + thisUniqueData.numInstances());
//Debug.Log("Done!");
} catch (java.lang.Exception ex)
{
Debug.LogError(ex.getMessage());
}
}