コード例 #1
0
        private static Data.Example ParseExampleLine(int exampleIndex, string line, Data.Dataset dataset)
        {
            string[] parts = line.Split(',');
            List<double> values = new List<double>();
            int label = dataset.Metadata.Target.GetIndex(parts[parts.Length - 1]);

            for (int index = 0; index < parts.Length - 1; index++)
            {
                if (dataset.Metadata.Attributes[index] is Data.NominalAttribute)
                {
                    Data.NominalAttribute attribute = dataset.Metadata.Attributes[index] as Data.NominalAttribute;
                    string value = parts[index];
                    values.Add(attribute.GetIndex(value));
                }
                else
                {
                    double value = double.NaN;
                    if (parts[index] != "?")
                        value = double.Parse(parts[index]);
                    values.Add(value);
                    
                }
               
            }


            Data.Example example = new Data.Example(dataset.Metadata, exampleIndex, values.ToArray(), label);
            return example;

        }
コード例 #2
0
ファイル: ArffParser.cs プロジェクト: skn123/iFourmi
        private static Data.Instance ParseHierarchicalinstanceLine(int instanceIndex, string line, Data.Dataset dataset, bool skipFirstAttribute)
        {
            string[]      parts  = line.Split(',');
            List <double> values = new List <double>();

            List <int> label = new List <int>();

            string[] labelParts = parts[parts.Length - 1].Split(';');
            foreach (string target in labelParts)
            {
                if (!string.IsNullOrWhiteSpace(target))
                {
                    label.Add(dataset.Metadata.Target.GetIndex(target));
                }
            }



            for (int index = 0; index < parts.Length - 1; index++)
            {
                if (dataset.Metadata.Attributes[index] is Data.NominalAttribute)
                {
                    Data.NominalAttribute attribute = dataset.Metadata.Attributes[index] as Data.NominalAttribute;
                    string value = parts[index];
                    values.Add(attribute.GetIndex(value));
                }
                else
                {
                    double value = double.NaN;
                    if (parts[index] != "?")
                    {
                        value = double.Parse(parts[index]);
                    }
                    values.Add(value);
                }
            }


            Data.Instance instance = new Data.Instance(dataset.Metadata, instanceIndex, values.ToArray(), label);
            return(instance);
        }