Unverified Commit c633c6c2 authored by Nikita Titov's avatar Nikita Titov Committed by GitHub
Browse files

[python] Re-enable scikit-learn 0.22+ support (#2949)

* Revert "specify the last supported version of scikit-learn (#2637)"

This reverts commit d1002776.

* ban scikit-learn 0.22.0 and skip broken test

* fix updated test

* fix lint test

* Revert "fix lint test"

This reverts commit 8b4db0805fe7a9e7f7eb0be3eac231f85026d196.
parent 505a145f
...@@ -74,7 +74,7 @@ if [[ $TASK == "r-package" ]]; then ...@@ -74,7 +74,7 @@ if [[ $TASK == "r-package" ]]; then
exit 0 exit 0
fi 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 scipy
if [[ $OS_NAME == "macos" ]] && [[ $COMPILER == "clang" ]]; then 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) # fix "OMP: Error #15: Initializing libiomp5.dylib, but found libomp.dylib already initialized." (OpenMP library conflict due to conda's MKL)
......
...@@ -17,7 +17,7 @@ conda init powershell ...@@ -17,7 +17,7 @@ conda init powershell
conda activate conda activate
conda config --set always_yes yes --set changeps1 no conda config --set always_yes yes --set changeps1 no
conda update -q -y conda conda update -q -y conda
conda create -q -y -n $env:CONDA_ENV python=$env:PYTHON_VERSION joblib matplotlib numpy pandas psutil pytest python-graphviz "scikit-learn<=0.21.3" scipy ; Check-Output $? conda create -q -y -n $env:CONDA_ENV python=$env:PYTHON_VERSION joblib matplotlib numpy pandas psutil pytest python-graphviz scikit-learn scipy ; Check-Output $?
conda activate $env:CONDA_ENV conda activate $env:CONDA_ENV
if ($env:TASK -eq "regular") { if ($env:TASK -eq "regular") {
......
...@@ -18,7 +18,7 @@ RUN apt-get update && \ ...@@ -18,7 +18,7 @@ RUN apt-get update && \
export PATH="$CONDA_DIR/bin:$PATH" && \ export PATH="$CONDA_DIR/bin:$PATH" && \
conda config --set always_yes yes --set changeps1 no && \ conda config --set always_yes yes --set changeps1 no && \
# lightgbm # lightgbm
conda install -q -y numpy scipy "scikit-learn<=0.21.3" pandas && \ conda install -q -y numpy scipy scikit-learn pandas && \
git clone --recursive --branch stable --depth 1 https://github.com/Microsoft/LightGBM && \ git clone --recursive --branch stable --depth 1 https://github.com/Microsoft/LightGBM && \
cd LightGBM/python-package && python setup.py install && \ cd LightGBM/python-package && python setup.py install && \
# clean # clean
......
...@@ -75,8 +75,8 @@ RUN echo "export PATH=$CONDA_DIR/bin:"'$PATH' > /etc/profile.d/conda.sh && \ ...@@ -75,8 +75,8 @@ RUN echo "export PATH=$CONDA_DIR/bin:"'$PATH' > /etc/profile.d/conda.sh && \
rm ~/miniconda.sh rm ~/miniconda.sh
RUN conda config --set always_yes yes --set changeps1 no && \ 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 py2 python=2.7 mkl numpy scipy scikit-learn 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 py3 python=3.6 mkl numpy scipy scikit-learn jupyter notebook ipython pandas matplotlib
################################################################################################################# #################################################################################################################
# LightGBM # LightGBM
......
LightGBM GPU Tutorial LightGBM GPU Tutorial
===================== =====================
The purpose of this document is to give you a quick step-by-step tutorial on GPU training. The purpose of this document is to give you a quick step-by-step tutorial on GPU training.
...@@ -78,7 +78,7 @@ If you want to use the Python interface of LightGBM, you can install it now (alo ...@@ -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 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 -U
cd python-package/ cd python-package/
sudo python setup.py install --precompile sudo python setup.py install --precompile
cd .. cd ..
......
...@@ -24,10 +24,6 @@ Training API ...@@ -24,10 +24,6 @@ Training API
Scikit-learn API Scikit-learn API
---------------- ----------------
.. warning::
The last supported version of scikit-learn is ``0.21.3``. Our estimators are incompatible with newer versions.
.. autosummary:: .. autosummary::
:toctree: pythonapi/ :toctree: pythonapi/
......
...@@ -15,11 +15,11 @@ Install ...@@ -15,11 +15,11 @@ Install
------- -------
Install Python-package dependencies, 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`` 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 -U
Refer to `Python-package`_ folder for the installation guide. Refer to `Python-package`_ folder for the installation guide.
......
...@@ -8,7 +8,7 @@ You should install LightGBM [Python-package](https://github.com/microsoft/LightG ...@@ -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: 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 pandas matplotlib scipy -U
``` ```
Now you can run examples in this folder, for example: Now you can run examples in this folder, for example:
......
...@@ -116,16 +116,24 @@ try: ...@@ -116,16 +116,24 @@ try:
from sklearn.preprocessing import LabelEncoder from sklearn.preprocessing import LabelEncoder
from sklearn.utils.class_weight import compute_sample_weight from sklearn.utils.class_weight import compute_sample_weight
from sklearn.utils.multiclass import check_classification_targets from sklearn.utils.multiclass import check_classification_targets
from sklearn.utils.validation import (assert_all_finite, check_X_y, from sklearn.utils.validation import assert_all_finite, check_X_y, check_array
check_array, check_consistent_length)
try: try:
from sklearn.model_selection import StratifiedKFold, GroupKFold from sklearn.model_selection import StratifiedKFold, GroupKFold
from sklearn.exceptions import NotFittedError from sklearn.exceptions import NotFittedError
except ImportError: except ImportError:
from sklearn.cross_validation import StratifiedKFold, GroupKFold from sklearn.cross_validation import StratifiedKFold, GroupKFold
from sklearn.utils.validation import NotFittedError from sklearn.utils.validation import NotFittedError
try:
from sklearn.utils.validation import _check_sample_weight
except ImportError:
from sklearn.utils.validation import check_consistent_length
# dummy function to support older version of scikit-learn
def _check_sample_weight(sample_weight, X, dtype=None):
check_consistent_length(sample_weight, X)
return sample_weight
SKLEARN_INSTALLED = True SKLEARN_INSTALLED = True
from sklearn import __version__ as SKLEARN_VERSION
_LGBMModelBase = BaseEstimator _LGBMModelBase = BaseEstimator
_LGBMRegressorBase = RegressorMixin _LGBMRegressorBase = RegressorMixin
_LGBMClassifierBase = ClassifierMixin _LGBMClassifierBase = ClassifierMixin
...@@ -135,13 +143,12 @@ try: ...@@ -135,13 +143,12 @@ try:
_LGBMGroupKFold = GroupKFold _LGBMGroupKFold = GroupKFold
_LGBMCheckXY = check_X_y _LGBMCheckXY = check_X_y
_LGBMCheckArray = check_array _LGBMCheckArray = check_array
_LGBMCheckConsistentLength = check_consistent_length _LGBMCheckSampleWeight = _check_sample_weight
_LGBMAssertAllFinite = assert_all_finite _LGBMAssertAllFinite = assert_all_finite
_LGBMCheckClassificationTargets = check_classification_targets _LGBMCheckClassificationTargets = check_classification_targets
_LGBMComputeSampleWeight = compute_sample_weight _LGBMComputeSampleWeight = compute_sample_weight
except ImportError: except ImportError:
SKLEARN_INSTALLED = False SKLEARN_INSTALLED = False
SKLEARN_VERSION = '0.0.0'
_LGBMModelBase = object _LGBMModelBase = object
_LGBMClassifierBase = object _LGBMClassifierBase = object
_LGBMRegressorBase = object _LGBMRegressorBase = object
...@@ -151,7 +158,7 @@ except ImportError: ...@@ -151,7 +158,7 @@ except ImportError:
_LGBMGroupKFold = None _LGBMGroupKFold = None
_LGBMCheckXY = None _LGBMCheckXY = None
_LGBMCheckArray = None _LGBMCheckArray = None
_LGBMCheckConsistentLength = None _LGBMCheckSampleWeight = None
_LGBMAssertAllFinite = None _LGBMAssertAllFinite = None
_LGBMCheckClassificationTargets = None _LGBMCheckClassificationTargets = None
_LGBMComputeSampleWeight = None _LGBMComputeSampleWeight = None
......
...@@ -7,9 +7,9 @@ import warnings ...@@ -7,9 +7,9 @@ import warnings
import numpy as np import numpy as np
from .basic import Dataset, LightGBMError, _ConfigAliases from .basic import Dataset, LightGBMError, _ConfigAliases
from .compat import (SKLEARN_INSTALLED, SKLEARN_VERSION, _LGBMClassifierBase, from .compat import (SKLEARN_INSTALLED, _LGBMClassifierBase,
LGBMNotFittedError, _LGBMLabelEncoder, _LGBMModelBase, LGBMNotFittedError, _LGBMLabelEncoder, _LGBMModelBase,
_LGBMRegressorBase, _LGBMCheckXY, _LGBMCheckArray, _LGBMCheckConsistentLength, _LGBMRegressorBase, _LGBMCheckXY, _LGBMCheckArray, _LGBMCheckSampleWeight,
_LGBMAssertAllFinite, _LGBMCheckClassificationTargets, _LGBMComputeSampleWeight, _LGBMAssertAllFinite, _LGBMCheckClassificationTargets, _LGBMComputeSampleWeight,
argc_, range_, zip_, string_type, DataFrame, DataTable) argc_, range_, zip_, string_type, DataFrame, DataTable)
from .engine import train from .engine import train
...@@ -298,9 +298,6 @@ class LGBMModel(_LGBMModelBase): ...@@ -298,9 +298,6 @@ class LGBMModel(_LGBMModelBase):
""" """
if not SKLEARN_INSTALLED: if not SKLEARN_INSTALLED:
raise LightGBMError('Scikit-learn is required for this module') 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.boosting_type = boosting_type
self.objective = objective self.objective = objective
...@@ -547,7 +544,8 @@ class LGBMModel(_LGBMModelBase): ...@@ -547,7 +544,8 @@ class LGBMModel(_LGBMModelBase):
if not isinstance(X, (DataFrame, DataTable)): if not isinstance(X, (DataFrame, DataTable)):
_X, _y = _LGBMCheckXY(X, y, accept_sparse=True, force_all_finite=False, ensure_min_samples=2) _X, _y = _LGBMCheckXY(X, y, accept_sparse=True, force_all_finite=False, ensure_min_samples=2)
_LGBMCheckConsistentLength(_X, _y, sample_weight) if sample_weight is not None:
sample_weight = _LGBMCheckSampleWeight(sample_weight, _X)
else: else:
_X, _y = X, y _X, _y = X, y
......
...@@ -276,7 +276,7 @@ if __name__ == "__main__": ...@@ -276,7 +276,7 @@ if __name__ == "__main__":
install_requires=[ install_requires=[
'numpy', 'numpy',
'scipy', 'scipy',
'scikit-learn<=0.21.3' 'scikit-learn!=0.22.0'
], ],
maintainer='Guolin Ke', maintainer='Guolin Ke',
maintainer_email='guolin.ke@microsoft.com', maintainer_email='guolin.ke@microsoft.com',
......
...@@ -293,6 +293,11 @@ class TestSklearn(unittest.TestCase): ...@@ -293,6 +293,11 @@ class TestSklearn(unittest.TestCase):
check_name = check.func.__name__ if hasattr(check, 'func') else check.__name__ check_name = check.func.__name__ if hasattr(check, 'func') else check.__name__
if check_name == 'check_estimators_nan_inf': if check_name == 'check_estimators_nan_inf':
continue # skip test because LightGBM deals with nan continue # skip test because LightGBM deals with nan
elif check_name == "check_no_attributes_set_in_init":
# skip test because scikit-learn incorrectly asserts that
# private attributes cannot be set in __init__
# (see https://github.com/microsoft/LightGBM/issues/2628)
continue
try: try:
check(name, estimator) check(name, estimator)
except SkipTest as message: except SkipTest as message:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment