{"id":18014326,"url":"https://github.com/mlr-org/mlr3tuning","last_synced_at":"2025-04-04T15:11:00.789Z","repository":{"id":39542383,"uuid":"152228697","full_name":"mlr-org/mlr3tuning","owner":"mlr-org","description":"Hyperparameter optimization package of the mlr3 ecosystem","archived":false,"fork":false,"pushed_at":"2024-10-28T08:17:37.000Z","size":9112,"stargazers_count":54,"open_issues_count":6,"forks_count":5,"subscribers_count":17,"default_branch":"main","last_synced_at":"2024-10-30T05:59:53.306Z","etag":null,"topics":["bbotk","hyperparameter-optimization","hyperparameter-tuning","machine-learning","mlr3","optimization","r","r-package","tune","tuning"],"latest_commit_sha":null,"homepage":"https://mlr3tuning.mlr-org.com/","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mlr-org.png","metadata":{"funding":{"github":"mlr-org"},"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-10-09T09:59:47.000Z","updated_at":"2024-10-28T08:14:12.000Z","dependencies_parsed_at":"2023-09-30T20:02:17.842Z","dependency_job_id":"48d02177-44f6-4c74-aefd-c592a31ac092","html_url":"https://github.com/mlr-org/mlr3tuning","commit_stats":{"total_commits":779,"total_committers":14,"mean_commits":"55.642857142857146","dds":0.7150192554557124,"last_synced_commit":"a5b2e097ac2b6900482ec98eebee4f5129adb547"},"previous_names":[],"tags_count":35,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlr-org%2Fmlr3tuning","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlr-org%2Fmlr3tuning/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlr-org%2Fmlr3tuning/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlr-org%2Fmlr3tuning/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mlr-org","download_url":"https://codeload.github.com/mlr-org/mlr3tuning/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247198463,"owners_count":20900080,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["bbotk","hyperparameter-optimization","hyperparameter-tuning","machine-learning","mlr3","optimization","r","r-package","tune","tuning"],"created_at":"2024-10-30T04:07:47.619Z","updated_at":"2025-04-04T15:11:00.769Z","avatar_url":"https://github.com/mlr-org.png","language":"R","funding_links":["https://github.com/sponsors/mlr-org"],"categories":[],"sub_categories":[],"readme":"---\noutput: github_document\n---\n\n```{r, include = FALSE}\nlgr::get_logger(\"mlr3\")$set_threshold(\"warn\")\nlgr::get_logger(\"bbotk\")$set_threshold(\"warn\")\nset.seed(1)\noptions(\n    datatable.print.nrows = 10,\n    datatable.print.class = FALSE,\n    datatable.print.keys = FALSE,\n    width = 100)\n# mute load messages\nlibrary(\"mlr3tuning\")\n```\n\n# mlr3tuning \u003cimg src=\"man/figures/logo.png\" align=\"right\" width = \"120\" /\u003e\n\nPackage website: [release](https://mlr3tuning.mlr-org.com/) | [dev](https://mlr3tuning.mlr-org.com/dev/)\n\n\u003c!-- badges: start --\u003e\n[![r-cmd-check](https://github.com/mlr-org/mlr3tuning/actions/workflows/r-cmd-check.yml/badge.svg)](https://github.com/mlr-org/mlr3tuning/actions/workflows/r-cmd-check.yml)\n[![CRAN Status](https://www.r-pkg.org/badges/version-ago/mlr3tuning)](https://cran.r-project.org/package=mlr3tuning)\n[![StackOverflow](https://img.shields.io/badge/stackoverflow-mlr3-orange.svg)](https://stackoverflow.com/questions/tagged/mlr3)\n[![Mattermost](https://img.shields.io/badge/chat-mattermost-orange.svg)](https://lmmisld-lmu-stats-slds.srv.mwn.de/mlr_invite/)\n\u003c!-- badges: end --\u003e\n\n*mlr3tuning* is the hyperparameter optimization package of the [mlr3](https://mlr-org.com/) ecosystem.\nIt features highly configurable search spaces via the [paradox](https://github.com/mlr-org/paradox) package and finds optimal hyperparameter configurations for any mlr3 [learner](https://github.com/mlr-org/mlr3learners).\nmlr3tuning works with several optimization algorithms e.g. Random Search, Iterated Racing, Bayesian Optimization (in [mlr3mbo](https://github.com/mlr-org/mlr3mbo)) and Hyperband (in [mlr3hyperband](https://github.com/mlr-org/mlr3hyperband)).\nMoreover, it can [automatically](https://mlr3book.mlr-org.com/chapters/chapter4/hyperparameter_optimization.html#sec-autotuner) optimize learners and estimate the performance of optimized models with [nested resampling](https://mlr3book.mlr-org.com/chapters/chapter4/hyperparameter_optimization.html#sec-nested-resampling).\nThe package is built on the optimization framework [bbotk](https://github.com/mlr-org/bbotk).\n\n## Extension packages\n\nmlr3tuning is extended by the following packages.\n\n* [mlr3tuningspaces](https://github.com/mlr-org/mlr3tuningspaces) is a collection of search spaces from scientific articles for commonly used learners.\n* [mlr3hyperband](https://github.com/mlr-org/mlr3hyperband) adds the Hyperband and Successive Halving algorithm.\n* [mlr3mbo](https://github.com/mlr-org/mlr3mbo) adds Bayesian Optimization methods.\n\n## Resources\n\nThere are several sections about hyperparameter optimization in the [mlr3book](https://mlr3book.mlr-org.com).\n\n* Getting started with [hyperparameter optimization](https://mlr3book.mlr-org.com/chapters/chapter4/hyperparameter_optimization.html).\n* An overview of all tuners can be found on our [website](https://mlr-org.com/tuners.html).\n* [Tune](https://mlr3book.mlr-org.com/chapters/chapter4/hyperparameter_optimization.html#sec-model-tuning) a support vector machine on the Sonar data set.\n* Learn about [tuning spaces](https://mlr3book.mlr-org.com/chapters/chapter4/hyperparameter_optimization.html#sec-defining-search-spaces).\n* Estimate the model performance with [nested resampling](https://mlr3book.mlr-org.com/chapters/chapter4/hyperparameter_optimization.html#sec-nested-resampling).\n* Learn about [multi-objective optimization](https://mlr3book.mlr-org.com/chapters/chapter5/advanced_tuning_methods_and_black_box_optimization.html#sec-multi-metrics-tuning).\n* Simultaneously optimize hyperparameters and use [early stopping](https://mlr3book.mlr-org.com/chapters/chapter15/predsets_valid_inttune.html) with XGBoost.\n* [Automate](https://mlr3book.mlr-org.com/chapters/chapter4/hyperparameter_optimization.html#sec-autotuner) the tuning.\n\nThe [gallery](https://mlr-org.com/gallery-all-optimization.html) features a collection of case studies and demos about optimization.\n\n* Learn more advanced methods with the [Practical Tuning Series](https://mlr-org.com/gallery/series/2021-03-09-practical-tuning-series-tune-a-support-vector-machine/).\n* Learn about [hotstarting](https://mlr-org.com/gallery/optimization/2023-01-16-hotstart/) models.\n* Run the [default hyperparameter configuration](https://mlr-org.com/gallery/optimization/2023-01-31-default-configuration/) of learners as a baseline.\n* Use the [Hyperband](https://mlr-org.com/gallery/series/2023-01-15-hyperband-xgboost/) optimizer with different budget parameters.\n\nThe [cheatsheet](https://cheatsheets.mlr-org.com/mlr3tuning.pdf) summarizes the most important functions of mlr3tuning.\n\n## Installation\n\nInstall the last release from CRAN:\n\n```{r eval = FALSE}\ninstall.packages(\"mlr3tuning\")\n```\n\nInstall the development version from GitHub:\n\n```{r eval = FALSE}\nremotes::install_github(\"mlr-org/mlr3tuning\")\n```\n\n## Examples\n\nWe optimize the `cost` and `gamma` hyperparameters of a support vector machine on the [Sonar](https://mlr3.mlr-org.com/reference/mlr_tasks_sonar.html) data set.\n\n```{r}\nlibrary(\"mlr3learners\")\nlibrary(\"mlr3tuning\")\n\nlearner = lrn(\"classif.svm\",\n  cost  = to_tune(1e-5, 1e5, logscale = TRUE),\n  gamma = to_tune(1e-5, 1e5, logscale = TRUE),\n  kernel = \"radial\",\n  type = \"C-classification\"\n)\n```\n\nWe construct a tuning instance with the `ti()` function.\nThe tuning instance describes the tuning problem.\n\n```{r}\ninstance = ti(\n  task = tsk(\"sonar\"),\n  learner = learner,\n  resampling = rsmp(\"cv\", folds = 3),\n  measures = msr(\"classif.ce\"),\n  terminator = trm(\"none\")\n)\ninstance\n```\n\nWe select a simple grid search as the optimization algorithm.\n\n```{r}\ntuner = tnr(\"grid_search\", resolution = 5)\ntuner\n```\n\nTo start the tuning, we simply pass the tuning instance to the tuner.\n\n```{r}\ntuner$optimize(instance)\n```\n\nThe tuner returns the best hyperparameter configuration and the corresponding measured performance.\n\nThe archive contains all evaluated hyperparameter configurations.\n\n```{r}\nas.data.table(instance$archive)[, .(cost, gamma, classif.ce, batch_nr, resample_result)]\n```\n\nThe [mlr3viz](https://mlr3viz.mlr-org.com/) package visualizes tuning results.\n\n```{r, eval=FALSE}\nlibrary(mlr3viz)\n\nautoplot(instance, type = \"surface\")\n```\n\n```{r, eval=FALSE, echo=FALSE}\np = autoplot(instance, type = \"surface\")\nggplot2::ggsave(filename = \"plot.png\", plot = p, units = \"px\", width = 600,  height = 500, scale = 5)\n```\n\n\u003cimg src=\"man/figures/plot.png\"/\u003e\n\nWe fit a final model with optimized hyperparameters to make predictions on new data.\n\n```{r}\nlearner$param_set$values = instance$result_learner_param_vals\nlearner$train(tsk(\"sonar\"))\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmlr-org%2Fmlr3tuning","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmlr-org%2Fmlr3tuning","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmlr-org%2Fmlr3tuning/lists"}