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
2 changes: 1 addition & 1 deletion .github/workflows/test-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
python-version: ["3.10", "3.11", "3.12"]
os: [ubuntu-latest, macOS-latest, windows-latest]
steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 24.2.0
rev: 26.3.0
hooks:
- id: black
- repo: https://github.com/pycqa/flake8
Expand Down
1 change: 1 addition & 0 deletions benchmarks/consumer_complaints/scripts/data.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
"""Script to share common functions for data manipulation."""

import csv
from typing import TextIO

Expand Down
1 change: 1 addition & 0 deletions benchmarks/consumer_complaints/scripts/metrics.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
"""Script to compute metrics."""

import argparse
import sys
from argparse import Namespace
Expand Down
1 change: 1 addition & 0 deletions benchmarks/consumer_complaints/scripts/predict.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
"""Script to predict with flat approach."""

import argparse
import pickle
import sys
Expand Down
1 change: 1 addition & 0 deletions benchmarks/consumer_complaints/scripts/split_data.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
"""Script to split train and test data."""

import argparse
import sys
from argparse import Namespace
Expand Down
1 change: 1 addition & 0 deletions benchmarks/consumer_complaints/scripts/statistics.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
"""Script to store basic statistical information."""

import argparse
import os
import sys
Expand Down
1 change: 1 addition & 0 deletions benchmarks/consumer_complaints/scripts/train.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
"""Script to train with flat or hierarchical approaches."""

import argparse
import pickle
import sys
Expand Down
3 changes: 2 additions & 1 deletion benchmarks/consumer_complaints/scripts/tune.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
"""Script to perform hyper-parameter tuning for flat and hierarchical approaches."""

import hashlib
import json
import logging
Expand Down Expand Up @@ -170,7 +171,7 @@ def load_trial(cfg: DictConfig) -> List[float]:
md5 = compute_md5(hyperparameters)
filename = f"{cfg.output_dir}/{md5}.sav"
if os.path.exists(filename):
(_, scores) = pickle.load(open(filename, "rb"))
_, scores = pickle.load(open(filename, "rb"))
log.info(f"Loaded trial with F-scores {scores}")
return scores
else:
Expand Down
1 change: 1 addition & 0 deletions benchmarks/consumer_complaints/scripts/tune_table.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
"""Script to create table with tuning results for flat and hierarchical approaches."""

import argparse
import glob
import pickle
Expand Down
1 change: 1 addition & 0 deletions docs/examples/plot_binary_policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@

Mathematical definition on the different policies is given at :ref:`Training Policies`.
"""

from sklearn.ensemble import RandomForestClassifier

from hiclass import LocalClassifierPerNode
Expand Down
1 change: 1 addition & 0 deletions docs/examples/plot_calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
In the code below, isotonic regression is used to calibrate the model.

"""

from sklearn.ensemble import RandomForestClassifier

from hiclass import LocalClassifierPerNode
Expand Down
1 change: 1 addition & 0 deletions docs/examples/plot_empty_levels.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
.. figure:: ../algorithms/local_classifier_per_node.svg
:align: center
"""

import numpy as np
from sklearn.linear_model import LogisticRegression

Expand Down
1 change: 1 addition & 0 deletions docs/examples/plot_hello_hiclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

A minimalist example showing how to use HiClass to train and predict.
"""

from sklearn.ensemble import RandomForestClassifier

from hiclass import LocalClassifierPerNode
Expand Down
1 change: 1 addition & 0 deletions docs/examples/plot_model_persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
Pickle can be used to easily store machine learning models on disk.
In this example, we demonstrate how to use pickle to store and load trained classifiers.
"""

import pickle

from sklearn.linear_model import LogisticRegression
Expand Down
1 change: 1 addition & 0 deletions docs/examples/plot_parallel_training.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
.. [1] https://www.ray.io/
.. [2] https://www.kaggle.com/datasets/kashnitsky/hierarchical-text-classification
"""

import sys
from os import cpu_count
from sklearn.feature_extraction.text import CountVectorizer, TfidfTransformer
Expand Down
1 change: 1 addition & 0 deletions docs/examples/plot_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
HiClass can be adopted in scikit-learn pipelines, and fully supports sparse matrices as input.
This example desmonstrates the use of both of these features.
"""

from sklearn.feature_extraction.text import CountVectorizer, TfidfTransformer
from sklearn.linear_model import LogisticRegression
from sklearn.pipeline import Pipeline
Expand Down
3 changes: 2 additions & 1 deletion hiclass/ConstantClassifier.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"""Constant classifier if there is only one class in the training set."""

import numpy as np
from sklearn.base import BaseEstimator


class ConstantClassifier:
class ConstantClassifier(BaseEstimator):
"""A classifier that always returns the only label seen during fit."""

def fit(self, X, y, sample_weight=None):
Expand Down
2 changes: 1 addition & 1 deletion hiclass/LocalClassifierPerLevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ def _fit_classifier(self, level, separator):
md5 = hashlib.md5(str(level).encode("utf-8")).hexdigest()
filename = f"{self.tmp_dir}/{md5}.sav"
if exists(filename):
(_, classifier) = pickle.load(open(filename, "rb"))
_, classifier = pickle.load(open(filename, "rb"))
self.logger_.info(
f"Loaded trained model for local classifier {level} from file {filename}"
)
Expand Down
2 changes: 1 addition & 1 deletion hiclass/LocalClassifierPerNode.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ def _fit_classifier(self, node):
md5 = hashlib.md5(node.encode("utf-8")).hexdigest()
filename = f"{self.tmp_dir}/{md5}.sav"
if exists(filename):
(_, classifier) = pickle.load(open(filename, "rb"))
_, classifier = pickle.load(open(filename, "rb"))
self.logger_.info(
f"Loaded trained model for local classifier {node.split(self.separator_)[-1]} from file {filename}"
)
Expand Down
2 changes: 1 addition & 1 deletion hiclass/LocalClassifierPerParentNode.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ def _fit_classifier(self, node):
md5 = hashlib.md5(node.encode("utf-8")).hexdigest()
filename = f"{self.tmp_dir}/{md5}.sav"
if exists(filename):
(_, classifier) = pickle.load(open(filename, "rb"))
_, classifier = pickle.load(open(filename, "rb"))
self.logger_.info(
f"Loaded trained model for local classifier {node.split(self.separator_)[-1]} from file {filename}"
)
Expand Down
3 changes: 2 additions & 1 deletion hiclass/_calibration/BinaryCalibrator.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import abc
import numpy as np
from sklearn.base import BaseEstimator


class _BinaryCalibrator(abc.ABC):
class _BinaryCalibrator(abc.ABC, BaseEstimator):
@abc.abstractmethod
def fit(
self, y: np.ndarray, scores: np.ndarray, X: np.ndarray = None
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ exclude = **/__init__.py, docs/source/conf.py
;file.py: error

[requires]
python_version = ">=3.9,<3.13"
python_version = ">=3.10,<3.13"

# See the docstring in versioneer.py for instructions. Note that you must
# re-run 'versioneer.py setup' after changing this section, and commit the
Expand Down
5 changes: 2 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
URL_ISSUES = "https://github.com/scikit-learn-contrib/hiclass/issues"
EMAIL = "fabio.malchermiranda@hpi.de, Niklas.Koehnecke@student.hpi.uni-potsdam.de"
AUTHOR = "Fabio Malcher Miranda, Niklas Koehnecke"
REQUIRES_PYTHON = ">=3.9,<3.13"
REQUIRES_PYTHON = ">=3.10,<3.13"
KEYWORDS = ["hierarchical classification"]
DACS_SOFTWARE = "https://gitlab.com/dacs-hpi"
# What packages are required for this module to be executed?
Expand All @@ -39,7 +39,7 @@
"pydocstyle",
"pytest-cov==3.0.0",
"pyfakefs==5.3.5",
"black==24.2.0",
"black==26.3.0",
"pre-commit==2.20.0",
"ray",
],
Expand Down Expand Up @@ -152,7 +152,6 @@ def run(self):
"Operating System :: Unix",
"Operating System :: MacOS",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_LocalClassifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def test_tmp_dir(classifier):
filename = "0cc175b9c0f1b6a831c399e269772661.sav"
expected_name = "a"
assert patcher.fs.exists(filename)
(name, classifier) = pickle.load(open(filename, "rb"))
name, classifier = pickle.load(open(filename, "rb"))
assert expected_name == name
check_is_fitted(classifier)
clf.fit(x, y)
1 change: 0 additions & 1 deletion tests/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
adaptive_calibration_error,
)


# TODO: add tests for 3D dataframe (not sure if it's possible to have 3D dataframes)


Expand Down
4 changes: 1 addition & 3 deletions versioneer.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,7 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, env=
return stdout, p.returncode


LONG_VERSION_PY[
"git"
] = r'''
LONG_VERSION_PY["git"] = r'''
# This file helps to compute a version number in source trees obtained from
# git-archive tarball (such as those provided by githubs download-from-tag
# feature). Distribution tarballs (built by setup.py sdist) and build
Expand Down
Loading