def accuracyMicro(y_test, predictions): """ Accuracy Micro of our model Params ====== y_test : sparse or dense matrix (n_samples, n_labels) Matrix of labels used in the test phase predictions: sparse or dense matrix (n_samples, n_labels) Matrix of predicted labels given by our model Returns ======= accuracymicro : float Accuracy Micro of our model """ accuracymicro = 0.0 TP, FP, TN, FN = multilabelConfussionMatrix(y_test, predictions) TPMicro, FPMicro, TNMicro, FNMicro = multilabelMicroConfussionMatrix( TP, FP, TN, FN) if (TPMicro + FPMicro + TNMicro + FNMicro) != 0: accuracymicro = float( (TPMicro + TNMicro) / (TPMicro + FPMicro + TNMicro + FNMicro)) return accuracymicro
def fbetaMicro(y_test, predictions, beta=1): """ FBeta Micro of our model Params ====== y_test : sparse or dense matrix (n_samples, n_labels) Matrix of labels used in the test phase predictions: sparse or dense matrix (n_samples, n_labels) Matrix of predicted labels given by our model Returns ======= fbetamicro : float FBeta Micro of our model """ fbetamicro = 0.0 TP, FP, TN, FN = multilabelConfussionMatrix(y_test, predictions) TPMicro, FPMicro, TNMicro, FNMicro = multilabelMicroConfussionMatrix( TP, FP, TN, FN) num = float((1 + pow(beta, 2)) * TPMicro) den = float((1 + pow(beta, 2)) * TPMicro + pow(beta, 2) * FNMicro + FPMicro) fbetamicro = float(num / den) return fbetamicro
def precisionMicro(y_test, predictions): """ Precision Micro of our model Params ====== y_test : sparse or dense matrix (n_samples, n_labels) Matrix of labels used in the test phase predictions: sparse or dense matrix (n_samples, n_labels) Matrix of predicted labels given by our model Returns ======= precisionmicro : float Precision micro of our model """ precisionmicro = 0.0 TP, FP, TN, FN = multilabelConfussionMatrix(y_test, predictions) TPMicro, FPMicro, TNMicro, FNMicro = multilabelMicroConfussionMatrix( TP, FP, TN, FN) if (TPMicro + FPMicro) != 0: precisionmicro = float(TPMicro / (TPMicro + FPMicro)) return precisionmicro