Metadata-Version: 2.4
Name: ipytreecraft
Version: 0.1.0
Summary: Incremental, interactive decision tree builder for risk specialists
Author-email: Mark <mark@example.com>
Classifier: Framework :: Jupyter
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.11
Requires-Dist: joblib>=1.3
Requires-Dist: numpy>=1.26
Requires-Dist: pandas>=2.0
Requires-Dist: pydantic>=2.0
Requires-Dist: scikit-learn<2.0,>=1.5
Provides-Extra: api
Requires-Dist: fastapi>=0.110; extra == 'api'
Requires-Dist: python-multipart>=0.0.9; extra == 'api'
Requires-Dist: slowapi>=0.1.9; extra == 'api'
Requires-Dist: uvicorn[standard]>=0.29; extra == 'api'
Provides-Extra: dev
Requires-Dist: httpx>=0.27; extra == 'dev'
Requires-Dist: pytest-cov>=5.0; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: ruff>=0.4; extra == 'dev'
Provides-Extra: jupyter
Requires-Dist: anywidget>=0.9.13; extra == 'jupyter'
Requires-Dist: jupyterlab>=4.0; extra == 'jupyter'
Description-Content-Type: text/markdown

# Treecraft

[![CI](https://github.com/markdedeuge/treecraft/actions/workflows/ci.yml/badge.svg)](https://github.com/markdedeuge/treecraft/actions/workflows/ci.yml) [![Coverage](https://img.shields.io/badge/coverage-96%25-success)](https://github.com/markdedeuge/treecraft) [![PyPI version](https://img.shields.io/pypi/v/treecraft.svg)](https://pypi.org/project/treecraft/) [![Downloads](https://img.shields.io/pypi/dm/treecraft.svg)](https://pypi.org/project/treecraft/) [![License](https://img.shields.io/badge/license-MIT-success)](https://github.com/markdedeuge/treecraft/blob/main/LICENSE)

Treecraft is an interactive decision tree framework. Treecraft allows analysts to manually evaluate, override, and prune decision boundaries utilizing an interactive UI interface, while automatically refitting subtrees optimally beneath manual split points.

![Treecraft Interface](docs/treecraftui.png)

The framework extends standard Scikit-Learn. Modifications made visually in the interface alter splits in the underlying tree graph. The resulting model can then be exported as a standard, fitted `DecisionTreeClassifier` or `DecisionTreeRegressor` compatible with standard sklearn pipelines.

## Installation

This module provides an interactive interface built upon `anywidget` for integration into Jupyter ecosystems.

Install from source locally via standard python package deployment:

```bash
pip install -e .
```

## Usage

Initiate the widget by supplying a `pandas.DataFrame` and declaring the target feature.

```python
import pandas as pd
from sklearn.datasets import load_iris
from treecraft.widget import TreecraftWidget

data = load_iris()
df = pd.DataFrame(data.data, columns=data.feature_names)
df['target'] = data.target

# Instantiate the interactive widget
widget = TreecraftWidget(df=df, target='target', model_id='iris_model')
widget
```

Once the interactive visualization opens, users can apply initial hyperparameters, manually navigate tree partitions, append/remove split points, and verify node performance across configurable train/validation splits.

### Pipeline Extraction

After modifying the boundaries visually to conform to the required constraints, extract the native Scikit-Learn estimator.

```python
from sklearn.pipeline import make_pipeline

# Extract the fitted Scikit-Learn estimator structure
clf = widget.export_sklearn()
pipeline = make_pipeline(clf)

# Execute predictions
X_test = df.drop(columns=['target'])
predictions = pipeline.predict(X_test)
```

