Last active
September 29, 2021 21:20
-
-
Save frogbandit/4987380bc8bb5291461b6254a1fc4abb to your computer and use it in GitHub Desktop.
Nova Credit Income Model Compute Confidence Score
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
/** | |
* Computes the sum of the intercept and the dot product of the coefficients and features for logistic regression model | |
* Using the formula s = b[0] + sum(b[1:] * x[1:]) | |
* and then computes the confidence score from this sum using the formula p = 1 / (1 + exp(-s)) | |
* @param normalizedFeatureValues the `x` vector, or the normalized model features | |
* @param coefficients the `b` vector, or the coefficients | |
* @param modelType conventional or non-conventional | |
*/ | |
export const computeConfidenceScore = ({ | |
normalizedFeatureValues, | |
coefficients, | |
modelType, | |
}: { | |
normalizedFeatureValues: number[]; | |
coefficients: number[]; | |
modelType: MODEL_TYPES; | |
}): number => { | |
const b0 = MODEL_FEATURE_TO_COEFFICIENT_MEAN_SCALE[modelType].intercept && MODEL_FEATURE_TO_COEFFICIENT_MEAN_SCALE[modelType].intercept.COEFFICIENT; | |
if (!b0) { | |
throw new commonErrors.NovaError(`Intercept coefficient not defined for model type ${modelType}`); | |
} | |
const sum = b0 + dot(coefficients, normalizedFeatureValues); | |
const p = 1 / (1 + Math.exp(-sum)); | |
return 100 * p; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment