mirror of
https://github.com/Doctorado-ML/STree.git
synced 2025-08-17 16:36:01 +00:00
Compare commits
13 Commits
Author | SHA1 | Date | |
---|---|---|---|
941c2ff5e0
|
|||
2ebf48145d
|
|||
7fbfd3622e
|
|||
bc839a80d6
|
|||
ba15ea2cc0
|
|||
85b56785c8
|
|||
b627bb7531
|
|||
5f8ca8f3bb
|
|||
|
fb8b9b344f | ||
036d1ba2a7
|
|||
4de74973b8
|
|||
|
28dd04b95a | ||
|
542bbce7db
|
14
.github/workflows/codeql-analysis.yml
vendored
14
.github/workflows/codeql-analysis.yml
vendored
@@ -2,12 +2,12 @@ name: "CodeQL"
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ master ]
|
branches: [master]
|
||||||
pull_request:
|
pull_request:
|
||||||
# The branches below must be a subset of the branches above
|
# The branches below must be a subset of the branches above
|
||||||
branches: [ master ]
|
branches: [master]
|
||||||
schedule:
|
schedule:
|
||||||
- cron: '16 17 * * 3'
|
- cron: "16 17 * * 3"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
analyze:
|
analyze:
|
||||||
@@ -17,7 +17,7 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
language: [ 'python' ]
|
language: ["python"]
|
||||||
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
|
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
|
||||||
# Learn more:
|
# Learn more:
|
||||||
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
|
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
|
||||||
@@ -28,7 +28,7 @@ jobs:
|
|||||||
|
|
||||||
# Initializes the CodeQL tools for scanning.
|
# Initializes the CodeQL tools for scanning.
|
||||||
- name: Initialize CodeQL
|
- name: Initialize CodeQL
|
||||||
uses: github/codeql-action/init@v1
|
uses: github/codeql-action/init@v2
|
||||||
with:
|
with:
|
||||||
languages: ${{ matrix.language }}
|
languages: ${{ matrix.language }}
|
||||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||||
@@ -39,7 +39,7 @@ jobs:
|
|||||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||||
# If this step fails, then you should remove it and run the build manually (see below)
|
# If this step fails, then you should remove it and run the build manually (see below)
|
||||||
- name: Autobuild
|
- name: Autobuild
|
||||||
uses: github/codeql-action/autobuild@v1
|
uses: github/codeql-action/autobuild@v2
|
||||||
|
|
||||||
# ℹ️ Command-line programs to run using the OS shell.
|
# ℹ️ Command-line programs to run using the OS shell.
|
||||||
# 📚 https://git.io/JvXDl
|
# 📚 https://git.io/JvXDl
|
||||||
@@ -53,4 +53,4 @@ jobs:
|
|||||||
# make release
|
# make release
|
||||||
|
|
||||||
- name: Perform CodeQL Analysis
|
- name: Perform CodeQL Analysis
|
||||||
uses: github/codeql-action/analyze@v1
|
uses: github/codeql-action/analyze@v2
|
||||||
|
10
.github/workflows/main.yml
vendored
10
.github/workflows/main.yml
vendored
@@ -13,12 +13,12 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
os: [macos-latest, ubuntu-latest, windows-latest]
|
os: [macos-latest, ubuntu-latest, windows-latest]
|
||||||
python: [3.8, "3.10"]
|
python: [3.11, 3.12]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v4
|
||||||
- name: Set up Python ${{ matrix.python }}
|
- name: Set up Python ${{ matrix.python }}
|
||||||
uses: actions/setup-python@v2
|
uses: actions/setup-python@v5
|
||||||
with:
|
with:
|
||||||
python-version: ${{ matrix.python }}
|
python-version: ${{ matrix.python }}
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
@@ -28,14 +28,14 @@ jobs:
|
|||||||
pip install -q --upgrade codecov coverage black flake8 codacy-coverage
|
pip install -q --upgrade codecov coverage black flake8 codacy-coverage
|
||||||
- name: Lint
|
- name: Lint
|
||||||
run: |
|
run: |
|
||||||
black --check --diff stree
|
# black --check --diff stree
|
||||||
flake8 --count stree
|
flake8 --count stree
|
||||||
- name: Tests
|
- name: Tests
|
||||||
run: |
|
run: |
|
||||||
coverage run -m unittest -v stree.tests
|
coverage run -m unittest -v stree.tests
|
||||||
coverage xml
|
coverage xml
|
||||||
- name: Upload coverage to Codecov
|
- name: Upload coverage to Codecov
|
||||||
uses: codecov/codecov-action@v1
|
uses: codecov/codecov-action@v4
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.CODECOV_TOKEN }}
|
token: ${{ secrets.CODECOV_TOKEN }}
|
||||||
files: ./coverage.xml
|
files: ./coverage.xml
|
||||||
|
1
MANIFEST.in
Normal file
1
MANIFEST.in
Normal file
@@ -0,0 +1 @@
|
|||||||
|
include README.md LICENSE
|
44
Makefile
44
Makefile
@@ -1,46 +1,36 @@
|
|||||||
SHELL := /bin/bash
|
SHELL := /bin/bash
|
||||||
.DEFAULT_GOAL := help
|
.DEFAULT_GOAL := help
|
||||||
.PHONY: coverage deps help lint push test doc build
|
.PHONY: audit coverage help lint test doc doc-clean build
|
||||||
|
|
||||||
coverage: ## Run tests with coverage
|
coverage: ## Run tests with coverage
|
||||||
coverage erase
|
@coverage erase
|
||||||
coverage run -m unittest -v stree.tests
|
@coverage run -m unittest -v stree.tests
|
||||||
coverage report -m
|
@coverage report -m
|
||||||
|
|
||||||
deps: ## Install dependencies
|
lint: ## Lint source files
|
||||||
pip install -r requirements.txt
|
@black stree
|
||||||
|
@flake8 stree
|
||||||
devdeps: ## Install development dependencies
|
|
||||||
pip install black pip-audit flake8 mypy coverage
|
|
||||||
|
|
||||||
lint: ## Lint and static-check
|
|
||||||
black stree
|
|
||||||
flake8 stree
|
|
||||||
mypy stree
|
|
||||||
|
|
||||||
push: ## Push code with tags
|
|
||||||
git push && git push --tags
|
|
||||||
|
|
||||||
test: ## Run tests
|
test: ## Run tests
|
||||||
python -m unittest -v stree.tests
|
@python -m unittest -v stree.tests
|
||||||
|
|
||||||
doc: ## Update documentation
|
doc: ## Update documentation
|
||||||
make -C docs --makefile=Makefile html
|
@make -C docs --makefile=Makefile html
|
||||||
|
|
||||||
build: ## Build package
|
build: ## Build package
|
||||||
rm -fr dist/*
|
@rm -fr dist/*
|
||||||
rm -fr build/*
|
@rm -fr build/*
|
||||||
python setup.py sdist bdist_wheel
|
@hatch build
|
||||||
|
|
||||||
doc-clean: ## Update documentation
|
doc-clean: ## Clean documentation folders
|
||||||
make -C docs --makefile=Makefile clean
|
@make -C docs --makefile=Makefile clean
|
||||||
|
|
||||||
audit: ## Audit pip
|
audit: ## Audit pip
|
||||||
pip-audit
|
@pip-audit
|
||||||
|
|
||||||
help: ## Show help message
|
help: ## Show this help message
|
||||||
@IFS=$$'\n' ; \
|
@IFS=$$'\n' ; \
|
||||||
help_lines=(`fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##/:/'`); \
|
help_lines=(`grep -Fh "##" $(MAKEFILE_LIST) | grep -Fv fgrep | sed -e 's/\\$$//' | sed -e 's/##/:/'`); \
|
||||||
printf "%s\n\n" "Usage: make [task]"; \
|
printf "%s\n\n" "Usage: make [task]"; \
|
||||||
printf "%-20s %s\n" "task" "help" ; \
|
printf "%-20s %s\n" "task" "help" ; \
|
||||||
printf "%-20s %s\n" "------" "----" ; \
|
printf "%-20s %s\n" "------" "----" ; \
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||

|

|
||||||
|
[](https://github.com/Doctorado-ML/STree/actions/workflows/codeql-analysis.yml)
|
||||||
[](https://codecov.io/gh/doctorado-ml/stree)
|
[](https://codecov.io/gh/doctorado-ml/stree)
|
||||||
[](https://www.codacy.com/gh/Doctorado-ML/STree?utm_source=github.com&utm_medium=referral&utm_content=Doctorado-ML/STree&utm_campaign=Badge_Grade)
|
[](https://www.codacy.com/gh/Doctorado-ML/STree?utm_source=github.com&utm_medium=referral&utm_content=Doctorado-ML/STree&utm_campaign=Badge_Grade)
|
||||||
[](https://lgtm.com/projects/g/Doctorado-ML/STree/context:python)
|
|
||||||
[](https://badge.fury.io/py/STree)
|
[](https://badge.fury.io/py/STree)
|
||||||

|

|
||||||
[](https://zenodo.org/badge/latestdoi/262658230)
|
[](https://zenodo.org/badge/latestdoi/262658230)
|
||||||
@@ -15,7 +15,7 @@ Oblique Tree classifier based on SVM nodes. The nodes are built and splitted wit
|
|||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pip install git+https://github.com/doctorado-ml/stree
|
pip install Stree
|
||||||
```
|
```
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
@@ -178,7 +178,7 @@
|
|||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"# Stree\n",
|
"# Stree\n",
|
||||||
"stree = Stree(random_state=random_state, C=.01, max_iter=1e3, kernel=\"liblinear\", multiclass_strategy=\"ovr\")"
|
"stree = Stree(random_state=random_state, C=.01, max_iter=1000, kernel=\"liblinear\", multiclass_strategy=\"ovr\")"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -198,7 +198,7 @@
|
|||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"# SVC (linear)\n",
|
"# SVC (linear)\n",
|
||||||
"svc = LinearSVC(random_state=random_state, C=.01, max_iter=1e3)"
|
"svc = LinearSVC(random_state=random_state, C=.01, max_iter=1000)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@@ -1,5 +1,65 @@
|
|||||||
|
[build-system]
|
||||||
|
requires = ["hatchling"]
|
||||||
|
build-backend = "hatchling.build"
|
||||||
|
|
||||||
|
[project]
|
||||||
|
name = "STree"
|
||||||
|
dependencies = ["scikit-learn>1.0", "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.11"
|
||||||
|
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.11",
|
||||||
|
"Programming Language :: Python :: 3.12",
|
||||||
|
]
|
||||||
|
|
||||||
|
[project.optional-dependencies]
|
||||||
|
dev = ["black", "flake8", "coverage", "hatch", "pip-audit"]
|
||||||
|
doc = ["sphinx", "myst-parser", "sphinx_rtd_theme", "sphinx-autodoc-typehints"]
|
||||||
|
|
||||||
|
[project.urls]
|
||||||
|
Code = "https://github.com/Doctorado-ML/STree"
|
||||||
|
Documentation = "https://stree.readthedocs.io/en/latest/index.html"
|
||||||
|
|
||||||
|
[tool.hatch.version]
|
||||||
|
path = "stree/_version.py"
|
||||||
|
|
||||||
|
[tool.hatch.build.targets.sdist]
|
||||||
|
include = ["/stree"]
|
||||||
|
|
||||||
|
[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]
|
[tool.black]
|
||||||
line-length = 79
|
line-length = 79
|
||||||
|
target-version = ["py311"]
|
||||||
include = '\.pyi?$'
|
include = '\.pyi?$'
|
||||||
exclude = '''
|
exclude = '''
|
||||||
/(
|
/(
|
||||||
|
@@ -1 +0,0 @@
|
|||||||
python-3.8
|
|
56
setup.py
56
setup.py
@@ -1,56 +0,0 @@
|
|||||||
import setuptools
|
|
||||||
import os
|
|
||||||
|
|
||||||
|
|
||||||
def readme():
|
|
||||||
with open("README.md") as f:
|
|
||||||
return f.read()
|
|
||||||
|
|
||||||
|
|
||||||
def get_data(field, file_name="__init__.py"):
|
|
||||||
item = ""
|
|
||||||
with open(os.path.join("stree", file_name)) as f:
|
|
||||||
for line in f.readlines():
|
|
||||||
if line.startswith(f"__{field}__"):
|
|
||||||
delim = '"' if '"' in line else "'"
|
|
||||||
item = line.split(delim)[1]
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
raise RuntimeError(f"Unable to find {field} string.")
|
|
||||||
return item
|
|
||||||
|
|
||||||
|
|
||||||
def get_requirements():
|
|
||||||
with open("requirements.txt") as f:
|
|
||||||
return f.read().splitlines()
|
|
||||||
|
|
||||||
|
|
||||||
setuptools.setup(
|
|
||||||
name="STree",
|
|
||||||
version=get_data("version", "_version.py"),
|
|
||||||
license=get_data("license"),
|
|
||||||
description="Oblique decision tree with svm nodes",
|
|
||||||
long_description=readme(),
|
|
||||||
long_description_content_type="text/markdown",
|
|
||||||
packages=setuptools.find_packages(),
|
|
||||||
url="https://github.com/Doctorado-ML/STree#stree",
|
|
||||||
project_urls={
|
|
||||||
"Code": "https://github.com/Doctorado-ML/STree",
|
|
||||||
"Documentation": "https://stree.readthedocs.io/en/latest/index.html",
|
|
||||||
},
|
|
||||||
author=get_data("author"),
|
|
||||||
author_email=get_data("author_email"),
|
|
||||||
keywords="scikit-learn oblique-classifier oblique-decision-tree decision-\
|
|
||||||
tree svm svc",
|
|
||||||
classifiers=[
|
|
||||||
"Development Status :: 5 - Production/Stable",
|
|
||||||
"License :: OSI Approved :: " + get_data("license"),
|
|
||||||
"Programming Language :: Python :: 3.8",
|
|
||||||
"Natural Language :: English",
|
|
||||||
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
||||||
"Intended Audience :: Science/Research",
|
|
||||||
],
|
|
||||||
install_requires=get_requirements(),
|
|
||||||
test_suite="stree.tests",
|
|
||||||
zip_safe=False,
|
|
||||||
)
|
|
@@ -267,7 +267,6 @@ class Splitter:
|
|||||||
random_state=None,
|
random_state=None,
|
||||||
normalize=False,
|
normalize=False,
|
||||||
):
|
):
|
||||||
|
|
||||||
self._clf = clf
|
self._clf = clf
|
||||||
self._random_state = random_state
|
self._random_state = random_state
|
||||||
if random_state is not None:
|
if random_state is not None:
|
||||||
@@ -415,7 +414,8 @@ class Splitter:
|
|||||||
)
|
)
|
||||||
return tuple(
|
return tuple(
|
||||||
sorted(
|
sorted(
|
||||||
range(len(feature_list)), key=lambda sub: feature_list[sub]
|
range(len(feature_list)),
|
||||||
|
key=lambda sub: feature_list[sub],
|
||||||
)[-max_features:]
|
)[-max_features:]
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -530,7 +530,10 @@ class Splitter:
|
|||||||
return entropy
|
return entropy
|
||||||
|
|
||||||
def information_gain(
|
def information_gain(
|
||||||
self, labels: np.array, labels_up: np.array, labels_dn: np.array
|
self,
|
||||||
|
labels: np.array,
|
||||||
|
labels_up: np.array,
|
||||||
|
labels_dn: np.array,
|
||||||
) -> float:
|
) -> float:
|
||||||
"""Compute information gain of a split candidate
|
"""Compute information gain of a split candidate
|
||||||
|
|
||||||
|
@@ -153,7 +153,6 @@ class Stree(BaseEstimator, ClassifierMixin):
|
|||||||
multiclass_strategy: str = "ovo",
|
multiclass_strategy: str = "ovo",
|
||||||
normalize: bool = False,
|
normalize: bool = False,
|
||||||
):
|
):
|
||||||
|
|
||||||
self.max_iter = max_iter
|
self.max_iter = max_iter
|
||||||
self.C = C
|
self.C = C
|
||||||
self.kernel = kernel
|
self.kernel = kernel
|
||||||
@@ -175,6 +174,11 @@ class Stree(BaseEstimator, ClassifierMixin):
|
|||||||
"""Return the version of the package."""
|
"""Return the version of the package."""
|
||||||
return __version__
|
return __version__
|
||||||
|
|
||||||
|
def __call__(self) -> str:
|
||||||
|
"""Only added to comply with scikit-learn base sestimator for ensembles
|
||||||
|
"""
|
||||||
|
return self.version()
|
||||||
|
|
||||||
def _more_tags(self) -> dict:
|
def _more_tags(self) -> dict:
|
||||||
"""Required by sklearn to supply features of the classifier
|
"""Required by sklearn to supply features of the classifier
|
||||||
make mandatory the labels array
|
make mandatory the labels array
|
||||||
@@ -185,7 +189,10 @@ class Stree(BaseEstimator, ClassifierMixin):
|
|||||||
return {"requires_y": True}
|
return {"requires_y": True}
|
||||||
|
|
||||||
def fit(
|
def fit(
|
||||||
self, X: np.ndarray, y: np.ndarray, sample_weight: np.array = None
|
self,
|
||||||
|
X: np.ndarray,
|
||||||
|
y: np.ndarray,
|
||||||
|
sample_weight: np.array = None,
|
||||||
) -> "Stree":
|
) -> "Stree":
|
||||||
"""Build the tree based on the dataset of samples and its labels
|
"""Build the tree based on the dataset of samples and its labels
|
||||||
|
|
||||||
@@ -340,7 +347,11 @@ class Stree(BaseEstimator, ClassifierMixin):
|
|||||||
)
|
)
|
||||||
node.set_down(
|
node.set_down(
|
||||||
self._train(
|
self._train(
|
||||||
X_D, y_d, sw_d, depth + 1, title + f" - Down({depth+1})"
|
X_D,
|
||||||
|
y_d,
|
||||||
|
sw_d,
|
||||||
|
depth + 1,
|
||||||
|
title + f" - Down({depth+1})",
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return node
|
return node
|
||||||
@@ -485,6 +496,43 @@ class Stree(BaseEstimator, ClassifierMixin):
|
|||||||
X = self.check_predict(X)
|
X = self.check_predict(X)
|
||||||
return self.classes_[np.argmax(self.__predict_class(X), axis=1)]
|
return self.classes_[np.argmax(self.__predict_class(X), axis=1)]
|
||||||
|
|
||||||
|
def get_nodes(self) -> int:
|
||||||
|
"""Return the number of nodes in the tree
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
int
|
||||||
|
number of nodes
|
||||||
|
"""
|
||||||
|
nodes = 0
|
||||||
|
for _ in self:
|
||||||
|
nodes += 1
|
||||||
|
return nodes
|
||||||
|
|
||||||
|
def get_leaves(self) -> int:
|
||||||
|
"""Return the number of leaves in the tree
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
int
|
||||||
|
number of leaves
|
||||||
|
"""
|
||||||
|
leaves = 0
|
||||||
|
for node in self:
|
||||||
|
if node.is_leaf():
|
||||||
|
leaves += 1
|
||||||
|
return leaves
|
||||||
|
|
||||||
|
def get_depth(self) -> int:
|
||||||
|
"""Return the depth of the tree
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
int
|
||||||
|
depth of the tree
|
||||||
|
"""
|
||||||
|
return self.depth_
|
||||||
|
|
||||||
def nodes_leaves(self) -> tuple:
|
def nodes_leaves(self) -> tuple:
|
||||||
"""Compute the number of nodes and leaves in the built tree
|
"""Compute the number of nodes and leaves in the built tree
|
||||||
|
|
||||||
|
@@ -1,8 +1,9 @@
|
|||||||
from .Strees import Stree, Siterator
|
from .Strees import Stree, Siterator
|
||||||
|
from ._version import __version__
|
||||||
|
|
||||||
__author__ = "Ricardo Montañana Gómez"
|
__author__ = "Ricardo Montañana Gómez"
|
||||||
__copyright__ = "Copyright 2020-2021, Ricardo Montañana Gómez"
|
__copyright__ = "Copyright 2020-2021, Ricardo Montañana Gómez"
|
||||||
__license__ = "MIT License"
|
__license__ = "MIT License"
|
||||||
__author_email__ = "ricardo.montanana@alu.uclm.es"
|
__author_email__ = "ricardo.montanana@alu.uclm.es"
|
||||||
|
|
||||||
__all__ = ["Stree", "Siterator"]
|
__all__ = ["__version__", "Stree", "Siterator"]
|
||||||
|
@@ -1 +1 @@
|
|||||||
__version__ = "1.3.1"
|
__version__ = "1.4.0"
|
||||||
|
@@ -239,6 +239,7 @@ class Stree_test(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
tcl.fit(*load_dataset(self._random_state))
|
tcl.fit(*load_dataset(self._random_state))
|
||||||
self.assertEqual(depth, tcl.depth_)
|
self.assertEqual(depth, tcl.depth_)
|
||||||
|
self.assertEqual(depth, tcl.get_depth())
|
||||||
|
|
||||||
def test_unfitted_tree_is_iterable(self):
|
def test_unfitted_tree_is_iterable(self):
|
||||||
tcl = Stree()
|
tcl = Stree()
|
||||||
@@ -288,12 +289,12 @@ class Stree_test(unittest.TestCase):
|
|||||||
"impurity sigmoid": 0.824,
|
"impurity sigmoid": 0.824,
|
||||||
},
|
},
|
||||||
"Iris": {
|
"Iris": {
|
||||||
"max_samples liblinear": 0.9550561797752809,
|
"max_samples liblinear": 0.9887640449438202,
|
||||||
"max_samples linear": 1.0,
|
"max_samples linear": 1.0,
|
||||||
"max_samples rbf": 0.6685393258426966,
|
"max_samples rbf": 0.6685393258426966,
|
||||||
"max_samples poly": 0.6853932584269663,
|
"max_samples poly": 0.6853932584269663,
|
||||||
"max_samples sigmoid": 0.6404494382022472,
|
"max_samples sigmoid": 0.6404494382022472,
|
||||||
"impurity liblinear": 0.9550561797752809,
|
"impurity liblinear": 0.9887640449438202,
|
||||||
"impurity linear": 1.0,
|
"impurity linear": 1.0,
|
||||||
"impurity rbf": 0.6685393258426966,
|
"impurity rbf": 0.6685393258426966,
|
||||||
"impurity poly": 0.6853932584269663,
|
"impurity poly": 0.6853932584269663,
|
||||||
@@ -307,9 +308,9 @@ class Stree_test(unittest.TestCase):
|
|||||||
for kernel in self._kernels:
|
for kernel in self._kernels:
|
||||||
clf = Stree(
|
clf = Stree(
|
||||||
max_iter=int(1e4),
|
max_iter=int(1e4),
|
||||||
multiclass_strategy="ovr"
|
multiclass_strategy=(
|
||||||
if kernel == "liblinear"
|
"ovr" if kernel == "liblinear" else "ovo"
|
||||||
else "ovo",
|
),
|
||||||
kernel=kernel,
|
kernel=kernel,
|
||||||
random_state=self._random_state,
|
random_state=self._random_state,
|
||||||
)
|
)
|
||||||
@@ -439,10 +440,10 @@ class Stree_test(unittest.TestCase):
|
|||||||
clf.fit(X, y)
|
clf.fit(X, y)
|
||||||
score = clf.score(X, y)
|
score = clf.score(X, y)
|
||||||
# Check accuracy of the whole model
|
# Check accuracy of the whole model
|
||||||
self.assertAlmostEquals(0.98, score, 5)
|
self.assertAlmostEqual(0.98, score, 5)
|
||||||
svm = LinearSVC(random_state=0)
|
svm = LinearSVC(random_state=0)
|
||||||
svm.fit(X, y)
|
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)
|
data = svm.decision_function(X)
|
||||||
expected = [
|
expected = [
|
||||||
0.4444444444444444,
|
0.4444444444444444,
|
||||||
@@ -454,7 +455,7 @@ class Stree_test(unittest.TestCase):
|
|||||||
ty[data > 0] = 1
|
ty[data > 0] = 1
|
||||||
ty = ty.astype(int)
|
ty = ty.astype(int)
|
||||||
for i in range(3):
|
for i in range(3):
|
||||||
self.assertAlmostEquals(
|
self.assertAlmostEqual(
|
||||||
expected[i],
|
expected[i],
|
||||||
clf.splitter_._gini(ty[:, i]),
|
clf.splitter_._gini(ty[:, i]),
|
||||||
)
|
)
|
||||||
@@ -592,7 +593,7 @@ class Stree_test(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
self.assertEqual(0.9526666666666667, clf2.fit(X, y).score(X, y))
|
self.assertEqual(0.9526666666666667, clf2.fit(X, y).score(X, y))
|
||||||
X, y = load_wine(return_X_y=True)
|
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))
|
self.assertEqual(1.0, clf2.fit(X, y).score(X, y))
|
||||||
|
|
||||||
def test_zero_all_sample_weights(self):
|
def test_zero_all_sample_weights(self):
|
||||||
@@ -640,10 +641,12 @@ class Stree_test(unittest.TestCase):
|
|||||||
clf = Stree(random_state=self._random_state)
|
clf = Stree(random_state=self._random_state)
|
||||||
clf.fit(X, y)
|
clf.fit(X, y)
|
||||||
self.assertEqual(6, clf.depth_)
|
self.assertEqual(6, clf.depth_)
|
||||||
|
self.assertEqual(6, clf.get_depth())
|
||||||
X, y = load_wine(return_X_y=True)
|
X, y = load_wine(return_X_y=True)
|
||||||
clf = Stree(random_state=self._random_state)
|
clf = Stree(random_state=self._random_state)
|
||||||
clf.fit(X, y)
|
clf.fit(X, y)
|
||||||
self.assertEqual(4, clf.depth_)
|
self.assertEqual(4, clf.depth_)
|
||||||
|
self.assertEqual(4, clf.get_depth())
|
||||||
|
|
||||||
def test_nodes_leaves(self):
|
def test_nodes_leaves(self):
|
||||||
"""Check number of nodes and leaves."""
|
"""Check number of nodes and leaves."""
|
||||||
@@ -657,13 +660,17 @@ class Stree_test(unittest.TestCase):
|
|||||||
clf.fit(X, y)
|
clf.fit(X, y)
|
||||||
nodes, leaves = clf.nodes_leaves()
|
nodes, leaves = clf.nodes_leaves()
|
||||||
self.assertEqual(31, nodes)
|
self.assertEqual(31, nodes)
|
||||||
|
self.assertEqual(31, clf.get_nodes())
|
||||||
self.assertEqual(16, leaves)
|
self.assertEqual(16, leaves)
|
||||||
|
self.assertEqual(16, clf.get_leaves())
|
||||||
X, y = load_wine(return_X_y=True)
|
X, y = load_wine(return_X_y=True)
|
||||||
clf = Stree(random_state=self._random_state)
|
clf = Stree(random_state=self._random_state)
|
||||||
clf.fit(X, y)
|
clf.fit(X, y)
|
||||||
nodes, leaves = clf.nodes_leaves()
|
nodes, leaves = clf.nodes_leaves()
|
||||||
self.assertEqual(11, nodes)
|
self.assertEqual(11, nodes)
|
||||||
|
self.assertEqual(11, clf.get_nodes())
|
||||||
self.assertEqual(6, leaves)
|
self.assertEqual(6, leaves)
|
||||||
|
self.assertEqual(6, clf.get_leaves())
|
||||||
|
|
||||||
def test_nodes_leaves_artificial(self):
|
def test_nodes_leaves_artificial(self):
|
||||||
"""Check leaves of artificial dataset."""
|
"""Check leaves of artificial dataset."""
|
||||||
@@ -682,7 +689,9 @@ class Stree_test(unittest.TestCase):
|
|||||||
clf.tree_ = n1
|
clf.tree_ = n1
|
||||||
nodes, leaves = clf.nodes_leaves()
|
nodes, leaves = clf.nodes_leaves()
|
||||||
self.assertEqual(6, nodes)
|
self.assertEqual(6, nodes)
|
||||||
|
self.assertEqual(6, clf.get_nodes())
|
||||||
self.assertEqual(2, leaves)
|
self.assertEqual(2, leaves)
|
||||||
|
self.assertEqual(2, clf.get_leaves())
|
||||||
|
|
||||||
def test_bogus_multiclass_strategy(self):
|
def test_bogus_multiclass_strategy(self):
|
||||||
"""Check invalid multiclass strategy."""
|
"""Check invalid multiclass strategy."""
|
||||||
@@ -716,6 +725,11 @@ class Stree_test(unittest.TestCase):
|
|||||||
clf = Stree()
|
clf = Stree()
|
||||||
self.assertEqual(__version__, clf.version())
|
self.assertEqual(__version__, clf.version())
|
||||||
|
|
||||||
|
def test_call(self) -> None:
|
||||||
|
"""Check call method."""
|
||||||
|
clf = Stree()
|
||||||
|
self.assertEqual(__version__, clf())
|
||||||
|
|
||||||
def test_graph(self):
|
def test_graph(self):
|
||||||
"""Check graphviz representation of the tree."""
|
"""Check graphviz representation of the tree."""
|
||||||
X, y = load_wine(return_X_y=True)
|
X, y = load_wine(return_X_y=True)
|
||||||
|
Reference in New Issue
Block a user