How to See Every Setting of a scikit-learn Model with get_params
You usually set two or three of a model's settings and leave the rest at their defaults, so the code doesn't show the full picture. get_params() does: it returns every setting of a scikit-learn model, chosen or default, as a dictionary you can print, check or save. This guide lists all 18 settings of a random forest, with real output from scikit-learn 1.9.1.
Syntax
<settings> = <model>.get_params()
<settings>["<setting name>"]
| Part | What it means |
|---|---|
<model>.get_params() | "Get parameters for this estimator." It returns a dictionary of every setting the model was created with |
| The keys | The settings' names, as you'd pass them when creating the model, such as max_depth |
| The values | Each setting's value: yours where you set one, scikit-learn's default otherwise |
deep=True | The default. "If True, will return the parameters for this estimator and contained subobjects that are estimators", which matters for pipelines that hold other models |
It works before and after training, on every scikit-learn estimator.
Step 1: List a Model's Settings
The example creates a random forest with two settings of its own, 200 trees and a maximum depth of 8, and prints everything get_params() returns. Create model_params.py:
![The model_params.py script in a macOS-style code window: a RandomForestRegressor created with n_estimators=200 and max_depth=8, params = model.get_params(), a print of how many settings there are, a loop that prints each name and value, and a print of params["max_depth"].](https://strdewiridedevblogsprod.blob.core.windows.net/images/blog/ai/scikit-learn/2026/sklearn-get-params-01-code.webp)
from sklearn.ensemble import RandomForestRegressor
model = RandomForestRegressor(n_estimators=200, max_depth=8)
params = model.get_params()
print(len(params), "settings:")
for name, value in params.items():
print(f" {name} = {value!r}")
print("max_depth is", params["max_depth"])
| Line | What it does |
|---|---|
RandomForestRegressor(n_estimators=200, max_depth=8) | Creates the model with two settings of your own. It isn't trained, and doesn't need to be |
model.get_params() | Returns all its settings as a dictionary |
| The loop | Prints each name and value. {value!r} shows text in quotes, so 'squared_error' is clearly text |
params["max_depth"] | Reads a single setting |
Step 2: Run It
uv run python model_params.py
18 settings:
bootstrap = True
ccp_alpha = 0.0
criterion = 'squared_error'
max_depth = 8
max_features = 1.0
max_leaf_nodes = None
max_samples = None
min_impurity_decrease = 0.0
min_samples_leaf = 1
min_samples_split = 2
min_weight_fraction_leaf = 0.0
monotonic_cst = None
n_estimators = 200
n_jobs = None
oob_score = False
random_state = None
verbose = 0
warm_start = False
max_depth is 8

- 18 settings, in alphabetical order. Two are yours,
max_depth = 8andn_estimators = 200; the other 16 are scikit-learn's defaults. - The defaults are worth knowing: each tree sees a resampled copy of the rows (
bootstrap = True), may use every feature at each split (max_features = 1.0), and may end a branch in a leaf of a single row (min_samples_leaf = 1). random_state = Nonemeans each training run builds different trees. Set it to get the same forest every time.Nonevalues mean "no limit" or "not set", depending on the setting; the model's reference explains each one.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Leaving out the brackets: model.get_params["max_depth"] | TypeError: 'method' object is not subscriptable | Call it first: model.get_params()["max_depth"] |
| Looking for what the model learned | get_params() holds settings only; learned values are attributes ending in _, such as feature_importances_ | Read the trained model's attributes for results |
| Misspelling a setting when creating the model | TypeError: RandomForestRegressor.__init__() got an unexpected keyword argument 'maxdepth'. Did you mean 'max_depth'? | Copy the name from get_params() or the model's reference |
Misspelling a name when changing a setting with set_params | ValueError: Invalid parameter 'maxdepth' for estimator RandomForestRegressor(max_depth=4). Valid parameters are: [...] | Copy the name from get_params() |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
Keys with double underscores, such as model__max_depth | The object is a pipeline or another model that contains models, and deep=True lists theirs too | Pass deep=False for the outer object's own settings |
FAQ
How do I change a setting after creating the model?
With set_params: model.set_params(max_depth=4) changes it and returns the model. get_params() then shows the new value, and the next fit uses it.
Can I save the settings with an experiment?
Yes. The dictionary holds plain values such as numbers, text, True and None, which save cleanly as JSON. For example, MLflow can store it with a run: How to Log a Dictionary to MLflow as a JSON or YAML File.
Is printing the model enough?
print(model) shows only the settings you changed, here RandomForestRegressor(max_depth=8, n_estimators=200). get_params() shows all of them.
Conclusion
model.get_params() returned all 18 settings of a random forest as a dictionary: the 2 chosen in code and the 16 defaults, such as bootstrap = True and random_state = None. Use it to see, check or record exactly how a model was configured.
Additional Resources
- RandomForestRegressor — scikit-learn's reference, with what each of the 18 settings does.
- Developing scikit-learn estimators: get_params and set_params — how every estimator provides these two methods.
