Comments (2)
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.
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)
- Update documentation
- GPU support
- when running the example i get IndexError: arrays used as indices must be of integer (or boolean) type HOT 2
- Yielding Error - from lazypredict.Supervised import LazyClassifier HOT 3
- ROC-AUC calculation HOT 1
- Support for time series forecasting
- Are predictions same as models? HOT 3
- Cannot run example as shown in the docs HOT 1
- ValueError: too many values to unpack (expected 2) HOT 2
- import error HOT 2
- segmentation fault error
- Add precision to LazyClassifier HOT 1
- Boolean DataFrame incorrect shape
- Verbosity and logging HOT 1
- libmamba Added empty dependency for problem type SOLVER_RULE_UPDATE
- Stopping slow algorithms
- TypeError (OneHotEncoder) on importing LazyRegressor from lazypredict.Supervised HOT 2
- from lazypredict.Supervised import LazyClassifier - TypeError: OneHotEncoder.__init__() got an unexpected keyword argument 'sparse' HOT 7
- scikit-learn version issue HOT 3
- Classification turned into regression HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lazypredict.