Skip to main content

PerMetrics: A Framework of Performance Metrics for Machine Learning Models

Project description

PERMETRICS


GitHub release Wheel PyPI version PyPI - Python Version PyPI - Status PyPI - Downloads Downloads Tests & Publishes to PyPI GitHub Release Date Documentation Status Chat GitHub contributors GitTutorial DOI License: GPL v3

PerMetrics is a python library for performance metrics of machine learning models. We aim to implement all performance metrics for problems such as regression, classification, clustering, ... problems. Helping users in all field access metrics as fast as possible

  • Free software: GNU General Public License (GPL) V3 license
  • Total metrics: 111 (47 regression metrics, 20 classification metrics, 44 clustering metrics)
  • Documentation: https://permetrics.readthedocs.io/en/latest/
  • Python versions: >= 3.7.x
  • Dependencies: numpy, scipy

Notification

  • Currently, there is a huge misunderstanding among frameworks around the world about the notation of R, R2, and R^2.
  • Please read the file R-R2-Rsquared.docx to understand the differences between them and why there is such confusion.

R

  • My recommendation is to denote the Coefficient of Determination as COD or R2, while the squared Pearson's Correlation Coefficient should be denoted as R^2 or RSQ (as in Excel software).

Installation

Install with pip

Install the current PyPI release:

$ pip install permetrics==1.5.0

Or installing from the source code, use:

$ git clone https://github.com/thieu1995/permetrics.git
$ cd permetrics
$ python setup.py install

Or install the development version from GitHub:

pip install git+https://github.com/thieu1995/permetrics

After installation, you can import Permetrics as any other Python module:

$ python
>>> import permetrics
>>> permetrics.__version__

Let's go through some examples. The more complicated test case in the folder: examples

The documentation includes more detailed installation instructions and explanations.

Example with Regression metrics

import numpy as np
from permetrics import RegressionMetric

## For 1-D array
y_true = [3, -0.5, 2, 7]
y_pred = [2.5, 0.0, 2, 8]

evaluator = RegressionMetric(y_true, y_pred, decimal=5)
print(evaluator.RMSE())
print(evaluator.MSE())

## For > 1-D array
y_true = np.array([[0.5, 1], [-1, 1], [7, -6]])
y_pred = np.array([[0, 2], [-1, 2], [8, -5]])

evaluator = RegressionMetric(y_true, y_pred, decimal=5)
print(evaluator.RMSE(multi_output="raw_values", decimal=5))
print(evaluator.MAE(multi_output="raw_values", decimal=5))

Example with Classification metrics

from permetrics import ClassificationMetric

## For integer labels or categorical labels
y_true = [0, 1, 0, 0, 1, 0]
y_pred = [0, 1, 0, 0, 0, 1]

# y_true = ["cat", "ant", "cat", "cat", "ant", "bird", "bird", "bird"]
# y_pred = ["ant", "ant", "cat", "cat", "ant", "cat", "bird", "ant"]

evaluator = ClassificationMetric(y_true, y_pred, decimal=5)

## Call specific function inside object, each function has 3 names like below

print(evaluator.f1_score())
print(evaluator.F1S(average="micro"))
print(evaluator.F1S(average="macro"))
print(evaluator.F1S(average="weighted"))

Example with Clustering metrics

import numpy as np
from permetrics import ClusteringMetric

# generate sample data
X = np.random.uniform(-1, 10, size=(500, 7))        # 500 examples, 7 features
y_true = np.random.randint(0, 4, size=500)          # 4 clusters
y_pred = np.random.randint(0, 4, size=500)

evaluator = ClusteringMetric(y_true=y_true, y_pred=y_pred, X=X, decimal=5)

## Call specific function inside object, each function has 2 names (fullname and short name)
##    + Internal metrics: Need X and y_pred and has suffix as index
##    + External metrics: Need y_true and y_pred and has suffix as score

print(evaluator.ball_hall_index())
print(evaluator.BHI())

Metrics

ProblemSTTMetricMetric FullnameCharacteristics
Regression1EVSExplained Variance ScoreBigger is better (Best = 1), Range=(-inf, 1.0]
****2MEMax ErrorSmaller is better (Best = 0), Range=[0, +inf)
****3MBEMean Bias ErrorBest = 0, Range=(-inf, +inf)
****4MAEMean Absolute ErrorSmaller is better (Best = 0), Range=[0, +inf)
****5MSEMean Squared ErrorSmaller is better (Best = 0), Range=[0, +inf)
****6RMSERoot Mean Squared ErrorSmaller is better (Best = 0), Range=[0, +inf)
****7MSLEMean Squared Log ErrorSmaller is better (Best = 0), Range=[0, +inf)
****8MedAEMedian Absolute ErrorSmaller is better (Best = 0), Range=[0, +inf)
****9MRE / MRBMean Relative Error / Mean Relative BiasSmaller is better (Best = 0), Range=[0, +inf)
****10MPEMean Percentage ErrorBest = 0, Range=(-inf, +inf)
****11MAPEMean Absolute Percentage ErrorSmaller is better (Best = 0), Range=[0, +inf)
****12SMAPESymmetric Mean Absolute Percentage ErrorSmaller is better (Best = 0), Range=[0, 1]
****13MAAPEMean Arctangent Absolute Percentage ErrorSmaller is better (Best = 0), Range=[0, +inf)
****14MASEMean Absolute Scaled ErrorSmaller is better (Best = 0), Range=[0, +inf)
****15NSENash-Sutcliffe Efficiency CoefficientBigger is better (Best = 1), Range=(-inf, 1]
****16NNSENormalized Nash-Sutcliffe Efficiency CoefficientBigger is better (Best = 1), Range=[0, 1]
****17WIWillmott IndexBigger is better (Best = 1), Range=[0, 1]
****18R / PCCPearson’s Correlation CoefficientBigger is better (Best = 1), Range=[-1, 1]
****19AR / APCCAbsolute Pearson's Correlation CoefficientBigger is better (Best = 1), Range=[-1, 1]
****20RSQ/R2S(Pearson’s Correlation Index) ^ 2Bigger is better (Best = 1), Range=[0, 1]
****21R2 / CODCoefficient of DeterminationBigger is better (Best = 1), Range=(-inf, 1]
****22AR2 / ACODAdjusted Coefficient of DeterminationBigger is better (Best = 1), Range=(-inf, 1]
****23CIConfidence IndexBigger is better (Best = 1), Range=(-inf, 1]
****24DRVDeviation of Runoff VolumeSmaller is better (Best = 1.0), Range=[1, +inf)
****25KGEKling-Gupta EfficiencyBigger is better (Best = 1), Range=(-inf, 1]
****26GINIGini CoefficientSmaller is better (Best = 0), Range=[0, +inf)
****27GINI_WIKIGini Coefficient on WikipageSmaller is better (Best = 0), Range=[0, +inf)
****28PCDPrediction of Change in DirectionBigger is better (Best = 1.0), Range=[0, 1]
****29CECross EntropyRange(-inf, 0], Can't give comment about this
****30KLDKullback Leibler DivergenceBest = 0, Range=(-inf, +inf)
****31JSDJensen Shannon DivergenceSmaller is better (Best = 0), Range=[0, +inf)
****32VAFVariance Accounted ForBigger is better (Best = 100%), Range=(-inf, 100%]
****33RAERelative Absolute ErrorSmaller is better (Best = 0), Range=[0, +inf)
****34A10A10 IndexBigger is better (Best = 1), Range=[0, 1]
****35A20A20 IndexBigger is better (Best = 1), Range=[0, 1]
****36A30A30 IndexBigger is better (Best = 1), Range=[0, 1]
****37NRMSENormalized Root Mean Square ErrorSmaller is better (Best = 0), Range=[0, +inf)
****38RSEResidual Standard ErrorSmaller is better (Best = 0), Range=[0, +inf)
****39RE / RBRelative Error / Relative BiasBest = 0, Range=(-inf, +inf)
****40AEAbsolute ErrorBest = 0, Range=(-inf, +inf)
****41SESquared ErrorSmaller is better (Best = 0), Range=[0, +inf)
****42SLESquared Log ErrorSmaller is better (Best = 0), Range=[0, +inf)
****43COVCovarianceBigger is better (No best value), Range=(-inf, +inf)
****44CORCorrelationBigger is better (Best = 1), Range=[-1, +1]
****45ECEfficiency CoefficientBigger is better (Best = 1), Range=(-inf, +1]
****46OIOverall IndexBigger is better (Best = 1), Range=(-inf, +1]
****47CRMCoefficient of Residual MassSmaller is better (Best = 0), Range=(-inf, +inf)
********************
Classification1PSPrecision ScoreBigger is better (Best = 1), Range = [0, 1]
****2NPVNegative Predictive ValueBigger is better (Best = 1), Range = [0, 1]
****3RSRecall ScoreBigger is better (Best = 1), Range = [0, 1]
****4ASAccuracy ScoreBigger is better (Best = 1), Range = [0, 1]
****5F1SF1 ScoreBigger is better (Best = 1), Range = [0, 1]
****6F2SF2 ScoreBigger is better (Best = 1), Range = [0, 1]
****7FBSF-Beta ScoreBigger is better (Best = 1), Range = [0, 1]
****8SSSpecificity ScoreBigger is better (Best = 1), Range = [0, 1]
****9MCCMatthews Correlation CoefficientBigger is better (Best = 1), Range = [-1, +1]
****10HSHamming ScoreBigger is better (Best = 1), Range = [0, 1]
****11CKSCohen's kappa scoreBigger is better (Best = +1), Range = [-1, +1]
****12JSIJaccard Similarity CoefficientBigger is better (Best = +1), Range = [0, +1]
****13GMSGeometric Mean ScoreBigger is better (Best = +1), Range = [0, +1]
****14ROC-AUCROC-AUCBigger is better (Best = +1), Range = [0, +1]
****15LSLift ScoreBigger is better (No best value), Range = [0, +inf)
****16GINIGINI IndexSmaller is better (Best = 0), Range = [0, +1]
****17CELCross Entropy LossSmaller is better (Best = 0), Range=[0, +inf)
****18HLHinge LossSmaller is better (Best = 0), Range=[0, +inf)
****19KLDLKullback Leibler Divergence LossSmaller is better (Best = 0), Range=[0, +inf)
****20BSLBrier Score LossSmaller is better (Best = 0), Range=[0, +1]
********************
Clustering1BHIBall Hall IndexSmaller is better (Best = 0), Range=[0, +inf)
****2XBIXie Beni IndexSmaller is better (Best = 0), Range=[0, +inf)
****3DBIDavies Bouldin IndexSmaller is better (Best = 0), Range=[0, +inf)
****4BRIBanfeld Raftery IndexSmaller is better (No best value), Range=(-inf, inf)
****5KDIKsq Detw IndexSmaller is better (No best value), Range=(-inf, +inf)
****6DRIDet Ratio IndexBigger is better (No best value), Range=[0, +inf)
****7DIDunn IndexBigger is better (No best value), Range=[0, +inf)
****8CHICalinski Harabasz IndexBigger is better (No best value), Range=[0, inf)
****9LDRILog Det Ratio IndexBigger is better (No best value), Range=(-inf, +inf)
****10LSRILog SS Ratio IndexBigger is better (No best value), Range=(-inf, +inf)
****11SISilhouette IndexBigger is better (Best = 1), Range = [-1, +1]
****12SSEISum of Squared Error IndexSmaller is better (Best = 0), Range = [0, +inf)
****13MSEIMean Squared Error IndexSmaller is better (Best = 0), Range = [0, +inf)
****14DHIDuda-Hart IndexSmaller is better (Best = 0), Range = [0, +inf)
****15BIBeale IndexSmaller is better (Best = 0), Range = [0, +inf)
****16RSIR-squared IndexBigger is better (Best=1), Range = (-inf, 1]
****17DBCVIDensity-based Clustering Validation IndexBigger is better (Best=0), Range = [0, 1]
****18HIHartigan IndexBigger is better (best=0), Range = [0, +inf)
****19MISMutual Info ScoreBigger is better (No best value), Range = [0, +inf)
****20NMISNormalized Mutual Info ScoreBigger is better (Best = 1), Range = [0, 1]
****21RaSRand ScoreBigger is better (Best = 1), Range = [0, 1]
****22ARSAdjusted Rand ScoreBigger is better (Best = 1), Range = [-1, 1]
****23FMSFowlkes Mallows ScoreBigger is better (Best = 1), Range = [0, 1]
****24HSHomogeneity ScoreBigger is better (Best = 1), Range = [0, 1]
****25CSCompleteness ScoreBigger is better (Best = 1), Range = [0, 1]
****26VMSV-Measure ScoreBigger is better (Best = 1), Range = [0, 1]
****27PrSPrecision ScoreBigger is better (Best = 1), Range = [0, 1]
****28ReSRecall ScoreBigger is better (Best = 1), Range = [0, 1]
****29FmSF-Measure ScoreBigger is better (Best = 1), Range = [0, 1]
****30CDSCzekanowski Dice ScoreBigger is better (Best = 1), Range = [0, 1]
****31HGSHubert Gamma ScoreBigger is better (Best = 1), Range=[-1, +1]
****32JSJaccard ScoreBigger is better (Best = 1), Range = [0, 1]
****33KSKulczynski ScoreBigger is better (Best = 1), Range = [0, 1]
****34MNSMc Nemar ScoreBigger is better (No best value), Range=(-inf, +inf)
****35PhSPhi ScoreBigger is better (No best value), Range = (-inf, +inf)
****36RTSRogers Tanimoto ScoreBigger is better (Best = 1), Range = [0, 1]
****37RRSRussel Rao ScoreBigger is better (Best = 1), Range = [0, 1]
****38SS1SSokal Sneath1 ScoreBigger is better (Best = 1), Range = [0, 1]
****39SS2SSokal Sneath2 ScoreBigger is better (Best = 1), Range = [0, 1]
****40PuSPurity ScoreBigger is better (Best = 1), Range = [0, 1]
****41ESEntropy ScoreSmaller is better (Best = 0), Range = [0, +inf)
****42TSTau ScoreBigger is better (No best value), Range = (-inf, +inf)
****43GASGamma ScoreBigger is better (Best = 1), Range = [-1, 1]
****44GPSGplus ScoreSmaller is better (Best = 0), Range = [0, 1]
********************

Support (questions, problems)

Official channels

Citation Request

Please include these citations if you plan to use this library:

@software{nguyen_van_thieu_2023_8220489,
  author       = {Nguyen Van Thieu},
  title        = {PerMetrics: A Framework of Performance Metrics for Machine Learning Models},
  month        = aug,
  year         = 2023,
  publisher    = {Zenodo},
  doi          = {10.5281/zenodo.3951205},
  url          = {https://github.com/thieu1995/permetrics}
}

@article{van2023mealpy,
  title={MEALPY: An open-source library for latest meta-heuristic algorithms in Python},
  author={Van Thieu, Nguyen and Mirjalili, Seyedali},
  journal={Journal of Systems Architecture},
  year={2023},
  publisher={Elsevier},
  doi={10.1016/j.sysarc.2023.102871}
}

Related Documents

  1. https://www.debadityachakravorty.com/ai-ml/cmatrix/
  2. https://neptune.ai/blog/evaluation-metrics-binary-classification
  3. https://danielyang1009.github.io/model-performance-measure/
  4. https://towardsdatascience.com/multi-class-metrics-made-simple-part-i-precision-and-recall-9250280bddc2
  5. http://cran.nexr.com/web/packages/clusterCrit/vignettes/clusterCrit.pdf
  6. https://publikationen.bibliothek.kit.edu/1000120412/79692380
  7. https://torchmetrics.readthedocs.io/en/latest/
  8. http://rasbt.github.io/mlxtend/user_guide/evaluate/lift_score/
  9. https://www.baeldung.com/cs/multi-class-f1-score
  10. https://kavita-ganesan.com/how-to-compute-precision-and-recall-for-a-multi-class-classification-problem/#.YoXMSqhBy3A
  11. https://machinelearningmastery.com/precision-recall-and-f-measure-for-imbalanced-classification/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

permetrics-1.5.0.tar.gz (386.1 kB view hashes)

Uploaded Source

Built Distribution

permetrics-1.5.0-py3-none-any.whl (56.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page