Created
September 14, 2020 20:28
-
-
Save andrewluetgers/f3f10a5061d0b256f200490713fcdbbc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {every, filter} from 'lodash' | |
export const numericComparisons = { | |
lte: (a, b) => a <= b, | |
lt: (a, b) => a < b, | |
gt: (a, b) => a > b, | |
gte: (a, b) => a >= b, | |
eq: (a, b) => a === b, | |
neq: (a, b) => a !== b | |
} | |
export function evalRules(n, {name, description, ...classRules}, rules) { | |
return every(classRules, (classVal, ruleName) => rules[ruleName](n, classVal)) | |
} | |
export function classify(n, classes, rules) { | |
return filter(classes, classDef => evalRules(n, classDef, rules)) | |
} | |
export function numericClassification(n, classes) { | |
let c = classify(n, classes, numericComparisons) | |
return c[0] || {} | |
} | |
/* e.g. | |
let aucClasses = [ | |
{gte: 0.0, lt: 0.6, name: 'Failed'}, | |
{gte: 0.6, lt: 0.7, name: 'Marginal'}, | |
{gte: 0.7, lt: 0.8, name: 'Satisfactory'}, | |
{gte: 0.8, lte: 1.0, name: 'Good'} | |
] | |
aucRating = numericClassification(auc, aucClasses) | |
*/ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment