Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[python] Re-enable scikit-learn 0.22+ support #2946

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .ci/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ if [[ $TASK == "r-package" ]]; then
exit 0
fi

conda install -q -y -n $CONDA_ENV joblib matplotlib numpy pandas psutil pytest python-graphviz "scikit-learn<=0.21.3" scipy
conda install -q -y -n $CONDA_ENV joblib matplotlib numpy pandas psutil pytest python-graphviz "scikit-learn!=0.22.0" scipy

if [[ $OS_NAME == "macos" ]] && [[ $COMPILER == "clang" ]]; then
# fix "OMP: Error #15: Initializing libiomp5.dylib, but found libomp.dylib already initialized." (OpenMP library conflict due to conda's MKL)
Expand Down
2 changes: 1 addition & 1 deletion docker/dockerfile-python
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ RUN apt-get update && \
export PATH="$CONDA_DIR/bin:$PATH" && \
conda config --set always_yes yes --set changeps1 no && \
# lightgbm
conda install -q -y numpy scipy "scikit-learn<=0.21.3" pandas && \
conda install -q -y numpy scipy "scikit-learn!=0.22.0" pandas && \
git clone --recursive --branch stable --depth 1 https://github.com/Microsoft/LightGBM && \
cd LightGBM/python-package && python setup.py install && \
# clean
Expand Down
4 changes: 2 additions & 2 deletions docker/gpu/dockerfile.gpu
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ RUN echo "export PATH=$CONDA_DIR/bin:"'$PATH' > /etc/profile.d/conda.sh && \
rm ~/miniconda.sh

RUN conda config --set always_yes yes --set changeps1 no && \
conda create -y -q -n py2 python=2.7 mkl numpy scipy "scikit-learn<=0.21.3" jupyter notebook ipython pandas matplotlib && \
conda create -y -q -n py3 python=3.6 mkl numpy scipy "scikit-learn<=0.21.3" jupyter notebook ipython pandas matplotlib
conda create -y -q -n py2 python=2.7 mkl numpy scipy "scikit-learn!=0.22.0" jupyter notebook ipython pandas matplotlib && \
conda create -y -q -n py3 python=3.6 mkl numpy scipy "scikit-learn!=0.22.0" jupyter notebook ipython pandas matplotlib

#################################################################################################################
# LightGBM
Expand Down
2 changes: 1 addition & 1 deletion docs/GPU-Tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ If you want to use the Python interface of LightGBM, you can install it now (alo
::

sudo apt-get -y install python-pip
sudo -H pip install setuptools numpy scipy "scikit-learn<=0.21.3" -U
sudo -H pip install setuptools numpy scipy "scikit-learn!=0.22.0" -U
cd python-package/
sudo python setup.py install --precompile
cd ..
Expand Down
4 changes: 0 additions & 4 deletions docs/Python-API.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ Training API
Scikit-learn API
----------------

.. warning::

The last supported version of scikit-learn is ``0.21.3``. Our estimators are incompatible with newer versions.

.. autosummary::
:toctree: pythonapi/

Expand Down
4 changes: 2 additions & 2 deletions docs/Python-Intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ Install
-------

Install Python-package dependencies,
``setuptools``, ``wheel``, ``numpy`` and ``scipy`` are required, ``scikit-learn<=0.21.3`` is required for sklearn interface and recommended:
``setuptools``, ``wheel``, ``numpy`` and ``scipy`` are required, ``scikit-learn!=0.22.0`` is required for sklearn interface and recommended:

::

pip install setuptools wheel numpy scipy "scikit-learn<=0.21.3" -U
pip install setuptools wheel numpy scipy "scikit-learn!=0.22.0" -U

Refer to `Python-package`_ folder for the installation guide.

Expand Down
2 changes: 1 addition & 1 deletion examples/python-guide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ You should install LightGBM [Python-package](https://github.com/microsoft/LightG
You also need scikit-learn, pandas, matplotlib (only for plot example), and scipy (only for logistic regression example) to run the examples, but they are not required for the package itself. You can install them with pip:

```
pip install "scikit-learn<=0.21.3" pandas matplotlib scipy -U
pip install "scikit-learn!=0.22.0" pandas matplotlib scipy -U
```

Now you can run examples in this folder, for example:
Expand Down
3 changes: 0 additions & 3 deletions python-package/lightgbm/sklearn.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,6 @@ def __init__(self, boosting_type='gbdt', num_leaves=31, max_depth=-1,
"""
if not SKLEARN_INSTALLED:
raise LightGBMError('Scikit-learn is required for this module')
elif SKLEARN_VERSION > '0.21.3':
raise RuntimeError("The last supported version of scikit-learn is 0.21.3.\n"
"Found version: {0}.".format(SKLEARN_VERSION))

self.boosting_type = boosting_type
self.objective = objective
Expand Down
2 changes: 1 addition & 1 deletion python-package/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def run(self):
install_requires=[
'numpy',
'scipy',
'scikit-learn<=0.21.3'
'scikit-learn!=0.22.0'
],
maintainer='Guolin Ke',
maintainer_email='[email protected]',
Expand Down
5 changes: 5 additions & 0 deletions tests/python_package_test/test_sklearn.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,11 @@ def test_sklearn_integration(self):
check_name = check.func.__name__ if hasattr(check, 'func') else check.__name__
if check_name == 'check_estimators_nan_inf':
continue # skip test because LightGBM deals with nan
elif (check_name == "check_no_attributes_set_in_init"
and sk_version < '0.23.0'):
# scikit-learn <0.23 incorrectly asserts that private attributes
# cannot be set in __init__.
continue
try:
check(name, estimator)
except SkipTest as message:
Expand Down