{"id":4133,"date":"2022-10-20T13:32:35","date_gmt":"2022-10-20T21:32:35","guid":{"rendered":"https:\/\/live-cometml.pantheonsite.io\/?p=4133"},"modified":"2025-04-24T17:17:03","modified_gmt":"2025-04-24T17:17:03","slug":"keep-track-of-machine-learning-experiments-with-comet","status":"publish","type":"post","link":"https:\/\/www.comet.com\/site\/blog\/keep-track-of-machine-learning-experiments-with-comet\/","title":{"rendered":"Keep Track of Machine Learning Experiments With Comet"},"content":{"rendered":"\n<div class=\"ir is it iu iv\">\n<p id=\"0070\" class=\"pw-post-body-paragraph ld le iy bm b lf lg jz lh li lj kc lk ll lm ln lo lp lq lr ls lt lu lv lw lx ir ga\" data-selectable-paragraph=\"\">If you\u2019re a software developer, you\u2019ve probably heard of Git (a version control system that allows you to keep track of any changes you make to your code) and GitHub (a hosting platform for Git). But, it turns out that there is a similar platform for those of us in the machine learning and data science worlds.&nbsp;<a class=\"au lc\" href=\"https:\/\/www.comet.com\/site\/\" target=\"_blank\" rel=\"noopener ugc nofollow\">Comet<\/a>&nbsp;(the GitHub for machine learning models) provides tools to assist us with tasks such as model tracking and version control, as well as model production management. In this post, we will learn more about what Comet is and how Comet can assist us in tracking the progress of our machine learning models. Without further ado, let\u2019s get started!<\/p>\n<h2 id=\"19c7\" class=\"ly lz iy bm ma mb mc md me mf mg mh mi ke mj kf mk kh ml ki mm kk mn kl mo mp ga\">What is Comet?<\/h2>\n<p id=\"61fc\" class=\"pw-post-body-paragraph ld le iy bm b lf mq jz lh li mr kc lk ll ms ln lo lp mt lr ls lt mu lv lw lx ir ga\" data-selectable-paragraph=\"\"><a class=\"au lc\" href=\"https:\/\/www.comet.com\/site\/\" target=\"_blank\" rel=\"noopener ugc nofollow\">Comet<\/a>&nbsp;is a platform for managing and optimizing your machine learning lifecycle, from experiment tracking to model production monitoring. What that means \u2014 in simple terms \u2014 is that Comet allows you to compare and audit your machine learning model\u2019s experiments and artifacts (including your model hyperparameters, metrics, and more) in an optimal and effective manner.<\/p>\n<p id=\"2366\" class=\"pw-post-body-paragraph ld le iy bm b lf lg jz lh li lj kc lk ll lm ln lo lp lq lr ls lt lu lv lw lx ir ga\" data-selectable-paragraph=\"\">Consider the case in which you\u2019re building a classification model and want to tune it using&nbsp;<code class=\"fp mv mw mx my b\">GridSearchCV<\/code>. While tuning the model, you want to keep track of model metrics such as a precision score and the ROC-curve visualization. Instead of logging each metric manually in a notebook or spreadsheet, which is very inefficient, Comet enables you to automatically track and optimize all of these metrics without even batting an eye.<\/p>\n<p id=\"d1cd\" class=\"pw-post-body-paragraph ld le iy bm b lf lg jz lh li lj kc lk ll lm ln lo lp lq lr ls lt lu lv lw lx ir ga\" data-selectable-paragraph=\"\">Comet is an excellent tool for successfully organizing your machine learning model experiments. It offers several perks, including the ability to integrate with many common machine learning packages and platforms (e.g. TensorFlow, Keras, PyTorch, etc.), and is compatible with several mainstream data science and machine learning programming languages (e.g. Python, R, Java, etc.). And, it is completely free for individual use.<\/p>\n<h2 id=\"8bbd\" class=\"ly lz iy bm ma mb mc md me mf mg mh mi ke mj kf mk kh ml ki mm kk mn kl mo mp ga\">Who Can Use Comet?<\/h2>\n<p id=\"de14\" class=\"pw-post-body-paragraph ld le iy bm b lf mq jz lh li mr kc lk ll ms ln lo lp mt lr ls lt mu lv lw lx ir ga\" data-selectable-paragraph=\"\">While Comet is often used for enterprise business applications, it can also be extremely handy for small- and mid-scale personal projects. In fact, Comet is remarkably accessible to beginner, intermediate, and professional users alike, so, whatever your skill-level, don\u2019t be afraid to dive in!<\/p>\n<p id=\"b337\" class=\"pw-post-body-paragraph ld le iy bm b lf lg jz lh li lj kc lk ll lm ln lo lp lq lr ls lt lu lv lw lx ir ga\" data-selectable-paragraph=\"\">In what type of scenario might beginner-level individuals employ Comet? Say you\u2019re developing a model for a Kaggle competition and you want to keep track of each ROC-curve visualization as you modify the model\u2019s hyperparameters. Comet will help you to achieve this, and as a result, will help you obtain better model results, more efficiently.<\/p>\n<p id=\"971a\" class=\"pw-post-body-paragraph ld le iy bm b lf lg jz lh li lj kc lk ll lm ln lo lp lq lr ls lt lu lv lw lx ir ga\" data-selectable-paragraph=\"\">Now that we understand how Comet may be useful for your particular use-case, let\u2019s test it out and see what we can do with it.<\/p>\n<h2 id=\"c54d\" class=\"ly lz iy bm ma mb mc md me mf mg mh mi ke mj kf mk kh ml ki mm kk mn kl mo mp ga\">Creating Our First Model Tracking Experiment Demo With Comet<\/h2>\n<p id=\"6d14\" class=\"pw-post-body-paragraph ld le iy bm b lf mq jz lh li mr kc lk ll ms ln lo lp mt lr ls lt mu lv lw lx ir ga\" data-selectable-paragraph=\"\">After we\u2019ve fitted the first version of our model on the training set, and evaluated it on the validation set, it\u2019s time to start tuning the hyperparameters to ensure we\u2019re getting the best performance possible. This process is commonly referred to as an experiment, because each time we tune the model, we are testing how well it performs based on that particular set of hyperparameters.<\/p>\n<p id=\"e0e4\" class=\"pw-post-body-paragraph ld le iy bm b lf lg jz lh li lj kc lk ll lm ln lo lp lq lr ls lt lu lv lw lx ir ga\" data-selectable-paragraph=\"\">Keeping track of many iterations of experiments can be chaotic and time-consuming. Consider saving the confusion matrix for each set of hyperparameters passed to your model, and then trying to remember which matrix corresponded to which set of hyperparameters.<\/p>\n<p id=\"a8da\" class=\"pw-post-body-paragraph ld le iy bm b lf lg jz lh li lj kc lk ll lm ln lo lp lq lr ls lt lu lv lw lx ir ga\" data-selectable-paragraph=\"\">Comet can assist us in organizing and managing this process, and we\u2019ll do exactly this in our demo. We will use Comet to keep track of our experiments and then, among the experiments we\u2019ve tracked, we\u2019ll choose the optimal set of hyperparameters for our model.<\/p>\n<h2 id=\"c20d\" class=\"ly lz iy bm ma mb mc md me mf mg mh mi ke mj kf mk kh ml ki mm kk mn kl mo mp ga\">Dataset Used<\/h2>\n<p id=\"0508\" class=\"pw-post-body-paragraph ld le iy bm b lf mq jz lh li mr kc lk ll ms ln lo lp mt lr ls lt mu lv lw lx ir ga\" data-selectable-paragraph=\"\">For this classification task, I\u2019ll be utilizing a dataset that determines whether a customer is satisfied or dissatisfied with a product, based on a set of predictor variables. Now, without further ado, let\u2019s get started.<\/p>\n<h2 id=\"5920\" class=\"mz lz iy bm ma na nb nc me nd ne nf mi ll ng nh mk lp ni nj mm lt nk nl mo nm ga\" data-selectable-paragraph=\"\">Signing-up on Comet<\/h2>\n<p id=\"7ce4\" class=\"pw-post-body-paragraph ld le iy bm b lf mq jz lh li mr kc lk ll ms ln lo lp mt lr ls lt mu lv lw lx ir ga\" data-selectable-paragraph=\"\">The first step is to sign-up on the Comet platform in order to obtain an API key that will allow our code in our IDE to communicate with the Comet website. We can do so by clicking&nbsp;<a class=\"au lc\" href=\"\/signup\" target=\"_blank\" rel=\"noopener ugc nofollow\">here<\/a>. After we\u2019ve signed up and verified our account, we should see something like this in our dashboard:<\/p>\n<div class=\"kt ku do kv ce kw\" tabindex=\"0\" role=\"button\">\n<figure><img loading=\"lazy\" decoding=\"async\" class=\"ce kx ky c aligncenter\" role=\"presentation\" src=\"https:\/\/miro.medium.com\/max\/1050\/0*yO8EgXEJ3Uvo8uLi\" alt=\"\" width=\"700\" height=\"355\"><\/figure><p class=\"gl gm nn\" style=\"text-align: center;\"><picture><source srcset=\"https:\/\/miro.medium.com\/max\/640\/0*yO8EgXEJ3Uvo8uLi 640w, https:\/\/miro.medium.com\/max\/720\/0*yO8EgXEJ3Uvo8uLi 720w, https:\/\/miro.medium.com\/max\/750\/0*yO8EgXEJ3Uvo8uLi 750w, https:\/\/miro.medium.com\/max\/786\/0*yO8EgXEJ3Uvo8uLi 786w, https:\/\/miro.medium.com\/max\/828\/0*yO8EgXEJ3Uvo8uLi 828w, https:\/\/miro.medium.com\/max\/1100\/0*yO8EgXEJ3Uvo8uLi 1100w, https:\/\/miro.medium.com\/max\/1400\/0*yO8EgXEJ3Uvo8uLi 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\">Signing in to Comet<\/picture><\/p>\n<p>&nbsp;<\/p>\n<\/div>\n<p id=\"70b4\" class=\"pw-post-body-paragraph ld le iy bm b lf lg jz lh li lj kc lk ll lm ln lo lp lq lr ls lt lu lv lw lx ir ga\" data-selectable-paragraph=\"\">Now, in the upper-right corner, we can click on our profile and navigate to settings, where we can see our API key. We click on the API key tab and will see something like this:<\/p>\n<figure><img loading=\"lazy\" decoding=\"async\" class=\"ce kx ky c aligncenter\" role=\"presentation\" src=\"https:\/\/miro.medium.com\/max\/1050\/0*st3hGNVAlAd2DWsC\" alt=\"\" width=\"700\" height=\"143\"><\/figure><div class=\"gl gm nn\"><picture><source srcset=\"https:\/\/miro.medium.com\/max\/640\/0*st3hGNVAlAd2DWsC 640w, https:\/\/miro.medium.com\/max\/720\/0*st3hGNVAlAd2DWsC 720w, https:\/\/miro.medium.com\/max\/750\/0*st3hGNVAlAd2DWsC 750w, https:\/\/miro.medium.com\/max\/786\/0*st3hGNVAlAd2DWsC 786w, https:\/\/miro.medium.com\/max\/828\/0*st3hGNVAlAd2DWsC 828w, https:\/\/miro.medium.com\/max\/1100\/0*st3hGNVAlAd2DWsC 1100w, https:\/\/miro.medium.com\/max\/1400\/0*st3hGNVAlAd2DWsC 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<p class=\"ko kp kq kr gx ks gl gm paragraph-image\" style=\"text-align: center;\">Locating our API key<\/p>\n<p>&nbsp;<\/p>\n<p id=\"7252\" class=\"pw-post-body-paragraph ld le iy bm b lf lg jz lh li lj kc lk ll lm ln lo lp lq lr ls lt lu lv lw lx ir ga\" data-selectable-paragraph=\"\">Once we\u2019ve completed that, the next step is to install the Comet library locally which we can do by running either of the following commands:<\/p>\n<pre class=\"ko kp kq kr gx no bs np\"><span id=\"8fa4\" class=\"ga mz lz iy my b dm nq nr l ns\" data-selectable-paragraph=\"\">pip install comet_ml<\/span><\/pre>\n<p id=\"f7b4\" class=\"pw-post-body-paragraph ld le iy bm b lf lg jz lh li lj kc lk ll lm ln lo lp lq lr ls lt lu lv lw lx ir ga\" data-selectable-paragraph=\"\">\u2014 or \u2014<\/p>\n<pre class=\"ko kp kq kr gx no bs np\"><span id=\"84e7\" class=\"ga mz lz iy my b dm nq nr l ns\" data-selectable-paragraph=\"\">conda install -c comet_ml comet_ml<\/span><\/pre>\n<p id=\"ee62\" class=\"pw-post-body-paragraph ld le iy bm b lf lg jz lh li lj kc lk ll lm ln lo lp lq lr ls lt lu lv lw lx ir ga\" data-selectable-paragraph=\"\">Once we\u2019ve installed the comet library, it\u2019s time to open our Jupyter notebook.<\/p>\n<\/div>\n\n\n\n<div class=\"ir is it iu iv\">\n<p id=\"1192\" class=\"ob oc iy bm od oe of og oh oi oj lx cn\" data-selectable-paragraph=\"\">Is your current workflow siloed and impossible to track? It might be time for an MLOps strategy. We created a free guide on how to create effective ML teams just for you.&nbsp;<a class=\"au lc\" href=\"https:\/\/go.comet.ml\/ebook-Building-Effective-ML-Teams.html\" target=\"_blank\" rel=\"noopener ugc nofollow\">Learn more today!<\/a><\/p>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading mz lz iy bm ma na nb nc me nd ne nf mi ll ng nh mk lp ni nj mm lt nk nl mo nm ga\" id=\"0ae5\">Setting the Model\/Algorithm Parameter<\/h2>\n\n\n\n<p class=\"pw-post-body-paragraph ld le iy bm b lf mq jz lh li mr kc lk ll ms ln lo lp mt lr ls lt mu lv lw lx ir ga\" id=\"6553\">As previously mentioned, we will be focusing on hyperparameter optimization in this demo. We will use Comet to keep track of the hyperparameters used in each experiment, and we will then compare those experiments to see which set of hyperparameters performs the best.<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph ld le iy bm b lf lg jz lh li lj kc lk ll lm ln lo lp lq lr ls lt lu lv lw lx ir ga\" id=\"f4cc\">The first step is to specify which hyperparameters we want to tune, and which values (or range of values) we\u2019d like to test. We do this by defining a dictionary of model parameters (<code class=\"fp mv mw mx my b\">model_params<\/code>) where each key represents the parameter name and the value represents the value we want to pass to the parameter. The value of each parameter is further composed of two key-value pairs, representing the&nbsp;<code class=\"fp mv mw mx my b\">type<\/code>&nbsp;and&nbsp;<code class=\"fp mv mw mx my b\">values<\/code>&nbsp;of the parameter ranges. This is because Comet offers various ways of dealing with several types of values: integer, double or float, discrete (list of numbers), and categorical (list of strings). Let\u2019s take a look at the parameters we want to pass into our model to get a better idea of what this looks like.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#Specify the hyperparameters we want to tune in our algorithm\/estimator\nmodel_params = {\n     \"n_estimators\": {\n         \"type\": \"discrete\",\n         \"values\": [50, 100, 150, 200, 250, 300]\n     },\n     \"criterion\": {\n         \"type\": \"categorical\",\n         \"values\": [\"gini\", \"entropy\"]\n     },\n     \"min_samples_leaf\": {\n         \"type\": \"discrete\",\n         \"values\": [1, 2, 3, 4]\n     }\n}<\/pre>\n\n\n\n<p class=\"has-text-align-center\">Specifying our hyperparameters<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph ld le iy bm b lf lg jz lh li lj kc lk ll lm ln lo lp lq lr ls lt lu lv lw lx ir ga\" id=\"3a25\">In our example, we wish to pass a list of numbers to&nbsp;<code class=\"fp mv mw mx my b\">n_estimators<\/code>&nbsp;and categorical values to&nbsp;<code class=\"fp mv mw mx my b\">criterion<\/code>. Click&nbsp;<a class=\"au lc\" href=\"https:\/\/www.comet.com\/docs\/python-sdk\/introduction-optimizer\/#specifying-optimizer-parameters\" target=\"_blank\" rel=\"noopener ugc nofollow\">here<\/a>&nbsp;to learn more about how Comet handles parameter values.<\/p>\n\n\n\n<h2 class=\"wp-block-heading mz lz iy bm ma na nb nc me nd ne nf mi ll ng nh mk lp ni nj mm lt nk nl mo nm ga\" id=\"32ca\">The Comet Optimizer<\/h2>\n\n\n\n<p class=\"pw-post-body-paragraph ld le iy bm b lf mq jz lh li mr kc lk ll ms ln lo lp mt lr ls lt mu lv lw lx ir ga\" id=\"6ff7\">After we\u2019ve done specifying the hyperparameters, it\u2019s time to instantiate our Comet optimizer. The Comet optimizer is used to identify the best set of hyperparameter values that will minimize or maximize a specific metric on the fly. Because of its connection with Comet\u2019s Experiment objects, Comet\u2019s optimizer offers many advantages over typical hyperparameter optimizer search services.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># Initialize our optimizer\nopt = comet_ml.Optimizer(api_key=API_KEY, config=optimizer_dict)<\/pre>\n\n\n\n<p class=\"has-text-align-center\">Instantiating our optimizer<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph ld le iy bm b lf lg jz lh li lj kc lk ll lm ln lo lp lq lr ls lt lu lv lw lx ir ga\" id=\"4278\">The Comet optimizer provides three types of hyperparameter tuning algorithms: Grid search (similar to GridSearchCV from Scikit-learn), Random search (similar to Random Search in Scikit-learn), and Bayes optmization. According to the Comet documentation, the Bayes optimization algorithm is often the most efficient and effective one to utilize, and therefore we will be using it in this tutorial.<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph ld le iy bm b lf lg jz lh li lj kc lk ll lm ln lo lp lq lr ls lt lu lv lw lx ir ga\" id=\"1ec0\">The Comet optimizer config parameters accept a dictionary consisting of the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code class=\"fp mv mw mx my b\"><strong class=\"bm ov\">algorithm<\/strong><\/code>: string; which search algorithm to use (either Grid, Random, Bayes).<\/li>\n\n\n\n<li><code class=\"fp mv mw mx my b\"><strong class=\"bm ov\">spec<\/strong><\/code>: dictionary; the algorithm-specific specifications (in other words, the specification of the search algorithm we want to use, which in our case is the Bayes algorithm).<\/li>\n\n\n\n<li><code class=\"fp mv mw mx my b\"><strong class=\"bm ov\">parameters<\/strong><\/code>: dictionary; the parameter distribution space descriptions.<\/li>\n\n\n\n<li><code class=\"fp mv mw mx my b\"><strong class=\"bm ov\">name<\/strong><\/code>: string; the name we want to call our search instance (optional).<\/li>\n\n\n\n<li><code class=\"fp mv mw mx my b\"><strong class=\"bm ov\">trials<\/strong><\/code>: integer; the number of trials per experiment to run (optional, defaults to 1).<\/li>\n<\/ul>\n\n\n\n<p class=\"pw-post-body-paragraph ld le iy bm b lf lg jz lh li lj kc lk ll lm ln lo lp lq lr ls lt lu lv lw lx ir ga\" id=\"d749\">To read more about the Comet optimizer config parameters click&nbsp;<a class=\"au lc\" href=\"https:\/\/www.comet.com\/docs\/python-sdk\/introduction-optimizer\/\" target=\"_blank\" rel=\"noopener ugc nofollow\">here<\/a>.<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph ld le iy bm b lf lg jz lh li lj kc lk ll lm ln lo lp lq lr ls lt lu lv lw lx ir ga\" id=\"b7fd\">For this tutorial, we will use the default config setting for the Bayes method, which can be found in the documentation by clicking&nbsp;<a class=\"au lc\" href=\"https:\/\/www.comet.com\/docs\/python-sdk\/introduction-optimizer\/#bayes-algorithm\" target=\"_blank\" rel=\"noopener ugc nofollow\">here<\/a>, but we will pass in our&nbsp;<code class=\"fp mv mw mx my b\">model_params<\/code>&nbsp;variable and rename the search instance&nbsp;<code class=\"fp mv mw mx my b\">My Bayesian Search<\/code>. Then we\u2019ll assign this dictionary to the&nbsp;<code class=\"fp mv mw mx my b\">optimizer_dict<\/code>&nbsp;variable.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># Specify the parameters with want to supply to the optimizer config\noptimizer_dict= {\n    \"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\": model_params,\n    \"name\": \"My Bayesian Search\"\n}<\/pre>\n\n\n\n<p class=\"has-text-align-center\">Specifying the optimizer configuration<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph ld le iy bm b lf lg jz lh li lj kc lk ll lm ln lo lp lq lr ls lt lu lv lw lx ir ga\" id=\"4f21\">Finally, we run our Experiment with the following code:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#Specify the hyperparameters we want to tune in our algorithm\/estimator\nmodel_params ={\n     \"n_estimators\": {\n         \"type\": \"discrete\",\n         \"values\": [50, 100, 150, 200, 250, 300]\n     },\n     \"criterion\": {\n         \"type\": \"categorical\",\n         \"values\": [\"gini\", \"entropy\"]\n     },\n     \"min_samples_leaf\": {\n         \"type\": \"discrete\",\n         \"values\": [1, 2, 3, 4]\n     }\n}\n\n# Specify the parameters with want to supply to the optimizer config\noptimizer_dict= {\n    \"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\": model_params,\n    \"name\": \"My Bayesian Search\"\n}\n\n# Initialize our optimizer\nopt = comet_ml.Optimizer(api_key=API_KEY, config=optimizer_dict)\nfor experiment in opt.get_experiments(project_name=\"Our First Demo\",\n                                      workspace=\"ibrahim-ogunbiyi\"):\n    # initializing random forest\n    model = RandomForestClassifier(\n        n_estimators=experiment.get_parameter(\"n_estimators\"),\n        criterion=experiment.get_parameter(\"criterion\"),\n        min_samples_leaf=experiment.get_parameter(\"min_samples_leaf\"),\n        random_state=42)\n\n    # training the model and making predictions\n    model.fit(X_train, y_train)\n    y_preds = model.predict(X_test)\n\n    # logging the metrics to the comet website\n    experiment.log_parameter(\"random_state\", 42)\n    experiment.log_metric(\"accuracy\", accuracy_score(y_test, y_preds))\n    experiment.log_confusion_matrix(y_test, y_preds)\n    experiment.end()<\/pre>\n\n\n\n<p class=\"has-text-align-center\">Running our Comet Experiment<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph ld le iy bm b lf lg jz lh li lj kc lk ll lm ln lo lp lq lr ls lt lu lv lw lx ir ga\" id=\"ff7c\">Let\u2019s quickly review what we just did above.<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph ld le iy bm b lf lg jz lh li lj kc lk ll lm ln lo lp lq lr ls lt lu lv lw lx ir ga\" id=\"8ca9\">First:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><span id=\"47d5\" class=\"ga mz lz iy my b dm nq nr l ns\" data-selectable-paragraph=\"\"># Initialize our optimizer\nopt = comet_ml.Optimizer(api_key= API_KEY,\n                         config=optimizer_dict)<\/span><\/pre>\n\n\n\n<p class=\"pw-post-body-paragraph ld le iy bm b lf lg jz lh li lj kc lk ll lm ln lo lp lq lr ls lt lu lv lw lx ir ga\" id=\"724b\">We instantiated the Comet optimizer and passed it the arguments it requires, our API key and&nbsp;<code class=\"fp mv mw mx my b\">config<\/code>&nbsp;(the config is the&nbsp;<code class=\"fp mv mw mx my b\">optimize_dict<\/code>&nbsp;we created before, which contains our model hyperparameter values and Comet optimizer search algorithm).<\/p>\n\n\n\n<p class=\"ld le pe bm b lf lg jz lh li lj kc lk pf lm ln lo pg lq lr ls ph lu lv lw lx ir ga\" id=\"95fa\"><strong>Note don\u2019t disclose your API key to the public. It is meant private for use only.<\/strong><\/p>\n\n\n\n<p class=\"pw-post-body-paragraph ld le iy bm b lf lg jz lh li lj kc lk ll lm ln lo lp lq lr ls lt lu lv lw lx ir ga\" id=\"1c8b\">The next code:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><span id=\"24a9\" class=\"ga mz lz iy my b dm nq nr l ns\" data-selectable-paragraph=\"\">for experiment in opt.get_experiments(\n    project_name=\"Our First Demo\",\n    workspace=\"ibrahim-ogunbiyi\"):<\/span><\/pre>\n\n\n\n<p class=\"pw-post-body-paragraph ld le iy bm b lf lg jz lh li lj kc lk ll lm ln lo lp lq lr ls lt lu lv lw lx ir ga\" id=\"230b\">It\u2019s used to iterate through the experiments that we\u2019ve created. That is, it allows us to loop through all of the hyperparameters we have generated. The two arguments we passed into it are now used to name our project and specify the workspace to which we want it to belong (in the above example I want it to be in my default workspace).<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph ld le iy bm b lf lg jz lh li lj kc lk ll lm ln lo lp lq lr ls lt lu lv lw lx ir ga\" id=\"f134\">The next code:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><span id=\"53e4\" class=\"ga mz lz iy my b dm nq nr l ns\" data-selectable-paragraph=\"\">model = RandomForestClassifier(\n    n_estimators= experiment.get_parameter(\"n_estimators\"),\n    criterion= experiment.get_parameter(\"criterion\"),\n    min_samples_leaf= experiment.get_parameter(\"min_samples_leaf\"),\n    random_state= 42\n )<\/span><\/pre>\n\n\n\n<p class=\"pw-post-body-paragraph ld le iy bm b lf lg jz lh li lj kc lk ll lm ln lo lp lq lr ls lt lu lv lw lx ir ga\" id=\"7e9e\">In the above code, we instantiate our RandomForestClassifier and use&nbsp;<code class=\"fp mv mw mx my b\">experiment.get_parameter()<\/code>&nbsp;to retrieve the current experiment\u2019s parameter value so that we can pass it to our model. For example,&nbsp;<code class=\"fp mv mw mx my b\">experiment.get_parameter(\u201cn_estimators\u201d)<\/code>&nbsp;will get the return the number of&nbsp;<code class=\"fp mv mw mx my b\">n_estimators<\/code>&nbsp;in the experiment.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><span id=\"0d7a\" class=\"ga mz lz iy my b dm nq nr l ns\" data-selectable-paragraph=\"\">experiment.log_parameter(\"random_state\", 42)\nexperiment.log_metric(\"accuracy\", accuracy_score(y_test, y_preds))\nexperiment.log_confusion_matrix(y_test, y_preds)<\/span><\/pre>\n\n\n\n<p class=\"pw-post-body-paragraph ld le iy bm b lf lg jz lh li lj kc lk ll lm ln lo lp lq lr ls lt lu lv lw lx ir ga\" id=\"307e\">In addition to the&nbsp;<code class=\"fp mv mw mx my b\">.log_<\/code>&nbsp;method used above, there are other metrics provided by Comet that you can read about in more detail&nbsp;<a class=\"au lc\" href=\"https:\/\/www.comet.com\/docs\/python-sdk\/Experiment\/\" target=\"_blank\" rel=\"noopener ugc nofollow\">here<\/a>.<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph ld le iy bm b lf lg jz lh li lj kc lk ll lm ln lo lp lq lr ls lt lu lv lw lx ir ga\" id=\"c02e\">Finally:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><span id=\"0f81\" class=\"ga mz lz iy my b dm nq nr l ns\" data-selectable-paragraph=\"\">experiment.end()<\/span><\/pre>\n\n\n\n<p class=\"pw-post-body-paragraph ld le iy bm b lf lg jz lh li lj kc lk ll lm ln lo lp lq lr ls lt lu lv lw lx ir ga\" id=\"17cc\">This is used to end the experiment when the code is being run on a notebook like Jupyter or Colab.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><a href=\"https:\/\/vimeo.com\/724877137\/de66f44e80?embedded=true&amp;source=video_title&amp;owner=166794904\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"1015\" height=\"584\" src=\"https:\/\/www.comet.com\/site\/wp-content\/uploads\/2022\/10\/vimeo.png\" alt=\"\" class=\"wp-image-4137\" srcset=\"https:\/\/www.comet.com\/site\/wp-content\/uploads\/2022\/10\/vimeo.png 1015w, https:\/\/www.comet.com\/site\/wp-content\/uploads\/2022\/10\/vimeo-300x173.png 300w, https:\/\/www.comet.com\/site\/wp-content\/uploads\/2022\/10\/vimeo-768x442.png 768w\" sizes=\"auto, (max-width: 1015px) 100vw, 1015px\" \/><\/a><\/figure>\n\n\n\n<p class=\"pw-post-body-paragraph ld le iy bm b lf lg jz lh li lj kc lk ll lm ln lo lp lq lr ls lt lu lv lw lx ir ga\" id=\"ec3d\">Now if you run the above code you should see similar to this:<br>\n<\/p>\n\n\n\n<figure class=\"ko kp kq kr gx ks\"><\/figure>\n\n\n\n<p class=\"pw-post-body-paragraph ld le iy bm b lf lg jz lh li lj kc lk ll lm ln lo lp lq lr ls lt lu lv lw lx ir ga\" id=\"d206\">Now choose the best set of hyperparameters from each of the experiments all in one convenient place. Assuming I\u2019ve found the best hyperparameters and want to copy them, I can quickly navigate to the website and copy them like this:<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><a href=\"https:\/\/vimeo.com\/724879179\/7cc5afb359?embedded=true&amp;source=video_title&amp;owner=166794904\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"1001\" height=\"571\" src=\"https:\/\/www.comet.com\/site\/wp-content\/uploads\/2022\/10\/vimeo-2.png\" alt=\"\" class=\"wp-image-4138\" srcset=\"https:\/\/www.comet.com\/site\/wp-content\/uploads\/2022\/10\/vimeo-2.png 1001w, https:\/\/www.comet.com\/site\/wp-content\/uploads\/2022\/10\/vimeo-2-300x171.png 300w, https:\/\/www.comet.com\/site\/wp-content\/uploads\/2022\/10\/vimeo-2-768x438.png 768w\" sizes=\"auto, (max-width: 1001px) 100vw, 1001px\" \/><\/a><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading ly lz iy bm ma mb mc md me mf mg mh mi ke mj kf mk kh ml ki mm kk mn kl mo mp ga\" id=\"4502\">Conclusion<\/h2>\n\n\n\n<p class=\"pw-post-body-paragraph ld le iy bm b lf mq jz lh li mr kc lk ll ms ln lo lp mt lr ls lt mu lv lw lx ir ga\" id=\"bd99\">In this lesson, we learned how to use&nbsp;<a class=\"au lc\" href=\"https:\/\/www.comet.com\/\" target=\"_blank\" rel=\"noopener ugc nofollow\">Comet<\/a>&nbsp;to keep track of our machine learning model experiments. You can learn more about them by checking out their website. They have quite simple documentation and they support almost all machine learning libraries. Thanks for reading!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you\u2019re a software developer, you\u2019ve probably heard of Git (a version control system that allows you to keep track of any changes you make to your code) and GitHub (a hosting platform for Git). But, it turns out that there is a similar platform for those of us in the machine learning and data [&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":"","footnotes":""},"categories":[6,9],"tags":[],"coauthors":[137],"class_list":["post-4133","post","type-post","status-publish","format-standard","hentry","category-machine-learning","category-product"],"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>Keep Track of Machine Learning Experiments With Comet<\/title>\n<meta name=\"description\" content=\"Learn more about Comet and how Comet can assist us in tracking the progress of our machine learning experiments and models.\" \/>\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\/keep-track-of-machine-learning-experiments-with-comet\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Keep Track of Machine Learning Experiments With Comet\" \/>\n<meta property=\"og:description\" content=\"Learn more about Comet and how Comet can assist us in tracking the progress of our machine learning experiments and models.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.comet.com\/site\/blog\/keep-track-of-machine-learning-experiments-with-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=\"2022-10-20T21:32:35+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-04-24T17:17:03+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/miro.medium.com\/max\/1050\/0*yO8EgXEJ3Uvo8uLi\" \/>\n<meta name=\"author\" content=\"Ibrahim Ogunbiyi\" \/>\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=\"Ibrahim Ogunbiyi\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Keep Track of Machine Learning Experiments With Comet","description":"Learn more about Comet and how Comet can assist us in tracking the progress of our machine learning experiments and models.","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\/keep-track-of-machine-learning-experiments-with-comet\/","og_locale":"en_US","og_type":"article","og_title":"Keep Track of Machine Learning Experiments With Comet","og_description":"Learn more about Comet and how Comet can assist us in tracking the progress of our machine learning experiments and models.","og_url":"https:\/\/www.comet.com\/site\/blog\/keep-track-of-machine-learning-experiments-with-comet\/","og_site_name":"Comet","article_publisher":"https:\/\/www.facebook.com\/cometdotml","article_published_time":"2022-10-20T21:32:35+00:00","article_modified_time":"2025-04-24T17:17:03+00:00","og_image":[{"url":"https:\/\/miro.medium.com\/max\/1050\/0*yO8EgXEJ3Uvo8uLi","type":"","width":"","height":""}],"author":"Ibrahim Ogunbiyi","twitter_card":"summary_large_image","twitter_creator":"@Cometml","twitter_site":"@Cometml","twitter_misc":{"Written by":"Ibrahim Ogunbiyi","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.comet.com\/site\/blog\/keep-track-of-machine-learning-experiments-with-comet\/#article","isPartOf":{"@id":"https:\/\/www.comet.com\/site\/blog\/keep-track-of-machine-learning-experiments-with-comet\/"},"author":{"name":"Team Comet Digital","@id":"https:\/\/www.comet.com\/site\/#\/schema\/person\/6266601170c60a7a82b3e0043fbe8ddf"},"headline":"Keep Track of Machine Learning Experiments With Comet","datePublished":"2022-10-20T21:32:35+00:00","dateModified":"2025-04-24T17:17:03+00:00","mainEntityOfPage":{"@id":"https:\/\/www.comet.com\/site\/blog\/keep-track-of-machine-learning-experiments-with-comet\/"},"wordCount":1661,"publisher":{"@id":"https:\/\/www.comet.com\/site\/#organization"},"image":{"@id":"https:\/\/www.comet.com\/site\/blog\/keep-track-of-machine-learning-experiments-with-comet\/#primaryimage"},"thumbnailUrl":"https:\/\/miro.medium.com\/max\/1050\/0*yO8EgXEJ3Uvo8uLi","articleSection":["Machine Learning","Product"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.comet.com\/site\/blog\/keep-track-of-machine-learning-experiments-with-comet\/","url":"https:\/\/www.comet.com\/site\/blog\/keep-track-of-machine-learning-experiments-with-comet\/","name":"Keep Track of Machine Learning Experiments With Comet","isPartOf":{"@id":"https:\/\/www.comet.com\/site\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.comet.com\/site\/blog\/keep-track-of-machine-learning-experiments-with-comet\/#primaryimage"},"image":{"@id":"https:\/\/www.comet.com\/site\/blog\/keep-track-of-machine-learning-experiments-with-comet\/#primaryimage"},"thumbnailUrl":"https:\/\/miro.medium.com\/max\/1050\/0*yO8EgXEJ3Uvo8uLi","datePublished":"2022-10-20T21:32:35+00:00","dateModified":"2025-04-24T17:17:03+00:00","description":"Learn more about Comet and how Comet can assist us in tracking the progress of our machine learning experiments and models.","breadcrumb":{"@id":"https:\/\/www.comet.com\/site\/blog\/keep-track-of-machine-learning-experiments-with-comet\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.comet.com\/site\/blog\/keep-track-of-machine-learning-experiments-with-comet\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.comet.com\/site\/blog\/keep-track-of-machine-learning-experiments-with-comet\/#primaryimage","url":"https:\/\/miro.medium.com\/max\/1050\/0*yO8EgXEJ3Uvo8uLi","contentUrl":"https:\/\/miro.medium.com\/max\/1050\/0*yO8EgXEJ3Uvo8uLi"},{"@type":"BreadcrumbList","@id":"https:\/\/www.comet.com\/site\/blog\/keep-track-of-machine-learning-experiments-with-comet\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.comet.com\/site\/"},{"@type":"ListItem","position":2,"name":"Keep Track of Machine Learning Experiments With 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\/"}]}},"_links":{"self":[{"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/posts\/4133","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=4133"}],"version-history":[{"count":1,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/posts\/4133\/revisions"}],"predecessor-version":[{"id":15671,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/posts\/4133\/revisions\/15671"}],"wp:attachment":[{"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/media?parent=4133"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/categories?post=4133"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/tags?post=4133"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/coauthors?post=4133"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}