{"id":32203044,"url":"https://github.com/serkor1/slmetrics","last_synced_at":"2026-02-18T21:03:13.703Z","repository":{"id":266789042,"uuid":"847038696","full_name":"serkor1/SLmetrics","owner":"serkor1","description":"A high-performance R :package: for supervised and unsupervised machine learning evaluation metrics witten in 'C++'.","archived":false,"fork":false,"pushed_at":"2025-06-21T20:16:25.000Z","size":28606,"stargazers_count":27,"open_issues_count":1,"forks_count":4,"subscribers_count":1,"default_branch":"development","last_synced_at":"2026-02-01T16:47:24.331Z","etag":null,"topics":["armadillo","armadillo-library","artificial-intelligence","cpp","cran","cran-r","data-analysis","data-science","eigen3","machine-learning","performance-metrics","r","r-package","r-stats","rcpp","rcpparmadillo","rcppeigen","statistics","supervised-learning"],"latest_commit_sha":null,"homepage":"https://slmetrics-docs.gitbook.io/v1","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/serkor1.png","metadata":{"files":{"readme":"README.md","changelog":"NEWS.md","contributing":null,"funding":".github/FUNDING.yaml","license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":"codemeta.json","zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":["serkor1"]}},"created_at":"2024-08-24T17:09:25.000Z","updated_at":"2025-09-02T11:40:05.000Z","dependencies_parsed_at":"2025-03-21T05:19:53.633Z","dependency_job_id":"9971460f-b771-4c2e-b23e-8fe9434ccb46","html_url":"https://github.com/serkor1/SLmetrics","commit_stats":null,"previous_names":["serkor1/slmetrics"],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/serkor1/SLmetrics","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serkor1%2FSLmetrics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serkor1%2FSLmetrics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serkor1%2FSLmetrics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serkor1%2FSLmetrics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/serkor1","download_url":"https://codeload.github.com/serkor1/SLmetrics/tar.gz/refs/heads/development","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serkor1%2FSLmetrics/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29596127,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-18T20:59:56.587Z","status":"ssl_error","status_checked_at":"2026-02-18T20:58:41.434Z","response_time":162,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["armadillo","armadillo-library","artificial-intelligence","cpp","cran","cran-r","data-analysis","data-science","eigen3","machine-learning","performance-metrics","r","r-package","r-stats","rcpp","rcpparmadillo","rcppeigen","statistics","supervised-learning"],"created_at":"2025-10-22T04:28:40.373Z","updated_at":"2026-02-18T21:03:13.698Z","avatar_url":"https://github.com/serkor1.png","language":"C++","funding_links":["https://github.com/sponsors/serkor1"],"categories":[],"sub_categories":[],"readme":"\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n# {SLmetrics}: Machine learning performance evaluation on steroids \u003cimg src=\"man/figures/logo.png\" align=\"right\" height=\"150\" alt=\"\" /\u003e\n\n\u003c!-- badges: start --\u003e\n\n[![CRAN\nstatus](https://www.r-pkg.org/badges/version/SLmetrics)](https://CRAN.R-project.org/package=SLmetrics)\n[![CRAN RStudio mirror\ndownloads](https://cranlogs.r-pkg.org/badges/last-month/SLmetrics?color=blue)](https://r-pkg.org/pkg/SLmetrics)\n[![Lifecycle:\nexperimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)\n[![R-CMD-check](https://github.com/serkor1/SLmetrics/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/serkor1/SLmetrics/actions/workflows/R-CMD-check.yaml)\n[![R-hub](https://github.com/serkor1/SLmetrics/actions/workflows/rhub.yaml/badge.svg)](https://github.com/serkor1/SLmetrics/actions/workflows/rhub.yaml)\n[![Gitbook](https://github.com/serkor1/SLmetrics/actions/workflows/online-docs.yaml/badge.svg)](https://github.com/serkor1/SLmetrics/actions/workflows/online-docs.yaml)\n[![codecov](https://codecov.io/gh/serkor1/SLmetrics/branch/development/graph/badge.svg?token=X2osJDSRlN)](https://app.codecov.io/gh/serkor1/SLmetrics)\n[![CodeFactor](https://www.codefactor.io/repository/github/serkor1/slmetrics/badge)](https://www.codefactor.io/repository/github/serkor1/slmetrics)\n\u003c!-- badges: end --\u003e\n\n[{SLmetrics}](https://slmetrics-docs.gitbook.io/v1) is a lightweight `R`\npackage written in `C++` and [{Rcpp}](https://github.com/RcppCore/Rcpp)\nfor *memory-efficient* and *lightning-fast* machine learning performance\nevaluation; it’s like using a supercharged\n[{yardstick}](https://github.com/tidymodels/yardstick) but without the\nrisk of soft to super-hard deprecations.\n[{SLmetrics}](https://slmetrics-docs.gitbook.io/v1) covers both\nregression and classification metrics and provides (almost) the same\narray of metrics as\n[{scikit-learn}](https://github.com/scikit-learn/scikit-learn) and\n[{PyTorch}](https://github.com/pytorch/pytorch) all without\n[{reticulate}](https://github.com/rstudio/reticulate) and the Python\ncompile-run-(crash)-debug cycle.\n\nDepending on the mood and alignment of planets\n[{SLmetrics}](https://slmetrics-docs.gitbook.io/v1) stands for\nSupervised Learning metrics, or Statistical Learning metrics. If\n[{SLmetrics}](https://slmetrics-docs.gitbook.io/v1) catches on, the\nlatter will be the core philosophy and include unsupervised learning\nmetrics. If not, then it will remain a {pkg} for Supervised Learning\nmetrics, and a sandbox for me to develop my `C++` skills.\n\n## :rocket: Gettting Started\n\nBelow you’ll find instructions to install\n[{SLmetrics}](https://slmetrics-docs.gitbook.io/v1) and get started with\nyour first metric, the Root Mean Squared Error (RMSE).\n\n### :package: CRAN version\n\n``` r\n## install latest CRAN build\ninstall.packages(\"SLmetrics\")\n```\n\n### :books: Basic Usage\n\nBelow is a minimal example demonstrating how to compute both unweighted\nand weighted RMSE.\n\n``` r\nlibrary(SLmetrics)\n\nactual    \u003c- c(10.2, 12.5, 14.1)\npredicted \u003c- c(9.8, 11.5, 14.2)\nweights   \u003c- c(0.2, 0.5, 0.3)\n\ncat(\n  \"Root Mean Squared Error\", rmse(\n    actual    = actual,\n    predicted = predicted,\n  ),\n  \"Root Mean Squared Error (weighted)\", weighted.rmse(\n    actual    = actual,\n    predicted = predicted,\n    w         = weights\n  ),\n  sep = \"\\n\"\n)\n#\u003e Root Mean Squared Error\n#\u003e 0.6244998\n#\u003e Root Mean Squared Error (weighted)\n#\u003e 0.7314369\n```\n\nThat’s all! Now you can explore the rest of this README for in-depth\nusage, performance comparisons, and more details about\n[{SLmetrics}](https://slmetrics-docs.gitbook.io/v1).\n\n## :information_source: Why?\n\nMachine learning can be a complicated task; the steps from feature\nengineering to model deployment require carefully measured actions and\ndecisions. One low-hanging fruit to simplify this process is\n*performance evaluation*.\n\nAt its core, performance evaluation is essentially just comparing two\nvectors - a programmatically and, at times, mathematically trivial step\nin the machine learning pipeline, but one that can become complicated\ndue to:\n\n1.  Dependencies and potential deprecations\n2.  Needlessly complex or repetitive arguments  \n3.  Performance and memory bottlenecks at scale\n\n[{SLmetrics}](https://slmetrics-docs.gitbook.io/v1) solves these issues\nby being:\n\n1.  **Fast:** Powered by `C++` and\n    [{Rcpp}](https://github.com/RcppCore/Rcpp)  \n2.  **Memory-efficient:** Everything is structured around pointers and\n    references\n3.  **Lightweight:** Only depends on\n    [{Rcpp}](https://github.com/RcppCore/Rcpp) and\n    [{lattice}](https://github.com/deepayan/lattice)\n4.  **Simple:** S3-based, minimal overhead, and flexible inputs\n\nPerformance evaluation should be plug-and-play and “just work” out of\nthe box - there’s no need to worry about *quasiquations*,\n*dependencies*, *deprecations*, or variations of the same functions\nrelative to their arguments when using\n[{SLmetrics}](https://slmetrics-docs.gitbook.io/v1).\n\n## :zap: Performance Comparison\n\nOne, obviously, can’t build an `R`-package on `C++` and\n[{Rcpp}](https://github.com/RcppCore/Rcpp) without a proper pissing\ncontest at the urinals - below is a comparison in execution time and\nmemory efficiency of two simple cases that any {pkg} should be able to\nhandle gracefully; computing a 2 x 2 confusion matrix and computing the\nRMSE[^1].\n\n### :fast_forward: Speed comparison\n\n\u003cimg src=\".meta/readme/README_files/figure-commonmark/plot%20speed-performance-1.png\"\nstyle=\"width:100.0%\" /\u003e\n\nAs shown in the chart,\n[{SLmetrics}](https://slmetrics-docs.gitbook.io/v1) maintains\nconsistently low(er) execution times across different sample sizes.\n\n### :floppy_disk: Memory-efficiency\n\nBelow are the results for garbage collections and total memory\nallocations when computing a 2×2 confusion matrix (N = 1e7) and RMSE (N\n= 1e7) [^2]. Notice that\n[{SLmetrics}](https://slmetrics-docs.gitbook.io/v1) requires no GC calls\nfor these operations.\n\n|  | Iterations | Garbage Collections \\[gc()\\] | gc() pr. second | Memory Allocation (MB) |\n|:---|---:|---:|---:|---:|\n| {SLmetrics} | 100 | 0 | 0.00 | 0 |\n| {yardstick} | 100 | 190 | 4.44 | 381 |\n| {MLmetrics} | 100 | 186 | 4.50 | 381 |\n| {mlr3measures} | 100 | 371 | 3.93 | 916 |\n\n2 x 2 Confusion Matrix (N = 1e7)\n\n|  | Iterations | Garbage Collections \\[gc()\\] | gc() pr. second | Memory Allocation (MB) |\n|:---|---:|---:|---:|---:|\n| {SLmetrics} | 100 | 0 | 0.00 | 0 |\n| {yardstick} | 100 | 149 | 4.30 | 420 |\n| {MLmetrics} | 100 | 15 | 2.00 | 76 |\n| {mlr3measures} | 100 | 12 | 1.29 | 76 |\n\nRMSE (N = 1e7)\n\nIn both tasks, [{SLmetrics}](https://slmetrics-docs.gitbook.io/v1)\nremains extremely memory-efficient, even at large sample sizes.\n\n\u003e \\[!IMPORTANT\\]\n\u003e\n\u003e From [{bench}](https://github.com/r-lib/bench) documentation: *Total\n\u003e amount of memory allocated by R while running the expression. Memory\n\u003e allocated outside the R heap, e.g. by `malloc()` or new directly is\n\u003e not tracked, take care to avoid misinterpreting the results if running\n\u003e code that may do this.*\n\n## :information_source: Basic usage\n\nIn its simplest form,\n[{SLmetrics}](https://slmetrics-docs.gitbook.io/v1)-functions work\ndirectly with pairs of `\u003cnumeric\u003e` vectors (for regression) or\n`\u003cfactor\u003e` vectors (for classification). Below we demonstrate this on\ntwo well-known datasets, `mtcars` (regression) and `iris`\n(classification).\n\n### :books: Regression\n\nWe first fit a linear model to predict `mpg` in the `mtcars` dataset,\nthen compute the in-sample RMSE:\n\n``` r\n## Evaluate a linear model on mpg (mtcars)\nmodel \u003c- lm(mpg ~ ., data = mtcars)\nrmse(mtcars$mpg, fitted(model))\n#\u003e [1] 2.146905\n```\n\n### :books: Classification\n\nNow we recode the `iris` dataset into a binary problem (“virginica”\nvs. “others”) and fit a logistic regression. Then we generate predicted\nclasses, compute the confusion matrix and summarize it.\n\n``` r\n## 1) recode iris\n## to binary problem\niris$species_num \u003c- as.numeric(\n  iris$Species == \"virginica\"\n)\n\n## 2) fit the logistic\n## regression\nmodel \u003c- glm(\n  formula = species_num ~ Sepal.Length + Sepal.Width,\n  data    = iris,\n  family  = binomial(\n    link = \"logit\"\n  )\n)\n\n## 3) generate predicted\n## classes\npredicted \u003c- factor(\n  as.numeric(\n    predict(model, type = \"response\") \u003e 0.5\n  ),\n  levels = c(1,0),\n  labels = c(\"Virginica\", \"Others\")\n)\n\n## 4) generate actual\n## values as factor\nactual \u003c- factor(\n  x = iris$species_num,\n  levels = c(1,0),\n  labels = c(\"Virginica\", \"Others\")\n)\n```\n\n``` r\n## 4) generate\n## confusion matrix\nsummary(\n  confusion_matrix \u003c- cmatrix(\n    actual    = actual,\n    predicted = predicted\n  )\n)\n#\u003e Confusion Matrix (2 x 2) \n#\u003e ================================================================================\n#\u003e           Virginica Others\n#\u003e Virginica        35     15\n#\u003e Others           14     86\n#\u003e ================================================================================\n#\u003e Overall Statistics (micro average)\n#\u003e  - Accuracy:          0.81\n#\u003e  - Balanced Accuracy: 0.78\n#\u003e  - Sensitivity:       0.81\n#\u003e  - Specificity:       0.81\n#\u003e  - Precision:         0.81\n```\n\n## :information_source: Enable OpenMP\n\n\u003e \\[!IMPORTANT\\]\n\u003e\n\u003e OpenMP support in [{SLmetrics}](https://slmetrics-docs.gitbook.io/v1)\n\u003e is experimental. Use it with caution, as performance gains and\n\u003e stability may vary based on your system configuration and workload.\n\nYou can control OpenMP usage within\n[{SLmetrics}](https://slmetrics-docs.gitbook.io/v1) using `openmp.on()`\nand `openmp.off()` . Below are examples demonstrating how to enable and\ndisable OpenMP:\n\n``` r\n## enable OpenMP\nSLmetrics::openmp.on()\n#\u003e OpenMP enabled!\n\n## disable OpenMP\nSLmetrics::openmp.off()\n#\u003e OpenMP disabled!\n```\n\nTo illustrate the impact of OpenMP on performance, consider the\nfollowing benchmarks for calculating entropy on a 1,000,000 x 200 matrix\nover 100 iterations[^3].\n\n### :books: Entropy without OpenMP\n\n| Iterations | Runtime (sec) | Garbage Collections \\[gc()\\] | gc() pr. second | Memory Allocation (MB) |\n|---:|---:|---:|---:|---:|\n| 100 | 0.86 | 0 | 0 | 0 |\n\n1e6 x 200 matrix without OpenMP\n\n### :books: Entropy with OpenMP\n\n| Iterations | Runtime (sec) | Garbage Collections \\[gc()\\] | gc() pr. second | Memory Allocation (MB) |\n|---:|---:|---:|---:|---:|\n| 100 | 0.15 | 0 | 0 | 0 |\n\n1e6 x 200 matrix with OpenMP\n\n## :package: Install from source\n\n### Github release\n\n``` r\n## install github release\npak::pak(\n    pkg = \"serkor1/SLmetrics@*release\",\n    ask = FALSE\n)\n```\n\n### Nightly build\n\n#### Clone repository with submodules\n\n``` console\ngit clone --recurse-submodules https://github.com/serkor1/SLmetrics.git\n```\n\n#### Installing with build tools\n\n``` console\nmake build\n```\n\n#### Installing with {pak}\n\n``` r\n## install nightly build\npak::pak(\n    pkg = \".\",\n    ask = FALSE\n)\n```\n\n## :information_source: Code of Conduct\n\nPlease note that the [{SLmetrics}](https://slmetrics-docs.gitbook.io/v1)\nproject is released with a [Contributor Code of\nConduct](https://contributor-covenant.org/version/2/1/CODE_OF_CONDUCT.html).\nBy contributing to this project, you agree to abide by its terms.\n\n[^1]: The source code is available\n    [here](https://github.com/serkor1/SLmetrics/blob/d9b6cdbc1fccbdb0d45364b0fc37ebe953df30b9/data-raw/classification_performance.R)\n    and\n    [here](https://github.com/serkor1/SLmetrics/blob/d9b6cdbc1fccbdb0d45364b0fc37ebe953df30b9/data-raw/regression_performance.R).\n\n[^2]: The source code is available\n    [here](https://github.com/serkor1/SLmetrics/blob/d9b6cdbc1fccbdb0d45364b0fc37ebe953df30b9/data-raw/memory_performance.R).\n\n[^3]: The source code is available\n    [here](https://github.com/serkor1/SLmetrics/blob/d9b6cdbc1fccbdb0d45364b0fc37ebe953df30b9/data-raw/OpenMP_perfomance.R).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserkor1%2Fslmetrics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fserkor1%2Fslmetrics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserkor1%2Fslmetrics/lists"}