{"id":762,"date":"2025-08-31T21:12:51","date_gmt":"2025-08-31T20:12:51","guid":{"rendered":"https:\/\/orange-attractor.eu\/?p=762"},"modified":"2025-09-01T08:26:32","modified_gmt":"2025-09-01T07:26:32","slug":"introducing-scikit-p4-a-simple-p4-metric-for-python","status":"publish","type":"post","link":"https:\/\/orange-attractor.eu\/?p=762","title":{"rendered":"Introducing Scikit-P4: a simple library for Python"},"content":{"rendered":"<p>I&#8217;ve just released Scikit-P4, a small Python library that computes the P4 metric for binary, multiclass, and multilabel classification &#8211; using an API that mirrors scikit-learn&#8217;s metrics (think <code>f1_score<\/code>, but for P4).<\/p>\n<p><!--more--><\/p>\n<h2>Why P4?<\/h2>\n<p>Unlike the F1 metric, the P4 metric incorporates true negatives. Based on four conditional probabilities, it is more balanced than F1 and, in some cases, more desirable.<\/p>\n<h2>Highlights<\/h2>\n<ul>\n<li>Drop-in function: <code>p4_score(y_true, y_pred)<\/code><\/li>\n<li>Works across binary\/multiclass\/multilabel (auto-detected)<\/li>\n<li>Micro \/ macro \/ weighted \/ samples averages for multi-case outputs<\/li>\n<li><code>zero_division<\/code> behavior aligned with scikit-learn<\/li>\n<\/ul>\n<h2>Install<\/h2>\n<pre><code>\r\npip install scikit-p4\r\n<\/code><\/pre>\n<p>Or add it to your Poetry project and <code>poetry install<\/code>.<\/p>\n<h2>Quick start<\/h2>\n<pre><code>\r\nfrom skp4.metrics import p4_score\r\n\r\ny_true = [0, 0, 0, 0, 1, 1, 1, 1, 0, 0]\r\ny_pred = [0, 1, 0, 0, 1, 1, 1, 0, 1, 0]\r\n\r\nprint(p4_score(y_true, y_pred))\r\n\r\n<\/code><\/pre>\n<h2>Links<\/h2>\n<ul>\n<li>GitHub: <a href=\"https:\/\/github.com\/mikolaj1024\/scikit-p4\">https:\/\/github.com\/mikolaj1024\/scikit-p4<\/a><\/li>\n<li>PyPI: <a href=\"https:\/\/pypi.org\/project\/scikit-p4\/\">https:\/\/pypi.org\/project\/scikit-p4\/<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve just released Scikit-P4, a small Python library that computes the P4 metric for binary, multiclass, and multilabel classification &#8211; using an API that mirrors scikit-learn&#8217;s metrics (think f1_score, but for P4).<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,20,2],"tags":[],"class_list":["post-762","post","type-post","status-publish","format-standard","hentry","category-machine-learning","category-python","category-statistics"],"_links":{"self":[{"href":"https:\/\/orange-attractor.eu\/index.php?rest_route=\/wp\/v2\/posts\/762"}],"collection":[{"href":"https:\/\/orange-attractor.eu\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/orange-attractor.eu\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/orange-attractor.eu\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/orange-attractor.eu\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=762"}],"version-history":[{"count":16,"href":"https:\/\/orange-attractor.eu\/index.php?rest_route=\/wp\/v2\/posts\/762\/revisions"}],"predecessor-version":[{"id":779,"href":"https:\/\/orange-attractor.eu\/index.php?rest_route=\/wp\/v2\/posts\/762\/revisions\/779"}],"wp:attachment":[{"href":"https:\/\/orange-attractor.eu\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=762"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/orange-attractor.eu\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=762"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/orange-attractor.eu\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=762"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}