diff --git a/.gitignore b/.gitignore index ad9f878..fa8f3d9 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ .env/ __pycache__/ *.cpython-* +docs/_build diff --git a/.readthedocs.yaml b/.readthedocs.yaml new file mode 100644 index 0000000..a6e4123 --- /dev/null +++ b/.readthedocs.yaml @@ -0,0 +1,21 @@ +# .readthedocs.yaml +# Read the Docs configuration file +# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details + +# Required +version: 2 + +# Set the OS, Python version and other tools you might need +build: + os: ubuntu-22.04 + tools: + python: "3.12" + rust: "1.70" + +# Build documentation in the "docs/" directory with Sphinx +sphinx: + configuration: docs/conf.py + +python: + install: + - requirements: docs/requirements.txt diff --git a/Cargo.lock b/Cargo.lock index dcd60b8..dab616c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1160,7 +1160,7 @@ dependencies = [ [[package]] name = "rustrees" -version = "0.1.0" +version = "0.2.0" dependencies = [ "arrow", "criterion", diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 0000000..d4bb2cb --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,20 @@ +# Minimal makefile for Sphinx documentation +# + +# You can set these variables from the command line, and also +# from the environment for the first two. +SPHINXOPTS ?= +SPHINXBUILD ?= sphinx-build +SOURCEDIR = . +BUILDDIR = _build + +# Put it first so that "make" without argument is like "make help". +help: + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + +.PHONY: help Makefile + +# Catch-all target: route all unknown targets to Sphinx using the new +# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). +%: Makefile + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 0000000..7cb3357 --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,32 @@ +import os +import sys + +sys.path.insert(0, os.path.abspath("../python/")) + +# Configuration file for the Sphinx documentation builder. +# +# For the full list of built-in configuration values, see the documentation: +# https://www.sphinx-doc.org/en/master/usage/configuration.html + +# -- Project information ----------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information + +project = "rustrees" +copyright = "2023, Pedro Tabacof, Guilherme Lázari" +author = "Pedro Tabacof, Guilherme Lázari" + +# -- General configuration --------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration + +extensions = ["sphinx.ext.autodoc", "sphinx.ext.napoleon"] + +templates_path = ["_templates"] +exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] + +autoclass_content = "both" + +# -- Options for HTML output ------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output + +html_theme = "sphinx_rtd_theme" +html_static_path = ["_static"] diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 0000000..fc598dd --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,42 @@ +.. rustrees documentation master file, created by + sphinx-quickstart on Wed Dec 6 19:31:26 2023. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +Welcome to rustrees's documentation! +==================================== + +.. toctree:: + :maxdepth: 2 + :caption: Contents: + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` + +Decision trees +=============== + +.. automodule:: rustrees.decision_tree + :members: + :undoc-members: + :show-inheritance: + +Random forests +=============== + +.. automodule:: rustrees.random_forest + :members: + :undoc-members: + :show-inheritance: + +Utils +=============== + +.. automodule:: rustrees.utils + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/make.bat b/docs/make.bat new file mode 100644 index 0000000..32bb245 --- /dev/null +++ b/docs/make.bat @@ -0,0 +1,35 @@ +@ECHO OFF + +pushd %~dp0 + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set SOURCEDIR=. +set BUILDDIR=_build + +%SPHINXBUILD% >NUL 2>NUL +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.https://www.sphinx-doc.org/ + exit /b 1 +) + +if "%1" == "" goto help + +%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% +goto end + +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% + +:end +popd diff --git a/docs/requirements.txt b/docs/requirements.txt new file mode 100644 index 0000000..8213302 --- /dev/null +++ b/docs/requirements.txt @@ -0,0 +1,2 @@ +sphinx +sphinx_rtd_theme diff --git a/python/rustrees/decision_tree.py b/python/rustrees/decision_tree.py index 0412ba6..3c5307c 100644 --- a/python/rustrees/decision_tree.py +++ b/python/rustrees/decision_tree.py @@ -84,6 +84,11 @@ def predict_proba(self, X) -> List: class DecisionTreeRegressor(DecisionTree, ClassifierMixin): + """ + Decision tree regressor implemented using Rust. + Usage should be similar to scikit-learn's DecisionTreeRegressor. + """ + def __init__(self, **kwargs): super(DecisionTreeRegressor, self).__init__(**kwargs) @@ -104,6 +109,11 @@ def predict(self, X) -> List: class DecisionTreeClassifier(DecisionTree, RegressorMixin): + """ + Decision tree classifier implemented using Rust. + Usage should be similar to scikit-learn's DecisionTreeClassifier. + """ + def __init__(self, **kwargs): super(DecisionTreeClassifier, self).__init__(**kwargs) diff --git a/python/rustrees/random_forest.py b/python/rustrees/random_forest.py index af8722d..ce5d903 100644 --- a/python/rustrees/random_forest.py +++ b/python/rustrees/random_forest.py @@ -88,6 +88,11 @@ def predict_proba(self, X) -> List: class RandomForestRegressor(RandomForest, RegressorMixin): + """ + A random forest regressor implemented using Rust. + Usage should be similar to scikit-learn's RandomForestRegressor. + """ + def __init__(self, **kwargs): super(RandomForestRegressor, self).__init__(**kwargs) @@ -109,6 +114,11 @@ def predict(self, X) -> List: class RandomForestClassifier(RandomForest, ClassifierMixin): + """ + A random forest classifier implemented using Rust. + Usage should be similar to scikit-learn's RandomForestClassifier. + """ + def __init__(self, **kwargs): super(RandomForestClassifier, self).__init__(**kwargs)