Skip to content

Commit

Permalink
[ML] Data Frame Analytics results: ensure model evaluation stats are …
Browse files Browse the repository at this point in the history
…shown (#97486)

* ensure we check for NaN and Infinity in eval response

* add unit test
  • Loading branch information
alvarezmelissa87 authored Apr 20, 2021
1 parent 7b030f3 commit ce2fec2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { getAnalysisType, isOutlierAnalysis } from './analytics';
import { getAnalysisType, getValuesFromResponse, isOutlierAnalysis } from './analytics';

describe('Data Frame Analytics: Analytics utils', () => {
test('getAnalysisType()', () => {
Expand Down Expand Up @@ -35,4 +35,22 @@ describe('Data Frame Analytics: Analytics utils', () => {
const unknownAnalysis = { outlier_detection: {}, regression: {} };
expect(isOutlierAnalysis(unknownAnalysis)).toBe(false);
});

test('getValuesFromResponse()', () => {
const evalResponse: any = {
regression: {
huber: { value: 'NaN' },
mse: { value: 7.514953437693147 },
msle: { value: 'Infinity' },
r_squared: { value: 0.9837343227799651 },
},
};
const expectedResponse = {
mse: 7.51,
msle: 'Infinity',
huber: 'NaN',
r_squared: 0.984,
};
expect(getValuesFromResponse(evalResponse)).toEqual(expectedResponse);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ export function getValuesFromResponse(response: RegressionEvaluateResponse) {
if (response.regression.hasOwnProperty(statType)) {
let currentStatValue =
response.regression[statType as keyof RegressionEvaluateResponse['regression']]?.value;
if (currentStatValue && !isNaN(currentStatValue)) {
if (currentStatValue && Number.isFinite(currentStatValue)) {
currentStatValue = Number(currentStatValue.toPrecision(DEFAULT_SIG_FIGS));
}
results[statType as keyof RegressionEvaluateExtractedResponse] = currentStatValue;
Expand Down

0 comments on commit ce2fec2

Please sign in to comment.