Skip to content

Commit ba1804e

Browse files
LittleLittleCloudBigBigMiao
andauthored
AutoML.Net filter infinity value when calculate average score (#5345)
* fix 5339 * Update CrossValSummaryRunner.cs Co-authored-by: BigBigMiao <BigBigMiao@github.com>
1 parent 9141290 commit ba1804e

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/Microsoft.ML.AutoML/Experiment/Runners/CrossValSummaryRunner.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,24 @@ private static double GetAverageOfNonNaNScores(IEnumerable<double> results)
157157
return newResults.Average(r => r);
158158
}
159159

160+
/// <summary>
161+
/// 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.
162+
/// </summary>
160163
private static int GetIndexClosestToAverage(IEnumerable<double> values, double average)
161164
{
162165
// Average will be NaN iff all values are NaN.
163166
// Return the first index in this case.
164167
if (double.IsNaN(average))
165168
return 0;
166169

170+
// Return the max value's index if average is positive inf.
171+
if (double.IsPositiveInfinity(average))
172+
return values.ToList().IndexOf(values.Max());
173+
174+
// Return the min value's index if average is negative inf.
175+
if (double.IsNegativeInfinity(average))
176+
return values.ToList().IndexOf(values.Min());
177+
167178
int avgFoldIndex = -1;
168179
var smallestDistFromAvg = double.PositiveInfinity;
169180
for (var i = 0; i < values.Count(); i++)
@@ -181,4 +192,4 @@ private static int GetIndexClosestToAverage(IEnumerable<double> values, double a
181192
return avgFoldIndex;
182193
}
183194
}
184-
}
195+
}

0 commit comments

Comments
 (0)