https://github.com/jokoum/stochastic-gradient-trees-python
Stochastic Gradient Trees implementation in Python
https://github.com/jokoum/stochastic-gradient-trees-python
classification-algorithm machine-learning python regression-algorithms scikit-learn sklearn stochastic-gradient tree-algorithms tree-classifiers tree-regressor
Last synced: 4 months ago
JSON representation
Stochastic Gradient Trees implementation in Python
- Host: GitHub
- URL: https://github.com/jokoum/stochastic-gradient-trees-python
- Owner: JoKoum
- License: mit
- Created: 2021-10-18T19:15:20.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-11-18T18:15:28.000Z (over 2 years ago)
- Last Synced: 2025-02-17T05:46:47.196Z (4 months ago)
- Topics: classification-algorithm, machine-learning, python, regression-algorithms, scikit-learn, sklearn, stochastic-gradient, tree-algorithms, tree-classifiers, tree-regressor
- Language: Python
- Homepage: https://pypi.org/project/pysgt/
- Size: 85 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
Stochastic Gradient Trees - Python
=========================[Stochastic Gradient Trees](https://arxiv.org/abs/1901.07777)[^1] by Henry Gouk, Bernhard Pfahringer, and Eibe Frank implementation in Python. Based on the [parer's accompanied repository](https://github.com/henrygouk/stochastic-gradient-trees) code.
### Python Version 3.7 or later
### Used Python libraries:
* numpy>=1.20.2
* scipy>=1.6.2
* pandas>=1.3.3
* scikit-learn>=0.24.2### Usage:
```python
from pysgt.StochasticGradientTree import StochasticGradientTreeClassifierfrom sklearn.model_selection import train_test_split
from sklearn.datasets import load_breast_cancer
from sklearn.metrics import confusion_matrix, accuracy_score, log_lossdef train(X, y):
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.34)
tree = StochasticGradientTreeClassifier()tree.fit(X_train, y_train)
y_pred = tree.predict(X_test)proba = tree.predict_proba(X_test)
acc_test = accuracy_score(y_test, y_pred)
print(confusion_matrix(y_test, y_pred))
print('Acc test: ', acc_test)
print('Cross entropy loss: ', log_loss(y_test, proba))return tree, acc_test
if __name__ == "__main__":
breast = load_breast_cancer(as_frame=True)
X = breast.frame.copy()
y = breast.frame.target
X.drop(['target'], axis=1, inplace=True)tree, _ = train(X, y)
```
### Binary classification example:
python classification_breast.py
### Multiclass classification (using the [One-vs-the-rest](https://scikit-learn.org/stable/modules/generated/sklearn.multiclass.OneVsRestClassifier.html) multiclass strategy):
python classification_iris.py
### Regression example:
python regression_diabetes.py
[^1]: Gouk, H., Pfahringer, B., and Frank, E. Stochastic gradient trees. In Proceedings of The Eleventh Asian Conference on Machine Learning, volume 101 of Proceedings of Machine Learning Research, pp. 1094–1109. PMLR, 2019.