本文整理汇总了C#中weka.core.Instances.numAttributes方法的典型用法代码示例。如果您正苦于以下问题:C# Instances.numAttributes方法的具体用法?C# Instances.numAttributes怎么用?C# Instances.numAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类weka.core.Instances
的用法示例。
在下文中一共展示了Instances.numAttributes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: Main
public static void Main(string[] args) {
try {
int runs = 1;
string algo = "";
string data = "";
if(args.Length>0) runs = Convert.ToInt32(args[0]);
if(args.Length>1) algo = args[1];
if(args.Length>2) data = args[2];
Stopwatch read = new Stopwatch(),
build = new Stopwatch(),
classify = new Stopwatch();
for (int cnt=0; cnt<runs; cnt++) {
read.Start();
Instances train = new Instances(new java.io.FileReader(data+"train.arff"));
train.setClassIndex(train.numAttributes() - 1);
Instances test = new Instances(new java.io.FileReader(data+"test.arff"));
test.setClassIndex(test.numAttributes() - 1);
read.Stop();
Classifier[] clList = {
new weka.classifiers.bayes.NaiveBayes(),
new weka.classifiers.trees.RandomForest(),
new weka.classifiers.trees.J48(),
new weka.classifiers.functions.MultilayerPerceptron(),
new weka.classifiers.rules.ConjunctiveRule(),
new weka.classifiers.functions.SMO()
};
build.Start();
foreach (Classifier classifier in clList) {
if(algo.Equals("") || algo.Equals("All") || classifier.getClass().getSimpleName().Equals(algo))
classifier.buildClassifier(train);
}
build.Stop();
classify.Start();
foreach (Classifier classifier in clList) {
if(algo.Equals("") || algo.Equals("All") || classifier.getClass().getSimpleName().Equals(algo)) {
int numCorrect = 0;
for (int i = 0; i < test.numInstances(); i++)
{
if (classifier.classifyInstance(test.instance(i)) == test.instance(i).classValue())
numCorrect++;
}
//Console.Write(classifier.getClass().getSimpleName() + "\t" + numCorrect + " out of " + test.numInstances() + " correct (" +(100.0 * numCorrect / test.numInstances()) + "%)");
}
}
classify.Stop();
}
Console.WriteLine("{\""+ algo + "\"," + read.ElapsedMilliseconds + "," + build.ElapsedMilliseconds + "," + classify.ElapsedMilliseconds + "," + (read.ElapsedMilliseconds+build.ElapsedMilliseconds+classify.ElapsedMilliseconds)+"};");
if(args.Length>3) Console.ReadLine();
} catch (java.lang.Exception e){
e.printStackTrace();
}
}
示例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)
{
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");
}
示例4: 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;
}
示例5: InitializeClassifier
/* Use when the player logs in to initially create the classifier with data from server */
public void InitializeClassifier(String dataString)
{
try {
java.io.StringReader stringReader = new java.io.StringReader(dataString);
java.io.BufferedReader buffReader = new java.io.BufferedReader(stringReader);
playerData = new weka.core.Instances(buffReader);
/* State where in each Instance the class attribute is, if its not already specified by the file */
if (playerData.classIndex() == -1)
playerData.setClassIndex(playerData.numAttributes() - 1);
/* NAIVE BAYES */
//classifier = new weka.classifiers.bayes.NaiveBayes();
/* NEURAL NET */
//classifier = new weka.classifiers.functions.MultilayerPerceptron();
//((weka.classifiers.functions.MultilayerPerceptron)classifier).setHiddenLayers("12");
/* J48 TREE */
//classifier = new weka.classifiers.trees.J48();
/* IB1 NEAREST NEIGHBOUR */
//classifier = new weka.classifiers.lazy.IB1();
/* RANDOM FOREST */
classifier = new weka.classifiers.trees.RandomForest();
classifier.buildClassifier(playerData);
Debug.Log("Initialized Classifier");
}
catch (java.lang.Exception ex)
{
Debug.LogError(ex.getMessage());
}
}
示例6: mergeInstances
/// <summary> Merges two sets of Instances together. The resulting set will have
/// all the attributes of the first set plus all the attributes of the
/// second set. The number of instances in both sets must be the same.
///
/// </summary>
/// <param name="first">the first set of Instances
/// </param>
/// <param name="second">the second set of Instances
/// </param>
/// <returns> the merged set of Instances
/// </returns>
/// <exception cref="IllegalArgumentException">if the datasets are not the same size
/// </exception>
public static Instances mergeInstances(Instances first, Instances second)
{
if (first.numInstances() != second.numInstances())
{
throw new System.ArgumentException("Instance sets must be of the same size");
}
// Create the vector of merged attributes
FastVector newAttributes = new FastVector();
for (int i = 0; i < first.numAttributes(); i++)
{
newAttributes.addElement(first.attribute(i));
}
for (int i = 0; i < second.numAttributes(); i++)
{
newAttributes.addElement(second.attribute(i));
}
// Create the set of Instances
Instances merged = new Instances(first.relationName() + '_' + second.relationName(), newAttributes, first.numInstances());
// Merge each instance
for (int i = 0; i < first.numInstances(); i++)
{
merged.add(first.instance(i).mergeInstance(second.instance(i)));
}
return merged;
}
示例7: 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();
}
示例8: evaluateModel
//.........这里部分代码省略.........
{
//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);
}
if (objectInputFileName.Length != 0)
{
//UPGRADE_TODO: Constructor 'java.io.FileInputStream.FileInputStream' 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_javaioFileInputStreamFileInputStream_javalangString'"
objectStream= new System.IO.FileStream(objectInputFileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
if (objectInputFileName.EndsWith(".gz"))
{
//UPGRADE_ISSUE: Constructor 'java.util.zip.GZIPInputStream.GZIPInputStream' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javautilzipGZIPInputStream'"
objectStream= new ICSharpCode.SharpZipLib.GZip.GZipInputStream(objectStream);
}
//UPGRADE_TODO: Class 'java.io.ObjectInputStream' was converted to 'System.IO.BinaryReader' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioObjectInputStream'"
objectInputStream = new System.IO.BinaryReader(objectStream);
}
}
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 + '.');
}
if (testFileName.Length != 0)
{
template = test = new Instances(testReader, 1);
if (classIndex != - 1)
{
test.ClassIndex = classIndex - 1;
}
else
{
test.ClassIndex = test.numAttributes() - 1;
}
if (classIndex > test.numAttributes())
{
throw new System.Exception("Index of class attribute too large.");
}
}
if (trainFileName.Length != 0)
{
if ((classifier is UpdateableClassifier) && (testFileName.Length != 0))
{
train = new Instances(trainReader, 1);
}
else
{
train = new Instances(trainReader);
}
template = train;
if (classIndex != - 1)
{
train.ClassIndex = classIndex - 1;
}
else
{
train.ClassIndex = train.numAttributes() - 1;
}
if ((testFileName.Length != 0) && !test.equalHeaders(train))
{
throw new System.ArgumentException("Train and test file not compatible!");
}
if (classIndex > train.numAttributes())
{
throw new System.Exception("Index of class attribute too large.");
示例9: loadLabelsMeta
private LabelsMetaData loadLabelsMeta(Instances data, int numLabels)
{
LabelsMetaDataImpl labelsData = new LabelsMetaDataImpl();
int numAttributes = data.numAttributes();
for (int index = numAttributes - numLabels; index < numAttributes; index++) {
String attrName = data.attribute(index).name();
labelsData.addRootNode(new LabelNodeImpl(attrName));
}
return labelsData;
}
示例10: CreateInstancesWithClasses
/// <summary>
/// Create an instances structure with classes for supervised methods
/// </summary>
/// <param name="NumClass"></param>
/// <returns></returns>
public Instances CreateInstancesWithClasses(cInfoClass InfoClass, int NeutralClass)
{
weka.core.FastVector atts = new FastVector();
int columnNo = 0;
for (int i = 0; i < ParentScreening.ListDescriptors.Count; i++)
{
if (ParentScreening.ListDescriptors[i].IsActive() == false) continue;
atts.addElement(new weka.core.Attribute(ParentScreening.ListDescriptors[i].GetName()));
columnNo++;
}
weka.core.FastVector attVals = new FastVector();
for (int i = 0; i < InfoClass.NumberOfClass; i++)
attVals.addElement("Class__" + (i).ToString());
atts.addElement(new weka.core.Attribute("Class__", attVals));
Instances data1 = new Instances("MyRelation", atts, 0);
int IdxWell = 0;
foreach (cWell CurrentWell in this.ListActiveWells)
{
if (CurrentWell.GetCurrentClassIdx() == NeutralClass) continue;
double[] vals = new double[data1.numAttributes()];
int IdxCol = 0;
for (int Col = 0; Col < ParentScreening.ListDescriptors.Count; Col++)
{
if (ParentScreening.ListDescriptors[Col].IsActive() == false) continue;
vals[IdxCol++] = CurrentWell.ListSignatures[Col].GetValue();
}
vals[columnNo] = InfoClass.CorrespondanceTable[CurrentWell.GetCurrentClassIdx()];
data1.add(new DenseInstance(1.0, vals));
IdxWell++;
}
data1.setClassIndex((data1.numAttributes() - 1));
return data1;
}
示例11: EvaluteAndDisplayClusterer
/// <summary>
/// Evalute and display a WEKA clusterer
/// </summary>
/// <param name="SelectedClusterer">weka clusterer</param>
/// <param name="InstancesList">list of instances for the validation</param>
/// <param name="RichTextBoxToDisplayResults">Text box for the results (can be NULL)</param>
/// <param name="PanelTodisplayGraphicalResults">Panel to display visual results if avalaible (can be NULL)</param>
/// <returns></returns>
public ClusterEvaluation EvaluteAndDisplayClusterer(RichTextBox RichTextBoxToDisplayResults,
Panel PanelTodisplayGraphicalResults, Instances ListInstanceForValid)
{
ClusterEvaluation eval = new ClusterEvaluation();
eval.setClusterer(SelectedClusterer);
eval.evaluateClusterer(ListInstanceForValid);
if (RichTextBoxToDisplayResults != null)
{
if ((RichTextBoxToDisplayResults != null) && (eval.getNumClusters() > cGlobalInfo.ListCellularPhenotypes.Count))
{
RichTextBoxToDisplayResults.Clear();
RichTextBoxToDisplayResults.AppendText("Error: " + eval.getNumClusters() + " clusters identifed.");
RichTextBoxToDisplayResults.AppendText("The maximum number of cluster is " + cGlobalInfo.ListCellularPhenotypes.Count + ".");
return null;
}
if (RichTextBoxToDisplayResults != null)
{
RichTextBoxToDisplayResults.Clear();
RichTextBoxToDisplayResults.AppendText(eval.clusterResultsToString());
}
RichTextBoxToDisplayResults.AppendText("\n" + ListInstanceForValid.numAttributes() + " attributes:\n\n");
for (int IdxAttributes = 0; IdxAttributes < ListInstanceForValid.numAttributes(); IdxAttributes++)
{
RichTextBoxToDisplayResults.AppendText(IdxAttributes + "\t: " + ListInstanceForValid.attribute(IdxAttributes).name() + "\n");
}
}
if (PanelTodisplayGraphicalResults != null) PanelTodisplayGraphicalResults.Controls.Clear();
if ((PanelTodisplayGraphicalResults != null) && (SelectedClusterer.GetType().Name == "HierarchicalClusterer"))
{
Button ButtonToDisplayHierarchicalClustering = new Button();
ButtonToDisplayHierarchicalClustering.Text = "Display Hierarchical Tree";
ButtonToDisplayHierarchicalClustering.Width *= 2;
ButtonToDisplayHierarchicalClustering.Location = new System.Drawing.Point((PanelTodisplayGraphicalResults.Width - ButtonToDisplayHierarchicalClustering.Width) / 2,
(PanelTodisplayGraphicalResults.Height - ButtonToDisplayHierarchicalClustering.Height) / 2);
ButtonToDisplayHierarchicalClustering.Anchor = AnchorStyles.None;
ButtonToDisplayHierarchicalClustering.Click += new EventHandler(ClickToDisplayHierarchicalTree);
PanelTodisplayGraphicalResults.Controls.Add(ButtonToDisplayHierarchicalClustering);
}
return eval;
}
示例12: CreateInstanceForNClasses
/// <summary>
/// Create a single instance for WEKA
/// </summary>
/// <param name="NClasses">Number of classes</param>
/// <returns>the weka instances</returns>
public Instances CreateInstanceForNClasses(cInfoClass InfoClass)
{
List<double> AverageList = new List<double>();
for (int i = 0; i < Parent.ListDescriptors.Count; i++)
if (Parent.ListDescriptors[i].IsActive()) AverageList.Add(GetAverageValuesList()[i]);
weka.core.FastVector atts = new FastVector();
List<string> NameList = Parent.ListDescriptors.GetListNameActives();
for (int i = 0; i < NameList.Count; i++)
atts.addElement(new weka.core.Attribute(NameList[i]));
weka.core.FastVector attVals = new FastVector();
for (int i = 0; i < InfoClass.NumberOfClass; i++)
attVals.addElement("Class" + i);
atts.addElement(new weka.core.Attribute("Class__", attVals));
Instances data1 = new Instances("SingleInstance", atts, 0);
double[] newTable = new double[AverageList.Count + 1];
Array.Copy(AverageList.ToArray(), 0, newTable, 0, AverageList.Count);
//newTable[AverageList.Count] = 1;
data1.add(new DenseInstance(1.0, newTable));
data1.setClassIndex((data1.numAttributes() - 1));
return data1;
}
示例13: setInputFormat
// ---- OPERATIONS ----
///
/// <summary> * Sets the format of the input instances. If the filter is able to
/// * determine the output format before seeing any input instances, it
/// * does so here. This default implementation clears the output format
/// * and output queue, and the new batch flag is set. Overriders should
/// * call <code>super.setInputFormat(Instances)</code>
/// * </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>
///
//JAVA TO VB & C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public boolean setInputFormat(Instances instanceInfo) throws Exception
public override bool setInputFormat(Instances instanceInfo)
{
base.setInputFormat(instanceInfo);
for (int i = 0; i < instanceInfo.numAttributes(); ++i)
{
if (!instanceInfo.attribute(i).isNumeric())
{
throw new UnsupportedAttributeTypeException("All attributes must be numeric");
}
}
// Create the output buffer
setOutputFormat();
return true;
}
示例14: CreateInstancesWithoutClass
public Instances CreateInstancesWithoutClass(cExtendedTable Input)
{
weka.core.FastVector atts = new FastVector();
int columnNo = 0;
// Descriptors loop
for (int i = 0; i < Input.Count; i++)
{
//if (ParentScreening.ListDescriptors[i].IsActive() == false) continue;
atts.addElement(new weka.core.Attribute(Input[i].Name));
columnNo++;
}
// weka.core.FastVector attVals = new FastVector();
Instances data1 = new Instances("MyRelation", atts, 0);
for (int IdxRow = 0; IdxRow < Input[0].Count; IdxRow++)
{
double[] vals = new double[data1.numAttributes()];
for (int Col = 0; Col < columnNo; Col++)
{
// if (Glo .ListDescriptors[Col].IsActive() == false) continue;
vals[Col] = Input[Col][IdxRow];// double.Parse(dt.Rows[IdxRow][Col].ToString());
}
data1.add(new DenseInstance(1.0, vals));
}
return data1;
}
示例15: CreateInstancesWithoutClass
/// <summary>
/// Create an instances structure without classes for unsupervised methods
/// </summary>
/// <returns>a weka Instances object</returns>
public Instances CreateInstancesWithoutClass()
{
weka.core.FastVector atts = new FastVector();
int columnNo = 0;
// Descriptors loop
for (int i = 0; i < ParentScreening.ListDescriptors.Count; i++)
{
if (ParentScreening.ListDescriptors[i].IsActive() == false) continue;
atts.addElement(new weka.core.Attribute(ParentScreening.ListDescriptors[i].GetName()));
columnNo++;
}
weka.core.FastVector attVals = new FastVector();
Instances data1 = new Instances("MyRelation", atts, 0);
foreach (cWell CurrentWell in this.ListActiveWells)
{
double[] vals = new double[data1.numAttributes()];
int IdxRealCol = 0;
for (int Col = 0; Col < ParentScreening.ListDescriptors.Count; Col++)
{
if (ParentScreening.ListDescriptors[Col].IsActive() == false) continue;
vals[IdxRealCol++] = CurrentWell.ListSignatures[Col].GetValue();
}
data1.add(new DenseInstance(1.0, vals));
}
return data1;
}