Esempio n. 1
0
File: Iris.cs Progetto: alarial/numl
        public static Iris[] Load()
        {
            if (File.Exists("Data\\iris.data"))
            {
                List <Iris> data = new List <Iris>();
                using (var reader = File.OpenText("Data\\iris.data"))
                {
                    while (!reader.EndOfStream)
                    {
                        var tokens = reader.ReadLine().Split(',');
                        if (tokens.Length == 5)
                        {
                            Iris f = new Iris
                            {
                                SepalLength = decimal.Parse(tokens[0]),
                                SepalWidth  = decimal.Parse(tokens[1]),
                                PetalLength = decimal.Parse(tokens[2]),
                                PetalWidth  = decimal.Parse(tokens[3]),
                                Class       = tokens[4],
                            };

                            data.Add(f);
                        }
                    }
                }

                return(data.ToArray());
            }
            else
            {
                return new Iris[] { }
            };
        }
    }
Esempio n. 2
0
        public static Iris[] Load()
        {
            if (File.Exists("Data\\iris.data"))
            {
                List<Iris> data = new List<Iris>();
                using (var reader = File.OpenText("Data\\iris.data"))
                {
                    while (!reader.EndOfStream)
                    {
                        var tokens = reader.ReadLine().Split(',');
                        if (tokens.Length == 5)
                        {
                            Iris f = new Iris
                            {
                                SepalLength = decimal.Parse(tokens[0]),
                                SepalWidth = decimal.Parse(tokens[1]),
                                PetalLength = decimal.Parse(tokens[2]),
                                PetalWidth = decimal.Parse(tokens[3]),
                                Class = tokens[4],
                            };

                            data.Add(f);
                        }
                    }
                }

                return data.ToArray();
            }
            else
                return new Iris[] { };
        }
Esempio n. 3
0
        public void Iris_DT_and_Prediction()
        {
            var data = Iris.Load();
            var description = Descriptor.Create<Iris>();
            var generator = new NaiveBayesGenerator(2);
            var model = generator.Generate(description, data);

            // should be Iris-Setosa
            Iris iris = new Iris
            {
                SepalLength = 2.1m,
                SepalWidth = 2.2m,
                PetalWidth = 0.5m,
                PetalLength = 2.3m,
            };

            iris = model.Predict<Iris>(iris);
            Assert.AreEqual("Iris-setosa".Sanitize(), iris.Class);
        }
Esempio n. 4
0
        public void Iris_DT_and_Prediction_with_Learner()
        {
            var data = Iris.Load();

            var generator = new DecisionTreeGenerator(50)
            {
                Descriptor = Descriptor.Create<Iris>(),
                Hint = 0
            };

            var lmodel = Learner.Learn(data, .80, 1000, generator);

            // should be Iris-Setosa
            Iris iris = new Iris
            {
                PetalWidth = 0.5m,
                PetalLength = 2.3m,
                SepalLength = 2.1m,
                SepalWidth = 2.1m
            };

            iris = lmodel.Model.Predict<Iris>(iris);
            Assert.AreEqual("Iris-setosa".Sanitize(), iris.Class);
        }