Skip to content

AutoML.Net filter infinity value when calculate average score #5345

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 19, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,24 @@ private static double GetAverageOfNonNaNScores(IEnumerable<double> results)
return newResults.Average(r => r);
}

/// <summary>
/// return the index of value from <paramref name="values"/> that closest to <paramref name="average"/>. If <paramref name="average"/> is NaN, +/- inf, the first, max/min value's index will be return.
/// </summary>
private static int GetIndexClosestToAverage(IEnumerable<double> values, double average)
{
// Average will be NaN iff all values are NaN.
// Return the first index in this case.
if (double.IsNaN(average))
return 0;

// Return the max value's index if average is positive inf.
if (double.IsPositiveInfinity(average))
return values.ToList().IndexOf(values.Max());

// Return the min value's index if average is negative inf.
if (double.IsNegativeInfinity(average))
return values.ToList().IndexOf(values.Min());

int avgFoldIndex = -1;
var smallestDistFromAvg = double.PositiveInfinity;
for (var i = 0; i < values.Count(); i++)
Expand All @@ -181,4 +192,4 @@ private static int GetIndexClosestToAverage(IEnumerable<double> values, double a
return avgFoldIndex;
}
}
}
}