{"id":7792,"date":"2023-10-04T10:58:27","date_gmt":"2023-10-04T18:58:27","guid":{"rendered":"https:\/\/live-cometml.pantheonsite.io\/?p=7792"},"modified":"2025-04-24T17:06:04","modified_gmt":"2025-04-24T17:06:04","slug":"hyperparameter-tuning-in-comet","status":"publish","type":"post","link":"https:\/\/www.comet.com\/site\/blog\/hyperparameter-tuning-in-comet\/","title":{"rendered":"Hyperparameter Tuning in Comet"},"content":{"rendered":"\n<link rel=\"canonical\" href=\"https:\/\/www.comet.com\/site\/blog\/hyperparameter-tuning-in-comet\">\n\n\n\n<div class=\"fi fj fk fl fm\">\n<div class=\"ab ca\">\n<div class=\"ch bg eu ev ew ex\">\n<figure class=\"mr ms mt mu mv mw mo mp paragraph-image\">\n<div class=\"mx my eb mz bg na\" tabindex=\"0\" role=\"button\">\n<figure><img loading=\"lazy\" decoding=\"async\" class=\"bg nb nc c\" role=\"presentation\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:700\/0*m0F4yTHUl6hCfXSs\" alt=\"\" width=\"700\" height=\"467\"><\/figure><div class=\"mo mp mq\"><picture><\/picture><\/div>\n<\/div><figcaption class=\"nd ne nf mo mp ng nh be b bf z dv\" data-selectable-paragraph=\"\">Photo by <a class=\"af ni\" href=\"https:\/\/unsplash.com\/@holawalterlee?utm_source=medium&amp;utm_medium=referral\" target=\"_blank\" rel=\"noopener ugc nofollow\">Walter Lee Olivares de la Cruz<\/a> on <a class=\"af ni\" href=\"https:\/\/unsplash.com\/?utm_source=medium&amp;utm_medium=referral\" target=\"_blank\" rel=\"noopener ugc nofollow\">Unsplash<\/a><\/figcaption><\/figure>\n<p id=\"38f3\" class=\"pw-post-body-paragraph nj nk fp be b gs nl nm nn gv no np nq nr ns nt nu nv nw nx ny nz oa ob oc od fi bj\" data-selectable-paragraph=\"\">Hyperparameter tuning is one of the most important tasks in a Data Science project lifecycle because it determines the performance of our Machine Learning model.<\/p>\n<p id=\"f6c4\" class=\"pw-post-body-paragraph nj nk fp be b gs nl nm nn gv no np nq nr ns nt nu nv nw nx ny nz oa ob oc od fi bj\" data-selectable-paragraph=\"\">Many tools and strategies can be used to perform hyperparameter tuning, including (but not limited to) the following well-known Python libraries:<\/p>\n<ul class=\"\">\n<li id=\"8d2b\" class=\"nj nk fp be b gs nl nm nn gv no np nq nr oe nt nu nv of nx ny nz og ob oc od oh oi oj bj\" data-selectable-paragraph=\"\">Tree-based Pipeline Optimization Tool (TPOT)<\/li>\n<li id=\"1c0b\" class=\"nj nk fp be b gs ok nm nn gv ol np nq nr om nt nu nv on nx ny nz oo ob oc od oh oi oj bj\" data-selectable-paragraph=\"\">Hyperopt-Sklearn<\/li>\n<li id=\"630d\" class=\"nj nk fp be b gs ok nm nn gv ol np nq nr om nt nu nv on nx ny nz oo ob oc od oh oi oj bj\" data-selectable-paragraph=\"\">Auto-Sklearn<\/li>\n<\/ul>\n<p id=\"2a59\" class=\"pw-post-body-paragraph nj nk fp be b gs nl nm nn gv no np nq nr ns nt nu nv nw nx ny nz oa ob oc od fi bj\" data-selectable-paragraph=\"\">In this article, I focus on the <a class=\"af ni\" href=\"https:\/\/www.comet.com\/docs\/python-sdk\/Optimizer\/\" target=\"_blank\" rel=\"noopener ugc nofollow\">Comet Optimizer<\/a>, provided by <a class=\"af ni\" href=\"https:\/\/www.comet.com\/site\/\" target=\"_blank\" rel=\"noopener ugc nofollow\">Comet<\/a>. With respect to the previous libraries, Optimizer is already integrated with Comet Experiments, thus results of each test can be visualized directly in Comet.<\/p>\n<p id=\"46df\" class=\"pw-post-body-paragraph nj nk fp be b gs nl nm nn gv no np nq nr ns nt nu nv nw nx ny nz oa ob oc od fi bj\" data-selectable-paragraph=\"\"><a class=\"af ni\" href=\"https:\/\/www.comet.com\/\" target=\"_blank\" rel=\"noopener ugc nofollow\">Comet<\/a> is a platform for Machine Learning experimentation, which provides a variety of features. You can track experiments and their results, collaborate with other users, and optimize experiments using Comet\u2019s algorithms. When using Comet, you can compare datasets and code changes as they relate to experiments. <strong class=\"be op\">Trying to find the best dataset or the best model parameters? Comet can help.<\/strong><\/p>\n<p id=\"f678\" class=\"pw-post-body-paragraph nj nk fp be b gs nl nm nn gv no np nq nr ns nt nu nv nw nx ny nz oa ob oc od fi bj\" data-selectable-paragraph=\"\">In this article, I describe how to exploit Comet for hyperparameter tuning. The article is organized as follows:<\/p>\n<ul class=\"\">\n<li id=\"874c\" class=\"nj nk fp be b gs nl nm nn gv no np nq nr oe nt nu nv of nx ny nz og ob oc od oh oi oj bj\" data-selectable-paragraph=\"\">Overview of Comet Optimizer<\/li>\n<li id=\"1834\" class=\"nj nk fp be b gs ok nm nn gv ol np nq nr om nt nu nv on nx ny nz oo ob oc od oh oi oj bj\" data-selectable-paragraph=\"\">Configuration of Parameters<\/li>\n<li id=\"691b\" class=\"nj nk fp be b gs ok nm nn gv ol np nq nr om nt nu nv on nx ny nz oo ob oc od oh oi oj bj\" data-selectable-paragraph=\"\">Running Experiments<\/li>\n<li id=\"914e\" class=\"nj nk fp be b gs ok nm nn gv ol np nq nr om nt nu nv on nx ny nz oo ob oc od oh oi oj bj\" data-selectable-paragraph=\"\">Show Results<\/li>\n<\/ul>\n<h1 id=\"3206\" class=\"oq or fp be os ot ou gu ov ow ox gx oy oz pa pb pc pd pe pf pg ph pi pj pk pl bj\" data-selectable-paragraph=\"\">Overview of Comet Optimizer<\/h1>\n<p id=\"ead8\" class=\"pw-post-body-paragraph nj nk fp be b gs pm nm nn gv pn np nq nr po nt nu nv pp nx ny nz pq ob oc od fi bj\" data-selectable-paragraph=\"\">The Comet Optimizer is used to tune hyperparameters of a model by maximizing or minimizing a particular metric. The Comet Optimizer supports three different optimization algorithms including <em class=\"pr\">Grid<\/em>, <em class=\"pr\">Random<\/em>, and <em class=\"pr\">Bayes<\/em>. In addition Comet also provides a mechanism to specify your optimization algorithm. For details about each optimization algorithm, you can refer to the <a class=\"af ni\" href=\"https:\/\/www.comet.com\/docs\/python-sdk\/introduction-optimizer\/#optimizer-algorithms\" target=\"_blank\" rel=\"noopener ugc nofollow\">Comet official documentation<\/a>.<\/p>\n<p id=\"7d6a\" class=\"pw-post-body-paragraph nj nk fp be b gs nl nm nn gv no np nq nr ns nt nu nv nw nx ny nz oa ob oc od fi bj\" data-selectable-paragraph=\"\">The <code class=\"cw ps pt pu pv b\">Optimizer<\/code> class is the main class for hyperparameter tuning in Comet. I assume that you have already installed the <code class=\"cw ps pt pu pv b\">comet<\/code>Python package. If you have not installed it yet, you can refer to <a class=\"af ni\" href=\"https:\/\/towardsdatascience.com\/getting-started-with-comet-ml-549d44aff0c9\" target=\"_blank\" rel=\"noopener\">my previous article<\/a>.<\/p>\n<p id=\"a77d\" class=\"pw-post-body-paragraph nj nk fp be b gs nl nm nn gv no np nq nr ns nt nu nv nw nx ny nz oa ob oc od fi bj\" data-selectable-paragraph=\"\">Before creating an <code class=\"cw ps pt pu pv b\">Optimizer<\/code>, you should specify some configuration parameters, which include the optimization algorithm, the metric to be maximized\/minimized, the number of trials, and the parameters to be tested:<\/p>\n<pre class=\"mr ms mt mu mv pw pv px py ax pz bj\"><span id=\"237f\" class=\"qa or fp pv b ig qb qc l iz qd\" data-selectable-paragraph=\"\">config = {\"algorithm\": \"bayes\",\n       \"spec\": {\n       \"maxCombo\": 0,\n       \"objective\": \"minimize\",\n       \"metric\": \"loss\",\n       \"minSampleSize\": 100,\n       \"retryLimit\": 20,\n       \"retryAssignLimit\": 0,\n   },\n   \"trials\": 1,\n   \"parameters\": my_params,\n   \"name\": \"MY-OPTIMIZER\"\n}<\/span><\/pre>\n<\/div>\n<\/div>\n<\/div>\n\n\n\n<div class=\"fi fj fk fl fm\">\n<div class=\"ab ca\">\n<div class=\"ch bg eu ev ew ex\">\n<blockquote class=\"qm\"><p id=\"7dd4\" class=\"qn qo fp be qp qq qr qs qt qu qv od dv\" data-selectable-paragraph=\"\">Innovation and academia go hand-in-hand. <a class=\"af ni\" href=\"https:\/\/www.youtube.com\/watch?v=7XCsi64HLQ8.\" target=\"_blank\" rel=\"noopener ugc nofollow\">Listen to our own CEO Gideon Mendels chat with the Stanford MLSys Seminar Series team<\/a> about the future of MLOps and <a class=\"af ni\" href=\"https:\/\/www.comet.com\/site\/academics\/\" target=\"_blank\" rel=\"noopener ugc nofollow\">give the Comet platform a try for free!<\/a><\/p><\/blockquote>\n<\/div>\n<\/div>\n<\/div>\n\n\n\n<div class=\"fi fj fk fl fm\">\n<div class=\"ab ca\">\n<div class=\"ch bg eu ev ew ex\">\n<h1 id=\"0bf7\" class=\"oq or fp be os ot qw gu ov ow qx gx oy oz qy pb pc pd qz pf pg ph ra pj pk pl bj\" data-selectable-paragraph=\"\">Configuration of Parameters<\/h1>\n<p id=\"426f\" class=\"pw-post-body-paragraph nj nk fp be b gs pm nm nn gv pn np nq nr po nt nu nv pp nx ny nz pq ob oc od fi bj\" data-selectable-paragraph=\"\">Similar to the other tools for hyperparameter tuning, the Comet Optimizer requires specifying for each parameter to be tested the range of possible values, with a syntax depending on the type of parameter (integer, categorical, and so on). For example, for an <strong class=\"be op\">integer<\/strong>, the following configuration should be used:<\/p>\n<pre class=\"mr ms mt mu mv pw pv px py ax pz bj\"><span id=\"c4d1\" class=\"qa or fp pv b ig qb qc l iz qd\" data-selectable-paragraph=\"\">{\"PARAMETER-NAME\":\n  {\"type\": \"integer\",\n   \"scalingType\": \"linear\" | \"uniform\" | \"normal\" | \"loguniform\" | \"lognormal\",\n   \"min\": MY-MIN-VALUE,\n   \"max\": MY-MAX-VALUE,\n  }<\/span><\/pre>\n<p id=\"90f7\" class=\"pw-post-body-paragraph nj nk fp be b gs nl nm nn gv no np nq nr ns nt nu nv nw nx ny nz oa ob oc od fi bj\" data-selectable-paragraph=\"\">And for a <strong class=\"be op\">categorical parameter<\/strong>, the following configuration should be used:<\/p>\n<pre class=\"mr ms mt mu mv pw pv px py ax pz bj\"><span id=\"16a8\" class=\"qa or fp pv b ig qb qc l iz qd\" data-selectable-paragraph=\"\">{\"PARAMETER-NAME\":\n  {\"type\": \"categorical\",\n   \"values\": [\"LIST\", \"OF\", \"CATEGORIES\"]\n  }\n }<\/span><\/pre>\n<p id=\"41a6\" class=\"pw-post-body-paragraph nj nk fp be b gs nl nm nn gv no np nq nr ns nt nu nv nw nx ny nz oa ob oc od fi bj\" data-selectable-paragraph=\"\">For example, to tune a scikit-learn K-Neighbors Classifier you could use the following parameter configuration:<\/p>\n<pre class=\"mr ms mt mu mv pw pv px py ax pz bj\"><span id=\"f7f6\" class=\"qa or fp pv b ig qb qc l iz qd\" data-selectable-paragraph=\"\">my_params = {\n   '<strong class=\"pv fz\">n_neighbors<\/strong>':{\n       \"type\"         : \"integer\",\n       \"scalingType\"  : \"linear\",\n       \"min\"          : 3,\n       \"max\"          : 8,\n       },<\/span><span id=\"d221\" class=\"qa or fp pv b ig rb qc l iz qd\" data-selectable-paragraph=\"\">   '<strong class=\"pv fz\">weights<\/strong>':{\n       \"type\"         : \"categorical\",\n       \"values\"       : ['uniform', 'distance'],\n   },\n   '<strong class=\"pv fz\">metric<\/strong>': {\n       \"type\"         : \"categorical\",\n       \"values\"       : ['euclidean', 'manhattan', 'chebyshev', 'minkowski']\n   },\n   '<strong class=\"pv fz\">algorithm<\/strong>': {\n       \"type\"         : \"categorical\",\n       \"values\"       : ['ball_tree', 'kd_tree']\n   }\n}<\/span><\/pre>\n<h1 id=\"7109\" class=\"oq or fp be os ot ou gu ov ow ox gx oy oz pa pb pc pd pe pf pg ph pi pj pk pl bj\" data-selectable-paragraph=\"\">Running Experiments<\/h1>\n<p id=\"9efb\" class=\"pw-post-body-paragraph nj nk fp be b gs pm nm nn gv pn np nq nr po nt nu nv pp nx ny nz pq ob oc od fi bj\" data-selectable-paragraph=\"\">You can create an <code class=\"cw ps pt pu pv b\">Optimizer<\/code> object as follows:<\/p>\n<pre class=\"mr ms mt mu mv pw pv px py ax pz bj\"><span id=\"a3f5\" class=\"qa or fp pv b ig qb qc l iz qd\" data-selectable-paragraph=\"\">from comet_ml import Optimizer<\/span><span id=\"b560\" class=\"qa or fp pv b ig rb qc l iz qd\" data-selectable-paragraph=\"\">opt = Optimizer(config,\n   api_key=\"MY-API-KEY\",\n   project_name=\"MY-PROJECT-NAME\",\n   workspace=\"MY-WORKSPACE\")<\/span><\/pre>\n<p id=\"b17a\" class=\"pw-post-body-paragraph nj nk fp be b gs nl nm nn gv no np nq nr ns nt nu nv nw nx ny nz oa ob oc od fi bj\" data-selectable-paragraph=\"\">A Comet Optimizer creates a different experiment for each combination of parameters to be tested. Thus, you can iterate over the list of experiments and fit a new model for each experiment.<\/p>\n<p id=\"012f\" class=\"pw-post-body-paragraph nj nk fp be b gs nl nm nn gv no np nq nr ns nt nu nv nw nx ny nz oa ob oc od fi bj\" data-selectable-paragraph=\"\">For example, for the K-Neighbors classifier of the previous example, you can write the following code:<\/p>\n<pre class=\"mr ms mt mu mv pw pv px py ax pz bj\"><span id=\"ce5d\" class=\"qa or fp pv b ig qb qc l iz qd\" data-selectable-paragraph=\"\">from sklearn.neighbors import KNeighborsClassifier\nfrom sklearn.metrics import f1_score, precision_score, recall_score<\/span><span id=\"d77e\" class=\"qa or fp pv b ig rb qc l iz qd\" data-selectable-paragraph=\"\">for experiment in <strong class=\"pv fz\">opt.get_experiments()<\/strong>:\n    model = <strong class=\"pv fz\">KNeighborsClassifier<\/strong>(\n          n_neighbors=experiment.get_parameter(\"n_neighbors\"),\n          weights=experiment.get_parameter(\"weights\"),\n          metric=experiment.get_parameter(\"metric\"),\n          algorithm=experiment.get_parameter(\"algorithm\")\n    )\n    loss = model.fit(X_train, y_train)\n    experiment.log_metric(\"loss\", loss)<\/span><span id=\"bcfc\" class=\"qa or fp pv b ig rb qc l iz qd\" data-selectable-paragraph=\"\">    y_pred = model.predict(X_test)\n    f1 = f1_score(y_test, y_pred)\n    precision = precision_score(y_test, y_pred)\n    recall = recall_score(y_test, y_pred)<\/span><span id=\"b4be\" class=\"qa or fp pv b ig rb qc l iz qd\" data-selectable-paragraph=\"\">    experiment.log_metric(\"f1\", f1)\n    experiment.log_metric(\"precision\", precision)\n    experiment.log_metric(\"recall\", recall)<\/span><\/pre>\n<p id=\"423b\" class=\"pw-post-body-paragraph nj nk fp be b gs nl nm nn gv no np nq nr ns nt nu nv nw nx ny nz oa ob oc od fi bj\" data-selectable-paragraph=\"\">In the previous example, for each experiment, precision, recall, and f1-score are calculated and logged through the <code class=\"cw ps pt pu pv b\">log_metric()<\/code> function.<\/p>\n<h1 id=\"4a0d\" class=\"oq or fp be os ot ou gu ov ow ox gx oy oz pa pb pc pd pe pf pg ph pi pj pk pl bj\" data-selectable-paragraph=\"\">Show Results<\/h1>\n<p id=\"6cd3\" class=\"pw-post-body-paragraph nj nk fp be b gs pm nm nn gv pn np nq nr po nt nu nv pp nx ny nz pq ob oc od fi bj\" data-selectable-paragraph=\"\">When all the experiments finish, you can view results in Comet. For each experiment, you can view the configuration parameter as well as the performance metric, as shown in the following Figure:<\/p>\n<figure class=\"mr ms mt mu mv mw mo mp paragraph-image\">\n<div class=\"mx my eb mz bg na\" tabindex=\"0\" role=\"button\">\n<figure><img loading=\"lazy\" decoding=\"async\" class=\"bg nb nc c\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:700\/1*0JfvD-u-l3N_BIzndUAT_w.png\" alt=\"Hyperparameter Tuning in Comet\" width=\"700\" height=\"238\"><\/figure><div class=\"mo mp rc\"><picture><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/format:webp\/1*0JfvD-u-l3N_BIzndUAT_w.png 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/format:webp\/1*0JfvD-u-l3N_BIzndUAT_w.png 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/format:webp\/1*0JfvD-u-l3N_BIzndUAT_w.png 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/format:webp\/1*0JfvD-u-l3N_BIzndUAT_w.png 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/format:webp\/1*0JfvD-u-l3N_BIzndUAT_w.png 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/format:webp\/1*0JfvD-u-l3N_BIzndUAT_w.png 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1400\/format:webp\/1*0JfvD-u-l3N_BIzndUAT_w.png 1400w\" type=\"image\/webp\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 700px\"><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/1*0JfvD-u-l3N_BIzndUAT_w.png 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/1*0JfvD-u-l3N_BIzndUAT_w.png 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/1*0JfvD-u-l3N_BIzndUAT_w.png 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/1*0JfvD-u-l3N_BIzndUAT_w.png 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/1*0JfvD-u-l3N_BIzndUAT_w.png 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/1*0JfvD-u-l3N_BIzndUAT_w.png 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1400\/1*0JfvD-u-l3N_BIzndUAT_w.png 1400w\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 700px\" data-testid=\"og\"><\/picture><\/div>\n<\/div>\n<figcaption class=\"nd ne nf mo mp ng nh be b bf z dv\" data-selectable-paragraph=\"\">Image by Author<\/figcaption>\n<\/figure>\n<p id=\"5de7\" class=\"pw-post-body-paragraph nj nk fp be b gs nl nm nn gv no np nq nr ns nt nu nv nw nx ny nz oa ob oc od fi bj\" data-selectable-paragraph=\"\">In addition, you can build a panel with a specific metric for all the experiments. For example, the following Figure shows the precision for all the experiments:<\/p>\n<figure class=\"mr ms mt mu mv mw mo mp paragraph-image\">\n<div class=\"mx my eb mz bg na\" tabindex=\"0\" role=\"button\">\n<figure><img loading=\"lazy\" decoding=\"async\" class=\"bg nb nc c\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:700\/1*jsmKOHKAbky0ini3duNVNQ.png\" alt=\"An example of panel in Comet\" width=\"700\" height=\"533\"><\/figure><div class=\"mo mp rd\"><picture><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/format:webp\/1*jsmKOHKAbky0ini3duNVNQ.png 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/format:webp\/1*jsmKOHKAbky0ini3duNVNQ.png 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/format:webp\/1*jsmKOHKAbky0ini3duNVNQ.png 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/format:webp\/1*jsmKOHKAbky0ini3duNVNQ.png 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/format:webp\/1*jsmKOHKAbky0ini3duNVNQ.png 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/format:webp\/1*jsmKOHKAbky0ini3duNVNQ.png 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1400\/format:webp\/1*jsmKOHKAbky0ini3duNVNQ.png 1400w\" type=\"image\/webp\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 700px\"><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/1*jsmKOHKAbky0ini3duNVNQ.png 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/1*jsmKOHKAbky0ini3duNVNQ.png 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/1*jsmKOHKAbky0ini3duNVNQ.png 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/1*jsmKOHKAbky0ini3duNVNQ.png 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/1*jsmKOHKAbky0ini3duNVNQ.png 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/1*jsmKOHKAbky0ini3duNVNQ.png 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1400\/1*jsmKOHKAbky0ini3duNVNQ.png 1400w\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 700px\" data-testid=\"og\"><\/picture><\/div>\n<\/div>\n<figcaption class=\"nd ne nf mo mp ng nh be b bf z dv\" data-selectable-paragraph=\"\">Image by Author<\/figcaption>\n<\/figure>\n<p id=\"761c\" class=\"pw-post-body-paragraph nj nk fp be b gs nl nm nn gv no np nq nr ns nt nu nv nw nx ny nz oa ob oc od fi bj\" data-selectable-paragraph=\"\">I have highlighted the specific bar with the following parameters:<\/p>\n<ul class=\"\">\n<li id=\"d8cf\" class=\"nj nk fp be b gs nl nm nn gv no np nq nr oe nt nu nv of nx ny nz og ob oc od oh oi oj bj\" data-selectable-paragraph=\"\">n_neighbors = 4<\/li>\n<li id=\"7931\" class=\"nj nk fp be b gs ok nm nn gv ol np nq nr om nt nu nv on nx ny nz oo ob oc od oh oi oj bj\" data-selectable-paragraph=\"\">weight = uniform<\/li>\n<li id=\"46dd\" class=\"nj nk fp be b gs ok nm nn gv ol np nq nr om nt nu nv on nx ny nz oo ob oc od oh oi oj bj\" data-selectable-paragraph=\"\">algorithm = ball_tree<\/li>\n<\/ul>\n<p id=\"42a0\" class=\"pw-post-body-paragraph nj nk fp be b gs nl nm nn gv no np nq nr ns nt nu nv nw nx ny nz oa ob oc od fi bj\" data-selectable-paragraph=\"\">By comparing all the results, you can easily choose the best parameters for your model, and use them in production.<\/p>\n<h1 id=\"c04c\" class=\"oq or fp be os ot ou gu ov ow ox gx oy oz pa pb pc pd pe pf pg ph pi pj pk pl bj\" data-selectable-paragraph=\"\">Summary<\/h1>\n<p id=\"2a5a\" class=\"pw-post-body-paragraph nj nk fp be b gs pm nm nn gv pn np nq nr po nt nu nv pp nx ny nz pq ob oc od fi bj\" data-selectable-paragraph=\"\">Congratulations! You have just learned how to tune hyperparameters in Comet! You can just exploit the ready-to-use <code class=\"cw ps pt pu pv b\">Optimizer<\/code> class! For more details, you can read the <a class=\"af ni\" href=\"https:\/\/www.comet.com\/docs\/python-sdk\/introduction-optimizer\/#optimizer\" target=\"_blank\" rel=\"noopener ugc nofollow\">Comet documentation<\/a>.<\/p>\n<p id=\"6114\" class=\"pw-post-body-paragraph nj nk fp be b gs nl nm nn gv no np nq nr ns nt nu nv nw nx ny nz oa ob oc od fi bj\" data-selectable-paragraph=\"\">There are many other things you can do with Comet, such as using it in conjunction with <a class=\"af ni\" href=\"https:\/\/about.gitlab.com\/\" target=\"_blank\" rel=\"noopener ugc nofollow\">Gitlab<\/a>, as I described in <a class=\"af ni\" href=\"https:\/\/heartbeat.comet.ml\/empowering-comet-with-gitlab-3455f1f54f5d\" target=\"_blank\" rel=\"noopener ugc nofollow\">my previous article<\/a>.<\/p>\n<p id=\"0e4a\" class=\"pw-post-body-paragraph nj nk fp be b gs nl nm nn gv no np nq nr ns nt nu nv nw nx ny nz oa ob oc od fi bj\" data-selectable-paragraph=\"\">Now you just have to try it \u2014 have fun!<\/p>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Photo by Walter Lee Olivares de la Cruz on Unsplash Hyperparameter tuning is one of the most important tasks in a Data Science project lifecycle because it determines the performance of our Machine Learning model. Many tools and strategies can be used to perform hyperparameter tuning, including (but not limited to) the following well-known Python [&hellip;]<\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"customer_name":"","customer_description":"","customer_industry":"","customer_technologies":"","customer_logo":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[9,7],"tags":[],"coauthors":[132],"class_list":["post-7792","post","type-post","status-publish","format-standard","hentry","category-product","category-tutorials"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.9 (Yoast SEO v25.9) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Hyperparameter Tuning in Comet - Comet<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.comet.com\/site\/blog\/hyperparameter-tuning-in-comet\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Hyperparameter Tuning in Comet\" \/>\n<meta property=\"og:description\" content=\"Photo by Walter Lee Olivares de la Cruz on Unsplash Hyperparameter tuning is one of the most important tasks in a Data Science project lifecycle because it determines the performance of our Machine Learning model. Many tools and strategies can be used to perform hyperparameter tuning, including (but not limited to) the following well-known Python [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.comet.com\/site\/blog\/hyperparameter-tuning-in-comet\/\" \/>\n<meta property=\"og:site_name\" content=\"Comet\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/cometdotml\" \/>\n<meta property=\"article:published_time\" content=\"2023-10-04T18:58:27+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-04-24T17:06:04+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/miro.medium.com\/v2\/resize:fit:700\/0*m0F4yTHUl6hCfXSs\" \/>\n<meta name=\"author\" content=\"Angelica Lo Duca\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@Cometml\" \/>\n<meta name=\"twitter:site\" content=\"@Cometml\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Angelica Lo Duca\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Hyperparameter Tuning in Comet - Comet","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.comet.com\/site\/blog\/hyperparameter-tuning-in-comet\/","og_locale":"en_US","og_type":"article","og_title":"Hyperparameter Tuning in Comet","og_description":"Photo by Walter Lee Olivares de la Cruz on Unsplash Hyperparameter tuning is one of the most important tasks in a Data Science project lifecycle because it determines the performance of our Machine Learning model. Many tools and strategies can be used to perform hyperparameter tuning, including (but not limited to) the following well-known Python [&hellip;]","og_url":"https:\/\/www.comet.com\/site\/blog\/hyperparameter-tuning-in-comet\/","og_site_name":"Comet","article_publisher":"https:\/\/www.facebook.com\/cometdotml","article_published_time":"2023-10-04T18:58:27+00:00","article_modified_time":"2025-04-24T17:06:04+00:00","og_image":[{"url":"https:\/\/miro.medium.com\/v2\/resize:fit:700\/0*m0F4yTHUl6hCfXSs","type":"","width":"","height":""}],"author":"Angelica Lo Duca","twitter_card":"summary_large_image","twitter_creator":"@Cometml","twitter_site":"@Cometml","twitter_misc":{"Written by":"Angelica Lo Duca","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.comet.com\/site\/blog\/hyperparameter-tuning-in-comet\/#article","isPartOf":{"@id":"https:\/\/www.comet.com\/site\/blog\/hyperparameter-tuning-in-comet\/"},"author":{"name":"Team Comet Digital","@id":"https:\/\/www.comet.com\/site\/#\/schema\/person\/6266601170c60a7a82b3e0043fbe8ddf"},"headline":"Hyperparameter Tuning in Comet","datePublished":"2023-10-04T18:58:27+00:00","dateModified":"2025-04-24T17:06:04+00:00","mainEntityOfPage":{"@id":"https:\/\/www.comet.com\/site\/blog\/hyperparameter-tuning-in-comet\/"},"wordCount":673,"publisher":{"@id":"https:\/\/www.comet.com\/site\/#organization"},"image":{"@id":"https:\/\/www.comet.com\/site\/blog\/hyperparameter-tuning-in-comet\/#primaryimage"},"thumbnailUrl":"https:\/\/miro.medium.com\/v2\/resize:fit:700\/0*m0F4yTHUl6hCfXSs","articleSection":["Product","Tutorials"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.comet.com\/site\/blog\/hyperparameter-tuning-in-comet\/","url":"https:\/\/www.comet.com\/site\/blog\/hyperparameter-tuning-in-comet\/","name":"Hyperparameter Tuning in Comet - Comet","isPartOf":{"@id":"https:\/\/www.comet.com\/site\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.comet.com\/site\/blog\/hyperparameter-tuning-in-comet\/#primaryimage"},"image":{"@id":"https:\/\/www.comet.com\/site\/blog\/hyperparameter-tuning-in-comet\/#primaryimage"},"thumbnailUrl":"https:\/\/miro.medium.com\/v2\/resize:fit:700\/0*m0F4yTHUl6hCfXSs","datePublished":"2023-10-04T18:58:27+00:00","dateModified":"2025-04-24T17:06:04+00:00","breadcrumb":{"@id":"https:\/\/www.comet.com\/site\/blog\/hyperparameter-tuning-in-comet\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.comet.com\/site\/blog\/hyperparameter-tuning-in-comet\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.comet.com\/site\/blog\/hyperparameter-tuning-in-comet\/#primaryimage","url":"https:\/\/miro.medium.com\/v2\/resize:fit:700\/0*m0F4yTHUl6hCfXSs","contentUrl":"https:\/\/miro.medium.com\/v2\/resize:fit:700\/0*m0F4yTHUl6hCfXSs"},{"@type":"BreadcrumbList","@id":"https:\/\/www.comet.com\/site\/blog\/hyperparameter-tuning-in-comet\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.comet.com\/site\/"},{"@type":"ListItem","position":2,"name":"Hyperparameter Tuning in Comet"}]},{"@type":"WebSite","@id":"https:\/\/www.comet.com\/site\/#website","url":"https:\/\/www.comet.com\/site\/","name":"Comet","description":"Build Better Models Faster","publisher":{"@id":"https:\/\/www.comet.com\/site\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.comet.com\/site\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.comet.com\/site\/#organization","name":"Comet ML, Inc.","alternateName":"Comet","url":"https:\/\/www.comet.com\/site\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.comet.com\/site\/#\/schema\/logo\/image\/","url":"https:\/\/www.comet.com\/site\/wp-content\/uploads\/2025\/01\/logo_comet_square.png","contentUrl":"https:\/\/www.comet.com\/site\/wp-content\/uploads\/2025\/01\/logo_comet_square.png","width":310,"height":310,"caption":"Comet ML, Inc."},"image":{"@id":"https:\/\/www.comet.com\/site\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/cometdotml","https:\/\/x.com\/Cometml","https:\/\/www.youtube.com\/channel\/UCmN63HKvfXSCS-UwVwmK8Hw"]},{"@type":"Person","@id":"https:\/\/www.comet.com\/site\/#\/schema\/person\/6266601170c60a7a82b3e0043fbe8ddf","name":"Team Comet Digital","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.comet.com\/site\/#\/schema\/person\/image\/4f0c0a8cc7c0e87c636ff6a420a6647c","url":"https:\/\/www.comet.com\/site\/wp-content\/uploads\/2023\/08\/Screen-Shot-2023-08-12-at-8.58.50-AM-96x96.png","contentUrl":"https:\/\/www.comet.com\/site\/wp-content\/uploads\/2023\/08\/Screen-Shot-2023-08-12-at-8.58.50-AM-96x96.png","caption":"Team Comet Digital"},"sameAs":["https:\/\/www.comet.ml\/"],"url":"https:\/\/www.comet.com\/site\/blog\/author\/teamcometdigital\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/posts\/7792","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/comments?post=7792"}],"version-history":[{"count":1,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/posts\/7792\/revisions"}],"predecessor-version":[{"id":15521,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/posts\/7792\/revisions\/15521"}],"wp:attachment":[{"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/media?parent=7792"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/categories?post=7792"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/tags?post=7792"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/coauthors?post=7792"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}