private static double GetDistanceFromZero(DataRecord Record, string IDAttributeName, string ClassificationAttributeName, double Power = 2d) { double distance = 0; DataRecord zero = new DataRecord(); foreach (string attribute in Record.GetAttributes()) { zero.AddOrUpdateValue(attribute, "0"); } foreach (string attributeName in Record.GetAttributes()) { if (attributeName != ClassificationAttributeName && attributeName != IDAttributeName) { distance += Math.Pow(Math.Abs(double.Parse(Record.GetAttributeValue(attributeName)) - double.Parse(zero.GetAttributeValue(attributeName))), Power); } } return(Math.Pow(distance, (1 / Power))); }
private static double GetDistanceBetweenRecords(DataRecord LHS, DataRecord RHS, string IDAttributeName, string ClassificationAttributeName, double Power = 2d) { double distance = 0; foreach (string attributeName in LHS.GetAttributes()) { if (attributeName != ClassificationAttributeName && attributeName != IDAttributeName) { distance += Math.Pow(Math.Abs(double.Parse(LHS.GetAttributeValue(attributeName)) - double.Parse(RHS.GetAttributeValue(attributeName))), Power); } } return(Math.Pow(distance, (1 / Power))); }