Skip to content

Commit

Permalink
Support latest scikit-learn (>=0.24) and Python 3.9 (#333)
Browse files Browse the repository at this point in the history
* Update setup.py

* Update .appveyor.yml

* Update main.yml

* Update main.yml

* Update python_tests.sh

* Update python_tests.sh

* Update python_tests.sh

* Update test_rgf_python.py

* Update test_rgf_python.py

* Update utils.py

* Update utils.py

* Update rgf_model.py

* Update fastrgf_model.py

* Update test_rgf_python.py

* Update main.yml

* Update python_tests.sh

* Update .appveyor.yml

* Update python_tests.sh

* Update main.yml

* Update utils.py
  • Loading branch information
StrikerRUS authored Feb 12, 2021
1 parent 493f830 commit 2648265
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 16 deletions.
9 changes: 5 additions & 4 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ environment:
- PYTHON_VERSION: 3.6
- PYTHON_VERSION: 3.7
- PYTHON_VERSION: 3.8
- PYTHON_VERSION: 3.8
- PYTHON_VERSION: 3.9
- PYTHON_VERSION: 3.9
TASK: R_PACKAGE

matrix:
exclude:
- platform: x86
PYTHON_VERSION: 3.8
PYTHON_VERSION: 3.9
TASK: R_PACKAGE

install:
Expand Down Expand Up @@ -61,7 +62,7 @@ after_test:
if(
$env:APPVEYOR_REPO_TAG -eq "false" -or
$env:APPVEYOR_REPO_BRANCH -ne "master" -or
$env:PYTHON_VERSION -ne "3.8" -or
$env:PYTHON_VERSION -ne "3.9" -or
$env:TASK -eq "R_PACKAGE") {
Exit-AppVeyorBuild
}
Expand Down Expand Up @@ -95,4 +96,4 @@ deploy:
on:
appveyor_repo_tag: true
branch: master
PYTHON_VERSION: 3.8
PYTHON_VERSION: 3.9
4 changes: 2 additions & 2 deletions .ci/python_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ conda update -q conda
if [[ $TASK == "R_PACKAGE" ]]; then
conda create -q -n $CONDA_ENV python=$PYTHON_VERSION pip openssl libffi --no-deps
source activate $CONDA_ENV
pip install setuptools joblib numpy "scikit-learn<0.24" scipy pandas wheel
pip install setuptools joblib numpy scikit-learn scipy pandas wheel
else
conda create -q -n $CONDA_ENV python=$PYTHON_VERSION joblib numpy "scikit-learn<0.24" scipy pandas pytest
conda create -q -n $CONDA_ENV python=$PYTHON_VERSION joblib numpy scikit-learn scipy pandas pytest
source activate $CONDA_ENV
fi
cd $GITHUB_WORKSPACE/python-package
Expand Down
13 changes: 9 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,17 @@ jobs:
python_version: 3.8
- os: macos-latest
python_version: 3.8
- os: ubuntu-latest
container: ubuntu:trusty
python_version: 3.9
- os: macos-latest
python_version: 3.9
- os: ubuntu-latest
container: rocker/verse:latest
python_version: 3.8
python_version: 3.9
task: R_PACKAGE
- os: macos-latest
python_version: 3.8
python_version: 3.9
task: R_PACKAGE
container: ${{ matrix.container }}
steps:
Expand Down Expand Up @@ -66,7 +71,7 @@ jobs:
$GITHUB_WORKSPACE/.ci/r_tests.sh || exit -1
fi
- name: Create Wheel
if: matrix.python_version == 3.8 && matrix.task != 'R_PACKAGE' && startsWith(github.ref, 'refs/tags/')
if: matrix.python_version == 3.9 && matrix.task != 'R_PACKAGE' && startsWith(github.ref, 'refs/tags/')
shell: bash
run: |
export PATH="${{ env.CONDA_PATH }}/bin:$PATH"
Expand All @@ -79,7 +84,7 @@ jobs:
python setup.py bdist_wheel --plat-name=manylinux1_x86_64 --python-tag py3;
fi
- name: Create GitHub Release
if: matrix.python_version == 3.8 && matrix.task != 'R_PACKAGE' && startsWith(github.ref, 'refs/tags/')
if: matrix.python_version == 3.9 && matrix.task != 'R_PACKAGE' && startsWith(github.ref, 'refs/tags/')
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
6 changes: 2 additions & 4 deletions python-package/rgf/fastrgf_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,7 @@ def _fit_multiclass_task(self, X, y, sample_weight, params):
sample_weight)


class FastRGFRegressor(FastRGFEstimatorBase, RegressorMixin,
utils.RGFRegressorMixin):
class FastRGFRegressor(RegressorMixin, utils.RGFRegressorMixin, FastRGFEstimatorBase):
def __init__(self,
n_estimators=500,
max_depth=6,
Expand Down Expand Up @@ -409,8 +408,7 @@ def _set_target_and_loss(self):
__doc__ = __doc__.replace(_template, _value)


class FastRGFClassifier(FastRGFEstimatorBase, ClassifierMixin,
utils.RGFClassifierMixin):
class FastRGFClassifier(ClassifierMixin, utils.RGFClassifierMixin, FastRGFEstimatorBase):
def __init__(self,
n_estimators=500,
max_depth=6,
Expand Down
4 changes: 2 additions & 2 deletions python-package/rgf/rgf_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ def feature_importances_(self):
return np.mean([est.feature_importances_ for est in self._estimators], axis=0)


class RGFRegressor(RGFEstimatorBase, RegressorMixin, utils.RGFRegressorMixin):
class RGFRegressor(RegressorMixin, utils.RGFRegressorMixin, RGFEstimatorBase):
def __init__(self,
max_leaf=500,
test_interval=100,
Expand Down Expand Up @@ -519,7 +519,7 @@ def save_model(self, filename):
save_model.__doc__ = save_model.__doc__.replace(_template, _value)


class RGFClassifier(RGFEstimatorBase, ClassifierMixin, utils.RGFClassifierMixin):
class RGFClassifier(ClassifierMixin, utils.RGFClassifierMixin, RGFEstimatorBase):
def __init__(self,
max_leaf=1000,
test_interval=100,
Expand Down
10 changes: 10 additions & 0 deletions python-package/rgf/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,11 @@ def _fit_regression_task(self, X, y, sample_weight, params):


class RGFClassifierMixin(object):
def _more_tags(self):
return {'X_types': ['2darray', 'sparse', '1dlabels'],
'requires_y' : True,
'_xfail_checks': {'check_sample_weights_invariance': 'sample_weight must have positive values'}}

@property
def classes_(self):
"""The classes labels when `fit` is performed."""
Expand Down Expand Up @@ -626,6 +631,11 @@ def predict_proba(self, X):


class RGFRegressorMixin(object):
def _more_tags(self):
return {'X_types': ['2darray', 'sparse', '1dlabels'],
'requires_y' : True,
'_xfail_checks': {'check_sample_weights_invariance': 'sample_weight must have positive values'}}

def fit(self, X, y, sample_weight=None):
"""
Build a regressor from the training set (X, y).
Expand Down
1 change: 1 addition & 0 deletions python-package/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,4 +395,5 @@ def run(self):
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Topic :: Scientific/Engineering :: Artificial Intelligence'])

0 comments on commit 2648265

Please sign in to comment.