Skip to content

MLPEstimator do not report the proper n_iter_ after successive call of fit #24764

@glemaitre

Description

@glemaitre

Describe the bug

It seems that MLPRegressor and MLPClassifier does not take into account max_iter with warm_start.

Steps/Code to Reproduce

model = MLPRegressor(warm_start=True, early_stopping=True, max_iter=10)
model.fit(X_iris, y_iris)
assert model.n_iter_ <= 10
model.set_params(max_iter=20)
model.fit(X_iris, y_iris)
assert model.n_iter_ <= 20

You can also try MLPClassifier which leads to over iterating.

Expected Results

n_iter_ <= 20

Actual Results

    def test_xxx():
        model = MLPRegressor(warm_start=True, early_stopping=False, max_iter=10)
        model.fit(X_iris, y_iris)
        assert model.n_iter_ <= 10
        model.set_params(max_iter=20)
        model.fit(X_iris, y_iris)
>       assert model.n_iter_ <= 20
E       assert 30 <= 20
E        +  where 30 = MLPRegressor(max_iter=20, warm_start=True).n_iter_

Versions

System:
    python: 3.8.12 | packaged by conda-forge | (default, Sep 16 2021, 01:38:21)  [Clang 11.1.0 ]
executable: /Users/glemaitre/mambaforge/envs/dev/bin/python
   machine: macOS-12.6-arm64-arm-64bit

Python dependencies:
      sklearn: 1.2.dev0
          pip: 21.3
   setuptools: 58.2.0
        numpy: 1.21.6
        scipy: 1.8.0
       Cython: 0.29.24
       pandas: 1.5.0
   matplotlib: 3.4.3
       joblib: 1.2.0
threadpoolctl: 2.2.0

Built with OpenMP: True

threadpoolctl info:
       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: /Users/glemaitre/mambaforge/envs/dev/lib/libopenblas_vortexp-r0.3.18.dylib
        version: 0.3.18
threading_layer: openmp
   architecture: VORTEX
    num_threads: 8

       user_api: openmp
   internal_api: openmp
         prefix: libomp
       filepath: /Users/glemaitre/mambaforge/envs/dev/lib/libomp.dylib
        version: None
    num_threads: 8

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions