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[] { } }; } }
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[] { }; }
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); }
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); }