Git Product home page Git Product logo

Comments (2)

fabio-reale avatar fabio-reale commented on September 3, 2024

I just took a look at the code. Never used it, never installed it even. So, with that caveat... it looks like if you pass to the custom_metric parameter a callabe with the same signature as .score() from sklearn it has to work.

from lazypredict.

mp675 avatar mp675 commented on September 3, 2024

you can add any metrics available on sklearn.metrics or even add a real custom one in example:

`import math
from sklearn.metrics import matthews_corrcoef, recall_score, precision_score, f1_score, accuracy_score, roc_auc_score

def custom_metrics(y_true, y_pred, model_name):
mcc = matthews_corrcoef(y_true, y_pred)
recall = recall_score(y_true, y_pred)
precision = precision_score(y_true, y_pred)
f1 = f1_score(y_true, y_pred)
accuracy = accuracy_score(y_true, y_pred)
roc_auc = roc_auc_score(y_true, y_pred)

# Calculate confusion matrix values
TN = ((y_true == 0) & (y_pred == 0)).sum()
FP = ((y_true == 0) & (y_pred == 1)).sum()
FN = ((y_true == 1) & (y_pred == 0)).sum()
TP = ((y_true == 1) & (y_pred == 1)).sum()

sensitivity = recall
specificity = TN / (TN + FP) if (TN + FP) != 0 else 0
npv = TN / (TN + FN) if (TN + FN) != 0 else 0
TPR = recall
FPR = FP / (FP + TN)
FNR = FN / (TP + FN)
TNR = specificity
ACC = accuracy
F1S = f1
MCC = mcc

print("{} - Sensitivity = {:.2f}%".format(model_name, sensitivity * 100))
print("{} - Specificity = {:.2f}%".format(model_name, specificity * 100))
print("{} - Precision   = {:.2f}%".format(model_name, precision * 100))
print("{} - NPV         = {:.2f}%".format(model_name, npv * 100))
print("{} - TPR         = {:.2f}%".format(model_name, TPR * 100))
print("{} - FPR         = {:.2f}%".format(model_name, FPR * 100))
print("{} - FNR         = {:.2f}%".format(model_name, FNR * 100))
print("{} - TNR         = {:.2f}%".format(model_name, TNR * 100))
print("{} - ACC         = {:.2f}".format(model_name, ACC))
print("{} - F1 Score    = {:.2f}%".format(model_name, F1S * 100))
print("{} - MCC         = {:.2f}".format(model_name, MCC))
print("{} - ROC AUC     = {:.2f}".format(model_name, roc_auc))

return {'Model': model_name, 'Sensitivity': sensitivity, 'Specificity': specificity, 
        'Precision': precision, 'NPV': npv, 'TPR': TPR, 'FPR': FPR, 'FNR': FNR, 
        'TNR': TNR, 'ACC': ACC, 'F1 Score': F1S, 'MCC': MCC, 'ROC AUC': roc_auc}

Initialize LazyClassifier for training

clf = LazyClassifier(custom_metric=custom_metrics, ignore_warnings=True, verbose=False)
models, predictions = clf.fit(X_train, X_test, y_train, y_test)
`

from lazypredict.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.