#4223·pycaret

[BUG] tune_model fails for 'mlp' in RegressionExperiment with ValueError: Invalid parameter 'hidden_layer_size_2'

Author: amiemieux12-blipCreated Aug 29, 2026Updated Aug 29, 2026
Labelsbug

Pre-flight checklist

  • I have searched existing issues and this isn't a duplicate.
  • I'm reporting against PyCaret 4.0 (the OOP Experiment(...).fit(df) API), not 3.x.
  • I've confirmed the feature I'm asking about is not on the 4.0 kill list (docs/revamp/KILL_LIST.md).

Issue description

Describe the bug

When using RegressionExperiment in PyCaret 4, running tune_model() on an MLP Regressor (create_model('mlp')) fails with a ValueError.

The tuning tuning space internally generates parameters like hidden_layer_size_1 and hidden_layer_size_2 which are invalid for scikit-learn's MLPRegressor. Scikit-learn expects hidden_layer_sizes as a tuple.

Reproducible Example

python
from pycaret.regression import RegressionExperiment
import pandas as pd
import numpy as np

# Sample data
df = pd.DataFrame(np.random.randint(0, 100, size=(100, 4)), columns=['A', 'B', 'C', 'target'])

exp = RegressionExperiment()
exp.setup(data=df, target='target', verbose=False)

# Create and tune MLP
mlp = exp.create_model('mlp')
tuned_mlp = exp.tune_model(mlp) # <-- Fails here

Expected Behavior

tune_model should successfully find the optimal hyperparameters using a valid grid layout for MLPRegressor (e.g., using hidden_layer_sizes instead of broken individual layer sizes).

Actual Error Log

ValueError: Invalid parameter 'hidden_layer_size_2' for estimator MLPRegressor(learning_rate='adaptive', max_iter=500, random_state=123). Valid parameters are: ['activation', 'alpha', 'batch_size', 'beta_1', 'beta_2', 'early_stopping', 'epsilon', 'hidden_layer_sizes', 'learning_rate', 'learning_rate_init', 'loss', 'max_fun', 'max_iter', 'momentum', 'n_iter_no_change', 'nesterovs_momentum', 'power_t', 'random_state', 'shuffle', 'solver', 'tol', 'validation_fraction', 'verbose', 'warm_start'].

Additional Context

  • PyCaret Version: 4.x (Alpha/Beta)
  • The issue can be bypassed by manually passing a custom_grid with a valid hidden_layer_sizes parameter.
  • Other models work perfectly; this seems specific to the MLP search space definition.

Minimal reproducible example

python
from pycaret.regression import RegressionExperiment
import pandas as pd
import numpy as np

# Create a dummy dataset
df = pd.DataFrame(np.random.randint(0, 100, size=(100, 4)), columns=['A', 'B', 'C', 'target'])

# Initialize and setup experiment
exp = RegressionExperiment()
exp.setup(data=df, target='target', verbose=False)

# Create and tune MLP model
mlp = exp.create_model('mlp')
tuned_mlp = exp.tune_model(mlp) # <-- Fails here

Expected behavior

The tune_model function should successfully optimize the hyperparameters for the MLP model using a valid search space layout for scikit-learn's MLPRegressor (e.g., passing a tuple to hidden_layer_sizes instead of separate parameters like hidden_layer_size_1 or hidden_layer_size_2).

Actual behavior / traceback

python-traceback
The execution fails with the following ValueError because PyCaret internally attempts to pass an invalid parameter name (`hidden_layer_size_2`) to scikit-learn's `MLPRegressor`:

ValueError: Invalid parameter 'hidden_layer_size_2' for estimator MLPRegressor(learning_rate='adaptive', max_iter=500, random_state=123). Valid parameters are: ['activation', 'alpha', 'batch_size', 'beta_1', 'beta_2', 'early_stopping', 'epsilon', 'hidden_layer_sizes', 'learning_rate', 'learning_rate_init', 'loss', 'max_fun', 'max_iter', 'momentum', 'n_iter_no_change', 'nesterovs_momentum', 'power_t', 'random_state', 'shuffle', 'solver', 'tol', 'validation_fraction', 'verbose', 'warm_start'].

Environment

4.0.0a8 3.12.10 (tags/v3.12.10:0cc8128, Apr 8 2025, 12:21:36) [MSC v.1943 64 bit (AMD64)] 1.9.0 2.5.2 3.0.5