Skip to content
Merged
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
17 changes: 9 additions & 8 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: [3.7, 3.8, 3.9]
python-version: ["3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Display python version
Expand All @@ -33,8 +33,9 @@ jobs:
- name: Run tests
run: |
pytest ./tests --cov-config=.coveragerc --cov-report=xml --cov=deepforest deepforest
- name: Publish code coverage
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.xml
# This step requires CODECOV_TOKEN, which is only avail. in the original repo. We therefore comment that out.
# - name: Publish code coverage
# uses: codecov/codecov-action@v5
# with:
# token: ${{ secrets.CODECOV_TOKEN }}
# file: ./coverage.xml
15 changes: 9 additions & 6 deletions .github/workflows/build-wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,28 @@ jobs:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Set up QEMU
if: runner.os == 'Linux'
uses: docker/setup-qemu-action@v1
uses: docker/setup-qemu-action@v3
with:
platforms: all

- name: Build wheels
uses: joerick/cibuildwheel@v1.9.0
uses: pypa/cibuildwheel@v2.16.5
with:
output-dir: wheelhouse
env:
CIBW_ARCHS_LINUX: "x86_64 aarch64"
CIBW_ARCHS_WINDOWS: "AMD64"
CIBW_ARCHS_MACOS: "x86_64"
CIBW_BUILD: cp3*-macosx_x86_64 cp3*-win_amd64 cp3*-manylinux_x86_64 cp3*-manylinux_aarch64
CIBW_SKIP: cp35-* cp36-*
CIBW_BUILD: >-
cp310-manylinux_x86_64 cp310-manylinux_aarch64 cp310-macosx_x86_64 cp310-win_amd64
cp311-manylinux_x86_64 cp311-manylinux_aarch64 cp311-macosx_x86_64 cp311-win_amd64
cp312-manylinux_x86_64 cp312-manylinux_aarch64 cp312-macosx_x86_64 cp312-win_amd64
- name: Store artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: wheels-${{ matrix.os }}
path: ./wheelhouse/*.whl
6 changes: 3 additions & 3 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
python-version: [3.7]
python-version: ["3.10"]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Display python version
Expand Down
84 changes: 84 additions & 0 deletions .github/workflows/manual-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Manual Release

on:
workflow_dispatch:
inputs:
version:
description: "Version to release (e.g., 0.1.8 <~ Must be above 0.1.7 as this is the point where we forked DF21)"
required: true

permissions:
contents: write

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"

- name: Install build backend
run: |
python -m pip install --upgrade pip
python -m pip install build toml

- name: Update version in setup.py
env:
RELEASE_VERSION: "${{ github.event.inputs.version }}"
run: |
python - <<'PY'
import os
import pathlib
import re

release_version = os.environ["RELEASE_VERSION"].strip()
if not release_version:
raise SystemExit("RELEASE_VERSION is required")

version = pathlib.Path("setup.py")
text = version.read_text()
new_text, count = re.subn(
r'^VERSION = "[^"]+"', f'VERSION = "{release_version}"', text, flags=re.MULTILINE
)
if count == 0:
raise SystemExit("VERSION assignment not found in setup.py")
if new_text != text:
version.write_text(new_text)
PY
shell: bash

- name: Commit version bump
env:
RELEASE_VERSION: "${{ github.event.inputs.version }}"
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add setup.py
if git diff --cached --quiet; then
echo "No changes to commit"
else
git commit -m "chore: release v${RELEASE_VERSION}"
fi

- name: Create and push tag
env:
RELEASE_VERSION: "${{ github.event.inputs.version }}"
run: |
git tag "v${RELEASE_VERSION}" || true
git push origin HEAD
git push origin "v${RELEASE_VERSION}"

- name: Build distributions
run: python -m build

- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
4 changes: 4 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Deep Forest (DF) 21
===================

.. note::

This repository is a community-maintained copy of the original `Deep Forest (DF21) project <https://github.com/LAMDA-NJU/Deep-Forest>`_. We do **not** claim credit for the underlying research or implementation; our goal is to keep the project usable on modern Python versions (e.g., Python 3.10+) while the upstream repository has seen minimal activity since a long time (with one recent try to move to py310+ but with CI/CD failing). If the upstream maintainers prioritise these updates, we are happy to contribute everything back via pull request.

|github|_ |readthedocs|_ |codecov|_ |python|_ |pypi|_ |style|_

.. |github| image:: https://github.com/LAMDA-NJU/Deep-Forest/workflows/DeepForest-CI/badge.svg
Expand Down
10 changes: 5 additions & 5 deletions deepforest/cascade.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,10 @@ def _build_regressor_predictor(
The maximum number of cascade layers in the deep forest. Notice that
the actual number of layers can be smaller than ``max_layers`` because
of the internal early stopping stage.
criterion : :obj:`{"mse", "mae"}`, default= :obj:`"mse"`
The function to measure the quality of a split. Supported criteria are
``mse`` for the mean squared error, which is equal to variance reduction
as feature selection criterion, and ``mae`` for the mean absolute error.
criterion : :obj:`{"squared_error", "absolute_error"}`, default= :obj:`"squared_error"`
The function to measure the quality of a split. Supported criteria are
``squared_error`` for the mean squared error, which is equal to variance reduction
as feature selection criterion, and ``absolute_error`` for the mean absolute error.
n_estimators : :obj:`int`, default=2
The number of estimator in each cascade layer. It will be multiplied
by 2 internally because each estimator contains a
Expand Down Expand Up @@ -1553,7 +1553,7 @@ def __init__(
bin_subsample=200000,
bin_type="percentile",
max_layers=20,
criterion="mse",
criterion="squared_error",
n_estimators=2,
n_trees=100,
max_depth=None,
Expand Down
21 changes: 16 additions & 5 deletions deepforest/forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@
MAX_INT = np.iinfo(np.int32).max


def _normalize_regression_criterion(criterion: str) -> str:
"""Align legacy regression criteria names with scikit-learn
expectations."""

if criterion == "mse":
return "squared_error"
if criterion == "mae":
return "absolute_error"
return criterion


def _get_n_samples_bootstrap(n_samples, max_samples):
"""
Get the number of samples in a bootstrap sample.
Expand Down Expand Up @@ -199,9 +210,7 @@ def _partition_estimators(n_estimators, n_jobs):
n_jobs = min(effective_n_jobs(n_jobs), n_estimators)

# Partition estimators between jobs
n_estimators_per_job = np.full(
n_jobs, n_estimators // n_jobs, dtype=int
)
n_estimators_per_job = np.full(n_jobs, n_estimators // n_jobs, dtype=int)
n_estimators_per_job[: n_estimators % n_jobs] += 1
starts = np.cumsum(n_estimators_per_job)

Expand Down Expand Up @@ -840,7 +849,7 @@ def __init__(
self,
n_estimators=100,
*,
criterion="mse",
criterion="squared_error",
max_depth=None,
min_samples_split=2,
min_samples_leaf=1,
Expand All @@ -853,6 +862,7 @@ def __init__(
verbose=0,
max_samples=None
):
criterion = _normalize_regression_criterion(criterion)
super().__init__(
base_estimator=DecisionTreeRegressor(),
n_estimators=n_estimators,
Expand Down Expand Up @@ -889,7 +899,7 @@ def __init__(
self,
n_estimators=100,
*,
criterion="mse",
criterion="squared_error",
max_depth=None,
min_samples_split=2,
min_samples_leaf=1,
Expand All @@ -902,6 +912,7 @@ def __init__(
verbose=0,
max_samples=None
):
criterion = _normalize_regression_criterion(criterion)
super().__init__(
base_estimator=ExtraTreeRegressor(),
n_estimators=n_estimators,
Expand Down
13 changes: 9 additions & 4 deletions deepforest/tree/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@
DOUBLE = _tree.DOUBLE

CRITERIA_CLF = {"gini": _criterion.Gini, "entropy": _criterion.Entropy}
CRITERIA_REG = {"mse": _criterion.MSE, "mae": _criterion.MAE}
CRITERIA_REG = {
"mse": _criterion.MSE,
"mae": _criterion.MAE,
"squared_error": _criterion.MSE,
"absolute_error": _criterion.MAE,
}

DENSE_SPLITTERS = {
"best": _splitter.BestSplitter,
Expand Down Expand Up @@ -181,7 +186,7 @@ def fit(
if self.class_weight is not None:
y_original = np.copy(y)

y_encoded = np.zeros(y.shape, dtype=np.int)
y_encoded = np.zeros(y.shape, dtype=int)
for k in range(self.n_outputs_):
classes_k, y_encoded[:, k] = np.unique(
y[:, k], return_inverse=True
Expand Down Expand Up @@ -504,7 +509,7 @@ class DecisionTreeRegressor(RegressorMixin, BaseDecisionTree):
def __init__(
self,
*,
criterion="mse",
criterion="squared_error",
splitter="best",
max_depth=None,
min_samples_split=2,
Expand Down Expand Up @@ -580,7 +585,7 @@ class ExtraTreeRegressor(DecisionTreeRegressor):
def __init__(
self,
*,
criterion="mse",
criterion="squared_error",
splitter="random",
max_depth=None,
min_samples_split=2,
Expand Down
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
[build-system]
requires = [
"setuptools<60.0",
"setuptools>=61,<70",
"wheel",
"numpy==1.26.4",
"Cython>=0.28.5,<3.0",
"oldest-supported-numpy",
"scipy>=1.3.2",
]
build-backend = "setuptools.build_meta"
[tool.black]
line-length = 79
include = '\.pyi?$'
Expand Down
Loading