STree


NameSTree JSON
Version 1.3.2 PyPI version JSON
download
home_pagehttps://github.com/Doctorado-ML/STree#stree
SummaryOblique decision tree with svm nodes
upload_time2023-11-27 09:25:15
maintainer
docs_urlNone
authorRicardo Montañana Gómez
requires_python
licenseMIT License
keywords scikit-learn oblique-classifier oblique-decision-tree decision- tree svm svc
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            ![CI](https://github.com/Doctorado-ML/STree/workflows/CI/badge.svg)
[![CodeQL](https://github.com/Doctorado-ML/STree/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/Doctorado-ML/STree/actions/workflows/codeql-analysis.yml)
[![codecov](https://codecov.io/gh/doctorado-ml/stree/branch/master/graph/badge.svg)](https://codecov.io/gh/doctorado-ml/stree)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/35fa3dfd53a24a339344b33d9f9f2f3d)](https://www.codacy.com/gh/Doctorado-ML/STree?utm_source=github.com&utm_medium=referral&utm_content=Doctorado-ML/STree&utm_campaign=Badge_Grade)
[![PyPI version](https://badge.fury.io/py/STree.svg)](https://badge.fury.io/py/STree)
![https://img.shields.io/badge/python-3.8%2B-blue](https://img.shields.io/badge/python-3.8%2B-brightgreen)
[![DOI](https://zenodo.org/badge/262658230.svg)](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.

![Stree](https://raw.github.com/doctorado-ml/stree/master/example.png)

## Installation

```bash
pip install git+https://github.com/doctorado-ml/stree
```

## Documentation

Can be found in [stree.readthedocs.io](https://stree.readthedocs.io/en/stable/)

## Examples

### Jupyter notebooks

- [![benchmark](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/Doctorado-ML/STree/blob/master/notebooks/benchmark.ipynb) Benchmark

- [![features](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/Doctorado-ML/STree/blob/master/notebooks/features.ipynb) Some features

- [![Gridsearch](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/Doctorado-ML/STree/blob/master/notebooks/gridsearch.ipynb) Gridsearch

- [![Ensemble](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/Doctorado-ML/STree/blob/master/notebooks/ensemble.ipynb) Ensembles

## Hyperparameters

|     | **Hyperparameter**  | **Type/Values**                                                | **Default** | **Meaning**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| --- | ------------------- | -------------------------------------------------------------- | ----------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| \*  | C                   | \<float\>                                                      | 1.0         | Regularization parameter. The strength of the regularization is inversely proportional to C. Must be strictly positive.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| \*  | kernel              | {"liblinear", "linear", "poly", "rbf", "sigmoid"}              | linear      | Specifies the kernel type to be used in the algorithm. It must be one of ‘liblinear’, ‘linear’, ‘poly’ or ‘rbf’. liblinear uses [liblinear](https://www.csie.ntu.edu.tw/~cjlin/liblinear/) library and the rest uses [libsvm](https://www.csie.ntu.edu.tw/~cjlin/libsvm/) library through scikit-learn library                                                                                                                                                                                                                                                                                                                          |
| \*  | max_iter            | \<int\>                                                        | 1e5         | Hard limit on iterations within solver, or -1 for no limit.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| \*  | random_state        | \<int\>                                                        | None        | Controls the pseudo random number generation for shuffling the data for probability estimates. Ignored when probability is False.<br>Pass an int for reproducible output across multiple function calls                                                                                                                                                                                                                                                                                                                                                                                                                                 |
|     | max_depth           | \<int\>                                                        | None        | Specifies the maximum depth of the tree                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| \*  | tol                 | \<float\>                                                      | 1e-4        | Tolerance for stopping criterion.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| \*  | degree              | \<int\>                                                        | 3           | Degree of the polynomial kernel function (‘poly’). Ignored by all other kernels.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| \*  | gamma               | {"scale", "auto"} or \<float\>                                 | scale       | Kernel coefficient for ‘rbf’, ‘poly’ and ‘sigmoid’.<br>if gamma='scale' (default) is passed then it uses 1 / (n_features \* X.var()) as value of gamma,<br>if ‘auto’, uses 1 / n_features.                                                                                                                                                                                                                                                                                                                                                                                                                                              |
|     | split_criteria      | {"impurity", "max_samples"}                                    | impurity    | Decides (just in case of a multi class classification) which column (class) use to split the dataset in a node\*\*. max_samples is incompatible with 'ovo' multiclass_strategy                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
|     | criterion           | {“gini”, “entropy”}                                            | entropy     | The function to measure the quality of a split (only used if max_features != num_features). <br>Supported criteria are “gini” for the Gini impurity and “entropy” for the information gain.                                                                                                                                                                                                                                                                                                                                                                                                                                             |
|     | min_samples_split   | \<int\>                                                        | 0           | The minimum number of samples required to split an internal node. 0 (default) for any                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
|     | max_features        | \<int\>, \<float\> <br><br>or {“auto”, “sqrt”, “log2”}         | None        | The number of features to consider when looking for the split:<br>If int, then consider max_features features at each split.<br>If float, then max_features is a fraction and int(max_features \* n_features) features are considered at each split.<br>If “auto”, then max_features=sqrt(n_features).<br>If “sqrt”, then max_features=sqrt(n_features).<br>If “log2”, then max_features=log2(n_features).<br>If None, then max_features=n_features.                                                                                                                                                                                    |
|     | splitter            | {"best", "random", "trandom", "mutual", "cfs", "fcbf", "iwss"} | "random"    | The strategy used to choose the feature set at each node (only used if max_features < num_features).
Supported strategies are: **“best”**: sklearn SelectKBest algorithm is used in every node to choose the max_features best features. **“random”**: The algorithm generates 5 candidates and choose the best (max. info. gain) of them. **“trandom”**: The algorithm generates only one random combination. **"mutual"**: Chooses the best features w.r.t. their mutual info with the label. **"cfs"**: Apply Correlation-based Feature Selection. **"fcbf"**: Apply Fast Correlation-Based Filter. **"iwss"**: IWSS based algorithm |
|     | normalize           | \<bool\>                                                       | False       | If standardization of features should be applied on each node with the samples that reach it                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| \*  | multiclass_strategy | {"ovo", "ovr"}                                                 | "ovo"       | Strategy to use with multiclass datasets, **"ovo"**: one versus one. **"ovr"**: one versus rest                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |

\* Hyperparameter used by the support vector classifier of every node

\*\* **Splitting in a STree node**

The decision function is applied to the dataset and distances from samples to hyperplanes are computed in a matrix. This matrix has as many columns as classes the samples belongs to (if more than two, i.e. multiclass classification) or 1 column if it's a binary class dataset. In binary classification only one hyperplane is computed and therefore only one column is needed to store the distances of the samples to it. If three or more classes are present in the dataset we need as many hyperplanes as classes are there, and therefore one column per hyperplane is needed.

In case of multiclass classification we have to decide which column take into account to make the split, that depends on hyperparameter _split_criteria_, if "impurity" is chosen then STree computes information gain of every split candidate using each column and chooses the one that maximize the information gain, otherwise STree choses the column with more samples with a predicted class (the column with more positive numbers in it).

Once we have the column to take into account for the split, the algorithm splits samples with positive distances to hyperplane from the rest.

## Tests

```bash
python -m unittest -v stree.tests
```

## License

STree is [MIT](https://github.com/doctorado-ml/stree/blob/master/LICENSE) licensed

## Reference

R. Montañana, J. A. Gámez, J. M. Puerta, "STree: a single multi-class oblique decision tree based on support vector machines.", 2021 LNAI 12882, pg. 54-64

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Doctorado-ML/STree#stree",
    "name": "STree",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "scikit-learn oblique-classifier oblique-decision-tree decision-    tree svm svc",
    "author": "Ricardo Monta\u00f1ana G\u00f3mez",
    "author_email": "ricardo.montanana@alu.uclm.es",
    "download_url": "https://files.pythonhosted.org/packages/a8/a6/d1337f6628700c17dc7007199d6746bf9f32f435927aba59f5373bf03862/STree-1.3.2.tar.gz",
    "platform": null,
    "description": "![CI](https://github.com/Doctorado-ML/STree/workflows/CI/badge.svg)\n[![CodeQL](https://github.com/Doctorado-ML/STree/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/Doctorado-ML/STree/actions/workflows/codeql-analysis.yml)\n[![codecov](https://codecov.io/gh/doctorado-ml/stree/branch/master/graph/badge.svg)](https://codecov.io/gh/doctorado-ml/stree)\n[![Codacy Badge](https://app.codacy.com/project/badge/Grade/35fa3dfd53a24a339344b33d9f9f2f3d)](https://www.codacy.com/gh/Doctorado-ML/STree?utm_source=github.com&utm_medium=referral&utm_content=Doctorado-ML/STree&utm_campaign=Badge_Grade)\n[![PyPI version](https://badge.fury.io/py/STree.svg)](https://badge.fury.io/py/STree)\n![https://img.shields.io/badge/python-3.8%2B-blue](https://img.shields.io/badge/python-3.8%2B-brightgreen)\n[![DOI](https://zenodo.org/badge/262658230.svg)](https://zenodo.org/badge/latestdoi/262658230)\n\n# STree\n\nOblique 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.\n\n![Stree](https://raw.github.com/doctorado-ml/stree/master/example.png)\n\n## Installation\n\n```bash\npip install git+https://github.com/doctorado-ml/stree\n```\n\n## Documentation\n\nCan be found in [stree.readthedocs.io](https://stree.readthedocs.io/en/stable/)\n\n## Examples\n\n### Jupyter notebooks\n\n- [![benchmark](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/Doctorado-ML/STree/blob/master/notebooks/benchmark.ipynb) Benchmark\n\n- [![features](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/Doctorado-ML/STree/blob/master/notebooks/features.ipynb) Some features\n\n- [![Gridsearch](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/Doctorado-ML/STree/blob/master/notebooks/gridsearch.ipynb) Gridsearch\n\n- [![Ensemble](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/Doctorado-ML/STree/blob/master/notebooks/ensemble.ipynb) Ensembles\n\n## Hyperparameters\n\n|     | **Hyperparameter**  | **Type/Values**                                                | **Default** | **Meaning**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |\n| --- | ------------------- | -------------------------------------------------------------- | ----------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| \\*  | C                   | \\<float\\>                                                      | 1.0         | Regularization parameter. The strength of the regularization is inversely proportional to C. Must be strictly positive.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |\n| \\*  | kernel              | {\"liblinear\", \"linear\", \"poly\", \"rbf\", \"sigmoid\"}              | linear      | Specifies the kernel type to be used in the algorithm. It must be one of \u2018liblinear\u2019, \u2018linear\u2019, \u2018poly\u2019 or \u2018rbf\u2019. liblinear uses [liblinear](https://www.csie.ntu.edu.tw/~cjlin/liblinear/) library and the rest uses [libsvm](https://www.csie.ntu.edu.tw/~cjlin/libsvm/) library through scikit-learn library                                                                                                                                                                                                                                                                                                                          |\n| \\*  | max_iter            | \\<int\\>                                                        | 1e5         | Hard limit on iterations within solver, or -1 for no limit.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |\n| \\*  | random_state        | \\<int\\>                                                        | None        | Controls the pseudo random number generation for shuffling the data for probability estimates. Ignored when probability is False.<br>Pass an int for reproducible output across multiple function calls                                                                                                                                                                                                                                                                                                                                                                                                                                 |\n|     | max_depth           | \\<int\\>                                                        | None        | Specifies the maximum depth of the tree                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |\n| \\*  | tol                 | \\<float\\>                                                      | 1e-4        | Tolerance for stopping criterion.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |\n| \\*  | degree              | \\<int\\>                                                        | 3           | Degree of the polynomial kernel function (\u2018poly\u2019). Ignored by all other kernels.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |\n| \\*  | gamma               | {\"scale\", \"auto\"} or \\<float\\>                                 | scale       | Kernel coefficient for \u2018rbf\u2019, \u2018poly\u2019 and \u2018sigmoid\u2019.<br>if gamma='scale' (default) is passed then it uses 1 / (n_features \\* X.var()) as value of gamma,<br>if \u2018auto\u2019, uses 1 / n_features.                                                                                                                                                                                                                                                                                                                                                                                                                                              |\n|     | split_criteria      | {\"impurity\", \"max_samples\"}                                    | impurity    | Decides (just in case of a multi class classification) which column (class) use to split the dataset in a node\\*\\*. max_samples is incompatible with 'ovo' multiclass_strategy                                                                                                                                                                                                                                                                                                                                                                                                                                                          |\n|     | criterion           | {\u201cgini\u201d, \u201centropy\u201d}                                            | entropy     | The function to measure the quality of a split (only used if max_features != num_features). <br>Supported criteria are \u201cgini\u201d for the Gini impurity and \u201centropy\u201d for the information gain.                                                                                                                                                                                                                                                                                                                                                                                                                                             |\n|     | min_samples_split   | \\<int\\>                                                        | 0           | The minimum number of samples required to split an internal node. 0 (default) for any                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |\n|     | max_features        | \\<int\\>, \\<float\\> <br><br>or {\u201cauto\u201d, \u201csqrt\u201d, \u201clog2\u201d}         | None        | The number of features to consider when looking for the split:<br>If int, then consider max_features features at each split.<br>If float, then max_features is a fraction and int(max_features \\* n_features) features are considered at each split.<br>If \u201cauto\u201d, then max_features=sqrt(n_features).<br>If \u201csqrt\u201d, then max_features=sqrt(n_features).<br>If \u201clog2\u201d, then max_features=log2(n_features).<br>If None, then max_features=n_features.                                                                                                                                                                                    |\n|     | splitter            | {\"best\", \"random\", \"trandom\", \"mutual\", \"cfs\", \"fcbf\", \"iwss\"} | \"random\"    | The strategy used to choose the feature set at each node (only used if max_features < num_features).\nSupported strategies are: **\u201cbest\u201d**: sklearn SelectKBest algorithm is used in every node to choose the max_features best features. **\u201crandom\u201d**: The algorithm generates 5 candidates and choose the best (max. info. gain) of them. **\u201ctrandom\u201d**: The algorithm generates only one random combination. **\"mutual\"**: Chooses the best features w.r.t. their mutual info with the label. **\"cfs\"**: Apply Correlation-based Feature Selection. **\"fcbf\"**: Apply Fast Correlation-Based Filter. **\"iwss\"**: IWSS based algorithm |\n|     | normalize           | \\<bool\\>                                                       | False       | If standardization of features should be applied on each node with the samples that reach it                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |\n| \\*  | multiclass_strategy | {\"ovo\", \"ovr\"}                                                 | \"ovo\"       | Strategy to use with multiclass datasets, **\"ovo\"**: one versus one. **\"ovr\"**: one versus rest                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |\n\n\\* Hyperparameter used by the support vector classifier of every node\n\n\\*\\* **Splitting in a STree node**\n\nThe decision function is applied to the dataset and distances from samples to hyperplanes are computed in a matrix. This matrix has as many columns as classes the samples belongs to (if more than two, i.e. multiclass classification) or 1 column if it's a binary class dataset. In binary classification only one hyperplane is computed and therefore only one column is needed to store the distances of the samples to it. If three or more classes are present in the dataset we need as many hyperplanes as classes are there, and therefore one column per hyperplane is needed.\n\nIn case of multiclass classification we have to decide which column take into account to make the split, that depends on hyperparameter _split_criteria_, if \"impurity\" is chosen then STree computes information gain of every split candidate using each column and chooses the one that maximize the information gain, otherwise STree choses the column with more samples with a predicted class (the column with more positive numbers in it).\n\nOnce we have the column to take into account for the split, the algorithm splits samples with positive distances to hyperplane from the rest.\n\n## Tests\n\n```bash\npython -m unittest -v stree.tests\n```\n\n## License\n\nSTree is [MIT](https://github.com/doctorado-ml/stree/blob/master/LICENSE) licensed\n\n## Reference\n\nR. Monta\u00f1ana, J. A. G\u00e1mez, J. M. Puerta, \"STree: a single multi-class oblique decision tree based on support vector machines.\", 2021 LNAI 12882, pg. 54-64\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "Oblique decision tree with svm nodes",
    "version": "1.3.2",
    "project_urls": {
        "Code": "https://github.com/Doctorado-ML/STree",
        "Documentation": "https://stree.readthedocs.io/en/latest/index.html",
        "Homepage": "https://github.com/Doctorado-ML/STree#stree"
    },
    "split_keywords": [
        "scikit-learn",
        "oblique-classifier",
        "oblique-decision-tree",
        "decision-",
        "",
        "",
        "",
        "tree",
        "svm",
        "svc"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "dacf32e1576c2dd832075e7de0bfc031f04043b6bebd8cffef1e76736675ddab",
                "md5": "4b02ae61cef4255479c941e6b30169e5",
                "sha256": "bf99e90705fb371837333ec13455fd6d553a4829e18d2d5d2804a2b433514060"
            },
            "downloads": -1,
            "filename": "STree-1.3.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4b02ae61cef4255479c941e6b30169e5",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 26839,
            "upload_time": "2023-11-27T09:25:13",
            "upload_time_iso_8601": "2023-11-27T09:25:13.387464Z",
            "url": "https://files.pythonhosted.org/packages/da/cf/32e1576c2dd832075e7de0bfc031f04043b6bebd8cffef1e76736675ddab/STree-1.3.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a8a6d1337f6628700c17dc7007199d6746bf9f32f435927aba59f5373bf03862",
                "md5": "de95eb0b6f4d99234f26cb86f25a3990",
                "sha256": "a20ffd00f18b57c5ddf95efd3ef1615f19afa1a56b129f2893bdc30c3fe2fd60"
            },
            "downloads": -1,
            "filename": "STree-1.3.2.tar.gz",
            "has_sig": false,
            "md5_digest": "de95eb0b6f4d99234f26cb86f25a3990",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 24535,
            "upload_time": "2023-11-27T09:25:15",
            "upload_time_iso_8601": "2023-11-27T09:25:15.590506Z",
            "url": "https://files.pythonhosted.org/packages/a8/a6/d1337f6628700c17dc7007199d6746bf9f32f435927aba59f5373bf03862/STree-1.3.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-27 09:25:15",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Doctorado-ML",
    "github_project": "STree#stree",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "requirements": [],
    "lcname": "stree"
}
        
Elapsed time: 0.16855s