Master the difference between learned parameters and hyperparameters. Learn to identify tunable settings to optimize your machine learning models effectively.
Previously in this course, we explored the Bias-Variance Tradeoff to understand why models fail. Now that we know how to diagnose underfitting and overfitting, we need the tools to fix them. This lesson introduces hyperparameters, the "knobs" you turn to control how your model learns.
In machine learning, every model has two types of settings. First, there are learned parameters (often just called weights). These are the internal values the model adjusts automatically during training, such as the coefficients in a linear regression model. You don't set these; the data does.
Second, there are hyperparameters. These are the configuration settings you define before training begins. They dictate the "strategy" the model uses to find its internal weights. If the model were a student, the learned parameters would be the knowledge they gain, while hyperparameters would be the study habits or the curriculum you assigned them.
The distinction is critical for your workflow. If you change a hyperparameter, you must retrain the model from scratch.
| Feature | Learned Parameters | Hyperparameters |
|---|---|---|
| Origin | Derived from training data | Set by the user (you) |
| Adjustment | Automatic (via optimization) | Manual (via tuning) |
| Timing | During training | Before training |
| Examples | Regression coefficients, node weights | Learning rate, tree depth, regularization strength |
Different algorithms have different sets of hyperparameters. As you progress through this course, you'll encounter various models, each requiring its own unique configuration. Here is how to identify them for common Scikit-Learn models:
fit_intercept: A boolean (True/False) that determines if the model should calculate the intercept for this data.positive: When set to True, forces the coefficients to be positive.max_depth: The maximum depth of the tree. A deeper tree is more complex and prone to overfitting.min_samples_split: The minimum number of samples required to split an internal node. Higher values prevent overfitting.n_neighbors: The number of neighbors to use for queries.weights: Whether to weight points uniformly or by distance.Let’s look at how we define these settings in code using a Decision Tree. Notice how we pass these values during initialization.
PYTHONfrom sklearn.tree import DecisionTreeRegressor # Configuring the model with specific hyperparameters # We are manually setting the "strategy" for how the tree grows model = DecisionTreeRegressor( max_depth=5, min_samples_split=10, random_state=42 ) # After setting these, the model is ready to learn its parameters # model.fit(X_train, y_train)
By setting max_depth=5, we explicitly constrain the model's complexity. If we left it as default (None), the tree might grow until every leaf is pure, likely leading to overfitting. Tuning these hyperparameters is how we balance performance.
RandomForestRegressor or LogisticRegression).max_depth for trees or C for logistic regression).random_state: Many algorithms (like Random Forests) are stochastic. If you don't set a random_state, your results will change every time you run the code, making it impossible to tell if a change in performance is due to your tuning or just random luck.Hyperparameters are the manual configuration settings that define how a model learns. Unlike learned parameters, which the model discovers during training, you define hyperparameters to control complexity and prevent overfitting. By identifying the critical "knobs" for your chosen algorithm, you gain the ability to steer your model's performance toward better generalization.
Up next: We will move beyond manual setting and look at Implementing Grid Search to automate the discovery of the best hyperparameter combinations.
Learn how to instantiate, fit, and generate predictions with your first baseline linear model using Scikit-Learn to establish a performance benchmark.
Read moreMaster production monitoring for ML. Learn to design effective health checks, track performance metrics, and build alerts to catch silent model failures.
Hyperparameter Tuning Basics