public static double CalculateEuclideanDistance(AdultTest a, AdultTrain b) { List <double> dist = new List <double>(); dist.Add(Square(a.age, b.age)); dist.Add(Square(1, Match(a.workclass, b.workclass))); dist.Add(Square(a.fnlwgt, b.fnlwgt)); dist.Add(Square(1, Match(a.education, b.education))); dist.Add(Square(a.educationNum, b.educationNum)); dist.Add(Square(1, Match(a.maritalStatus, b.maritalStatus))); dist.Add(Square(1, Match(a.occupation, b.occupation))); dist.Add(Square(1, Match(a.relationship, b.relationship))); dist.Add(Square(1, Match(a.race, b.race))); dist.Add(Square(1, Match(a.sex, b.sex))); dist.Add(Square(a.capitalGain, b.capitalGain)); dist.Add(Square(a.capitalLoss, b.capitalLoss)); dist.Add(Square(a.hoursPerWeek, b.hoursPerWeek)); dist.Add(Square(1, Match(a.nativeCountry, b.nativeCountry))); double sum = 0; foreach (var dis in dist) { sum += dis; } return(Math.Sqrt(sum)); }
public static void CountError(AdultTest input, TupleList <double, int> distLabels, int inputLabel, int split, int k) { int i = 1; List <double> lThan50 = new List <double>(); List <double> gThan50 = new List <double>(); foreach (var dl in distLabels) { if (dl.Item2 == 0) { lThan50.Add(dl.Item1); } else { gThan50.Add(dl.Item1); } if (i == k) { int label = 1; if (lThan50.Count > gThan50.Count) { label = 0; } if (inputLabel != label) { testErr[inputLabel]++; } } i++; } }