public void InitializeSets() { string line; string path = @"C:\Users\matrona\Desktop\AI-Homework\AI-Homework\Knn-Iris\iris.txt"; var file = new StreamReader(path); while ((line = file.ReadLine()) != null) { bool isTest = rand.Next(50) % 5 == 0; string[] data = line.Split(","); var iris = new Iris() { Prop1 = Convert.ToDouble(data[0]), Prop2 = Convert.ToDouble(data[1]), Prop3 = Convert.ToDouble(data[2]), Prop4 = Convert.ToDouble(data[3]), Type = data[4], ActualType = data[4] }; if (isTest && testSet.Count < 20) { testSet.Add(iris); } else { trainingSet.Add(iris); } } }
private double calculateEuclideanDistance(Iris from, Iris to) { double distance = Math.Pow((from.Prop1 - to.Prop2), 2) + Math.Pow(from.Prop2 - to.Prop2, 2) + Math.Pow(from.Prop3 - to.Prop3, 2) + Math.Pow(from.Prop4 - to.Prop4, 2); return(Math.Sqrt(distance)); }