mirror of
https://github.com/Doctorado-ML/STree.git
synced 2025-08-18 00:46:02 +00:00
Compare commits
13 Commits
Author | SHA1 | Date | |
---|---|---|---|
cb80e8606b
|
|||
c93d3fbcc7
|
|||
f4ca4bbd5b
|
|||
e676ddbfcc
|
|||
|
dc637018e8 | ||
517013be09
|
|||
941c2ff5e0
|
|||
2ebf48145d
|
|||
7fbfd3622e
|
|||
bc839a80d6
|
|||
ba15ea2cc0
|
|||
85b56785c8
|
|||
b627bb7531
|
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@v3
|
- uses: actions/checkout@v4
|
||||||
- name: Set up Python ${{ matrix.python }}
|
- name: Set up Python ${{ matrix.python }}
|
||||||
uses: actions/setup-python@v4
|
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@v3
|
uses: codecov/codecov-action@v4
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.CODECOV_TOKEN }}
|
token: ${{ secrets.CODECOV_TOKEN }}
|
||||||
files: ./coverage.xml
|
files: ./coverage.xml
|
||||||
|
@@ -3,8 +3,12 @@ version: 2
|
|||||||
sphinx:
|
sphinx:
|
||||||
configuration: docs/source/conf.py
|
configuration: docs/source/conf.py
|
||||||
|
|
||||||
|
build:
|
||||||
|
os: ubuntu-22.04
|
||||||
|
tools:
|
||||||
|
python: "3.12"
|
||||||
|
|
||||||
python:
|
python:
|
||||||
version: 3.8
|
|
||||||
install:
|
install:
|
||||||
- requirements: requirements.txt
|
- requirements: requirements.txt
|
||||||
- requirements: docs/requirements.txt
|
- requirements: docs/requirements.txt
|
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,16 +1,18 @@
|
|||||||
|
# STree
|
||||||
|
|
||||||

|

|
||||||
[](https://github.com/Doctorado-ML/STree/actions/workflows/codeql-analysis.yml)
|
[](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://badge.fury.io/py/STree)
|
[](https://badge.fury.io/py/STree)
|
||||||

|

|
||||||
|
[](https://deepwiki.com/Doctorado-ML/STree)
|
||||||
[](https://zenodo.org/badge/latestdoi/262658230)
|
[](https://zenodo.org/badge/latestdoi/262658230)
|
||||||
|
|
||||||
# STree
|

|
||||||
|
|
||||||
Oblique Tree classifier based on SVM nodes. The nodes are built and splitted with sklearn SVC models. Stree is a sklearn estimator and can be integrated in pipelines, grid searches, etc.
|
Oblique Tree classifier based on SVM nodes. The nodes are built and splitted with sklearn SVC models. Stree is a sklearn estimator and can be integrated in pipelines, grid searches, etc.
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
@@ -1,9 +1,10 @@
|
|||||||
Siterator
|
Siterator
|
||||||
=========
|
=========
|
||||||
|
|
||||||
.. automodule:: Splitter
|
.. automodule:: stree
|
||||||
.. autoclass:: Siterator
|
.. autoclass:: Siterator
|
||||||
:members:
|
:members:
|
||||||
:undoc-members:
|
:undoc-members:
|
||||||
:private-members:
|
:private-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
:noindex:
|
@@ -1,9 +1,9 @@
|
|||||||
Snode
|
Snode
|
||||||
=====
|
=====
|
||||||
|
|
||||||
.. automodule:: Splitter
|
.. autoclass:: stree.Splitter.Snode
|
||||||
.. autoclass:: Snode
|
|
||||||
:members:
|
:members:
|
||||||
:undoc-members:
|
:undoc-members:
|
||||||
:private-members:
|
:private-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
:noindex:
|
@@ -1,9 +1,10 @@
|
|||||||
Splitter
|
Splitter
|
||||||
========
|
========
|
||||||
|
|
||||||
.. automodule:: Splitter
|
.. automodule:: stree.Splitter
|
||||||
.. autoclass:: Splitter
|
.. autoclass:: Splitter
|
||||||
:members:
|
:members:
|
||||||
:undoc-members:
|
:undoc-members:
|
||||||
:private-members:
|
:private-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
:noindex:
|
@@ -6,4 +6,5 @@ Stree
|
|||||||
:members:
|
:members:
|
||||||
:undoc-members:
|
:undoc-members:
|
||||||
:private-members:
|
:private-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
:noindex:
|
@@ -6,26 +6,21 @@
|
|||||||
|
|
||||||
# -- Path setup --------------------------------------------------------------
|
# -- Path setup --------------------------------------------------------------
|
||||||
|
|
||||||
# If extensions (or modules to document with autodoc) are in another directory,
|
|
||||||
# add these directories to sys.path here. If the directory is relative to the
|
|
||||||
# documentation root, use os.path.abspath to make it absolute, like shown here.
|
|
||||||
#
|
|
||||||
import os
|
|
||||||
import sys
|
import sys
|
||||||
from stree._version import __version__
|
from pathlib import Path
|
||||||
|
|
||||||
sys.path.insert(0, os.path.abspath("../../stree/"))
|
sys.path.insert(0, str(Path(__file__).parent.parent.parent))
|
||||||
|
|
||||||
|
import stree
|
||||||
|
|
||||||
# -- Project information -----------------------------------------------------
|
# -- Project information -----------------------------------------------------
|
||||||
|
|
||||||
project = "STree"
|
project = "STree"
|
||||||
copyright = "2020 - 2022, Ricardo Montañana Gómez"
|
copyright = "2020 - 2024, Ricardo Montañana Gómez"
|
||||||
author = "Ricardo Montañana Gómez"
|
author = "Ricardo Montañana Gómez"
|
||||||
|
|
||||||
# The full version, including alpha/beta/rc tags
|
# The full version, including alpha/beta/rc tags
|
||||||
version = __version__
|
version = release = stree.__version__
|
||||||
release = version
|
|
||||||
|
|
||||||
|
|
||||||
# -- General configuration ---------------------------------------------------
|
# -- General configuration ---------------------------------------------------
|
||||||
|
|
||||||
|
@@ -5,7 +5,6 @@ Welcome to STree's documentation!
|
|||||||
:caption: Contents:
|
:caption: Contents:
|
||||||
:titlesonly:
|
:titlesonly:
|
||||||
|
|
||||||
|
|
||||||
stree
|
stree
|
||||||
install
|
install
|
||||||
hyperparameters
|
hyperparameters
|
||||||
|
@@ -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 = '''
|
||||||
/(
|
/(
|
||||||
@@ -13,4 +73,4 @@ exclude = '''
|
|||||||
| build
|
| build
|
||||||
| dist
|
| dist
|
||||||
)/
|
)/
|
||||||
'''
|
'''
|
||||||
|
@@ -1,2 +1,3 @@
|
|||||||
scikit-learn>0.24
|
scikit-learn==1.5.2
|
||||||
mufs
|
coverage
|
||||||
|
mufs
|
||||||
|
@@ -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,
|
|
||||||
)
|
|
@@ -414,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:]
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -529,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
|
||||||
|
|
||||||
@@ -742,7 +746,7 @@ class Splitter:
|
|||||||
Train time - True / Test time - False
|
Train time - True / Test time - False
|
||||||
"""
|
"""
|
||||||
# data contains the distances of every sample to every class hyperplane
|
# data contains the distances of every sample to every class hyperplane
|
||||||
# array of (m, nc) nc = # classes
|
# array of (m, nc) nc = k if ovr, nc = k*(k-1)/2 if ovo
|
||||||
data = self._distances(node, samples)
|
data = self._distances(node, samples)
|
||||||
if data.shape[0] < self._min_samples_split:
|
if data.shape[0] < self._min_samples_split:
|
||||||
# there aren't enough samples to split
|
# there aren't enough samples to split
|
||||||
|
@@ -168,12 +168,18 @@ class Stree(BaseEstimator, ClassifierMixin):
|
|||||||
self.splitter = splitter
|
self.splitter = splitter
|
||||||
self.normalize = normalize
|
self.normalize = normalize
|
||||||
self.multiclass_strategy = multiclass_strategy
|
self.multiclass_strategy = multiclass_strategy
|
||||||
|
self.depth_ = 0
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def version() -> str:
|
def version() -> str:
|
||||||
"""Return the version of the package."""
|
"""Return the version of the package."""
|
||||||
return __version__
|
return __version__
|
||||||
|
|
||||||
|
def __call__(self) -> None:
|
||||||
|
"""Only added to comply with scikit-learn base sestimator for
|
||||||
|
ensembles"""
|
||||||
|
pass
|
||||||
|
|
||||||
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
|
||||||
@@ -184,7 +190,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
|
||||||
|
|
||||||
@@ -339,7 +348,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
|
||||||
|
@@ -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.2"
|
__version__ = "1.4.0"
|
||||||
|
@@ -289,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,
|
||||||
@@ -440,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,
|
||||||
@@ -455,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]),
|
||||||
)
|
)
|
||||||
@@ -593,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):
|
||||||
@@ -725,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.assertIsNone(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