Skip to content

Commit

Permalink
Add pyproject.toml install information
Browse files Browse the repository at this point in the history
Add __call__ method to support sklearn ensembles requirements for base estimators
Update tests
  • Loading branch information
rmontanana committed Aug 13, 2024
1 parent 5f8ca8f commit b627bb7
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 65 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include README.md LICENSE
65 changes: 64 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,68 @@
[build-system]
requires = ["setuptools", "scikit-learn>1.0", "numpy", "mufs"]
build-backend = "setuptools.build_meta"

[tool.setuptools]
packages = ["stree"]
license-files = ["LICENSE"]

[tool.setuptools.dynamic]
version = { attr = "stree.__version__" }

[project]
name = "STree"
dependencies = ["scikit-learn>1.0", "numpy", "mufs"]
license = { file = "LICENSE" }
description = "Oblique decision tree with svm nodes."
readme = "README.md"
authors = [
{ name = "Ricardo Montañana", email = "ricardo.montanana@alu.uclm.es" },
]
dynamic = ['version']
requires-python = ">=3.8"
keywords = [
"scikit-learn",
"oblique-classifier",
"oblique-decision-tree",
"decision-tree",
"svm",
"svc",
]
classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Science/Research",
"Intended Audience :: Developers",
"Topic :: Software Development",
"Topic :: Scientific/Engineering",
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]

[project.optional-dependencies]
dev = ["black", "flake8", "mypy", "coverage"]

[project.urls]
Code = "https://github.com/Doctorado-ML/STree"
Documentation = "https://stree.readthedocs.io/en/latest/index.html"

[tool.coverage.run]
branch = true
source = ["stree"]
command_line = "-m unittest discover -s stree.tests"

[tool.coverage.report]
show_missing = true
fail_under = 100

[tool.black]
line-length = 79
target_version = ['py311']
include = '\.pyi?$'
exclude = '''
/(
Expand All @@ -13,4 +76,4 @@ exclude = '''
| build
| dist
)/
'''
'''
56 changes: 0 additions & 56 deletions setup.py

This file was deleted.

4 changes: 4 additions & 0 deletions stree/Strees.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ def version() -> str:
"""Return the version of the package."""
return __version__

def __call__(self) -> str:
"""Only added to comply with scikit-learn base estimator for ensemble"""
return self.version()

def _more_tags(self) -> dict:
"""Required by sklearn to supply features of the classifier
make mandatory the labels array
Expand Down
3 changes: 2 additions & 1 deletion stree/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from .Strees import Stree, Siterator
from ._version import __version__

__author__ = "Ricardo Montañana Gómez"
__copyright__ = "Copyright 2020-2021, Ricardo Montañana Gómez"
__license__ = "MIT License"
__author_email__ = "ricardo.montanana@alu.uclm.es"

__all__ = ["Stree", "Siterator"]
__all__ = ["__version__", "Stree", "Siterator"]
2 changes: 1 addition & 1 deletion stree/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.3.2"
__version__ = "1.4.0"
17 changes: 11 additions & 6 deletions stree/tests/Stree_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,12 @@ def test_muticlass_dataset(self):
"impurity sigmoid": 0.824,
},
"Iris": {
"max_samples liblinear": 0.9550561797752809,
"max_samples liblinear": 0.9887640449438202,
"max_samples linear": 1.0,
"max_samples rbf": 0.6685393258426966,
"max_samples poly": 0.6853932584269663,
"max_samples sigmoid": 0.6404494382022472,
"impurity liblinear": 0.9550561797752809,
"impurity liblinear": 0.9887640449438202,
"impurity linear": 1.0,
"impurity rbf": 0.6685393258426966,
"impurity poly": 0.6853932584269663,
Expand Down Expand Up @@ -440,10 +440,10 @@ def test_multiclass_classifier_integrity(self):
clf.fit(X, y)
score = clf.score(X, y)
# Check accuracy of the whole model
self.assertAlmostEquals(0.98, score, 5)
self.assertAlmostEqual(0.98, score, 5)
svm = LinearSVC(random_state=0)
svm.fit(X, y)
self.assertAlmostEquals(0.9666666666666667, svm.score(X, y), 5)
self.assertAlmostEqual(0.9666666666666667, svm.score(X, y), 5)
data = svm.decision_function(X)
expected = [
0.4444444444444444,
Expand All @@ -455,7 +455,7 @@ def test_multiclass_classifier_integrity(self):
ty[data > 0] = 1
ty = ty.astype(int)
for i in range(3):
self.assertAlmostEquals(
self.assertAlmostEqual(
expected[i],
clf.splitter_._gini(ty[:, i]),
)
Expand Down Expand Up @@ -593,7 +593,7 @@ def test_score_multiclass_linear(self):
)
self.assertEqual(0.9526666666666667, clf2.fit(X, y).score(X, y))
X, y = load_wine(return_X_y=True)
self.assertEqual(0.9831460674157303, clf.fit(X, y).score(X, y))
self.assertEqual(0.9887640449438202, clf.fit(X, y).score(X, y))
self.assertEqual(1.0, clf2.fit(X, y).score(X, y))

def test_zero_all_sample_weights(self):
Expand Down Expand Up @@ -725,6 +725,11 @@ def test_version(self):
clf = Stree()
self.assertEqual(__version__, clf.version())

def test_call(self) -> None:
"""Check call method."""
clf = Stree()
self.assertEqual(__version__, clf())

def test_graph(self):
"""Check graphviz representation of the tree."""
X, y = load_wine(return_X_y=True)
Expand Down

0 comments on commit b627bb7

Please sign in to comment.