Coderhouse goes global

🌍

Read more

What Are Hyperparameters and How Machine Learning Teams Tune Them

AI Engineering

Build and ship real applications with LLMs, agents and automation.

8 weeks · Live online · View course →

Data Analytics

Go from zero to job-ready analyst with SQL, Python and BI tools.

10 weeks · Live online · View course →

Dan Patiño

AI Strategy & Innovation at Coderhouse

Artificial Intelligence

What Are Hyperparameters and How Machine Learning Teams Tune Them

What Are Hyperparameters and How Machine Learning Teams Tune Them

Hyperparameters are the settings you choose before training a machine learning model, and they control how the model learns. The learning rate, the number of trees in a random forest, the depth of each tree, the strength of regularization, the batch size, and the number of training epochs are all hyperparameters. The model does not learn them from the data; a person or an automated search picks them.

They matter because the same algorithm on the same dataset can perform very differently depending on these choices. A learning rate that is too high can make training unstable; a tree that is too deep can memorize the training data. Hyperparameter tuning is the process of searching for the combination that gives the best results on data the model has not seen, and it is one of the most practical skills in day-to-day machine learning work.

Hyperparameters vs. parameters

The two terms are easy to confuse, but the difference is simple:

  • Parameters are learned during training. In a linear model they are the weights and bias; in a neural network they are the millions (or billions) of weights updated by gradient descent.

  • Hyperparameters are set before training and shape how those parameters are learned. Google’s Machine Learning Crash Course uses learning rate, batch size, and epochs as its core examples.

A useful way to remember it: parameters are what the model figures out; hyperparameters are the rules of the game you give it.

Common hyperparameters by model type

Tree-based models

  • Number of trees (in random forests and gradient boosting)

  • Maximum depth and minimum samples per leaf, which limit how specific each tree can get

  • Learning rate in gradient boosting, which controls how much each new tree corrects the previous ones

Linear and logistic models

Neural networks and LLM fine-tuning

  • Learning rate and learning-rate schedule (warmup, decay)

  • Batch size and number of epochs

  • Dropout rate, number of layers, and layer size

  • In LoRA fine-tuning, the rank and scaling factor of the adapters

Why tuning matters: the overfitting balance

Most hyperparameters move a model along a spectrum from too simple to too complex. Too simple, and the model underfits: it misses real patterns. Too complex, and it starts memorizing noise, which is overfitting. Good tuning finds the point where performance on new data is highest, not where training accuracy looks most impressive.

That is why tuning must always be judged on held-out data. The standard approach is cross-validation: split the training data into folds, train on some, score on the rest, and average the results for each hyperparameter combination. A separate test set stays untouched until the very end to give an honest final estimate.

How hyperparameter tuning works

1. Manual tuning

You change one or two settings, retrain, and compare. It builds intuition and works for quick experiments, but it does not scale and it is easy to fool yourself.

2. Grid search

You define a list of values for each hyperparameter, and the search tries every combination. The scikit-learn guide to tuning hyperparameters covers GridSearchCV, which pairs grid search with cross-validation. It is thorough, but the number of combinations grows quickly: four hyperparameters with five values each already means 625 training runs per fold.

3. Random search

Instead of trying every combination, random search samples combinations from ranges you define. In their well-known paper, Bergstra and Bengio showed that random search often finds models as good as or better than grid search with far fewer trials, because usually only a few hyperparameters really matter and random sampling explores them more widely.

4. Bayesian and adaptive search

Smarter methods use the results of earlier trials to decide what to try next, focusing on promising regions and stopping weak trials early. Open-source frameworks such as Optuna make this approach accessible in a few lines of Python, and most cloud ML platforms offer a managed version.

A practical tuning workflow

  1. Start with defaults. Library defaults are often reasonable and give you a baseline to beat.

  2. Pick the metric that matters. Accuracy, F1, AUC, or error in business units: decide before you search.

  3. Tune the few settings with the biggest impact first, such as learning rate and model depth, using wide ranges (often on a logarithmic scale).

  4. Use random or Bayesian search with cross-validation, then narrow the ranges around the best results.

  5. Confirm on the untouched test set and log every experiment so results are reproducible.

Common mistakes

  • Tuning on the test set: if you keep checking the test score while tuning, it stops being an honest estimate.

  • Chasing tiny gains: a 0.2% improvement may be noise. Better features or cleaner data usually beat endless tuning.

  • Ignoring cost: a slightly better model that takes ten times longer to train or serve may not be worth it.

  • Forgetting the seed: random initialization and data splits can change results; fix seeds or average across runs.

FAQ

Is the learning rate a parameter or a hyperparameter?

It is a hyperparameter. You set it before training, and it controls how big each update to the model’s parameters is.

Do LLM users need to tune hyperparameters?

If you only call an LLM through an API, you mostly adjust generation settings such as temperature. If you fine-tune a model, you will tune training hyperparameters like learning rate, epochs, and LoRA rank.

Which tuning method should a beginner use?

Start with random search plus cross-validation in scikit-learn. It is simple, efficient, and teaches the core ideas before moving to Bayesian tools.

Build and tune real models with live practice

If you want hands-on experience training, evaluating, and tuning machine learning and AI systems, Coderhouse offers live online courses:

  • AI Engineering Course: for developers moving into AI engineering, covering LLM applications, retrieval, agents, evaluation, and deployment.

  • Data Analytics Course: for career switchers, analysts, and data-driven professionals who want to master metrics, SQL, Python, visualization, and experimentation.

Dan Patiño

I'm Dan Patiño, head of AI Strategy & Innovation at Coderhouse. My day-to-day work involves merging the tactical management of e-commerce (CRO, Email Marketing and SEO) with the development of disruptive solutions. I specialize in building internal AI-powered apps to automate tasks and boost innovation within the team. I firmly believe that technology is strategy's best ally. To dive deeper into my professional journey, I'll be waiting for you on my LinkedIn profile.