Metadata-Version: 2.4
Name: morphtree
Version: 2.2.0
Summary: Adaptive tree learning for tabular data with diagnostic structural evolution
Project-URL: Homepage, https://github.com/lucalullo/morph-tree
Project-URL: Source, https://github.com/lucalullo/morph-tree
License-Expression: MIT
License-File: LICENSE
Requires-Python: <3.15,>=3.12
Requires-Dist: numpy<3,>=1.26.0
Requires-Dist: optuna==5.0.0
Description-Content-Type: text/markdown

# MorphTree

[![PyPI version](https://img.shields.io/pypi/v/morphtree)](https://pypi.org/project/morphtree/)

**Adaptive tree learning for tabular data, with structural evolution and a simple Python API.**

MorphTree 2.2.0 supports binary classification, multiclass classification and single-target regression. It screens applicable native Boost and Bag tree families, selects a parent, diagnoses training errors and evaluates structural changes to the executable learning program. A descendant replaces its parent only when the internal selection criteria are satisfied; otherwise the parent is retained.

Automatic preprocessing, structural evolution, optional final numerical optimization and model persistence are available through `fit()` and `predict()`.

## Why MorphTree?

MorphTree explores changes to the tree-learning program itself, not only its
numerical parameters. A fitted model can be used directly for predictions;
inspecting or exporting the selected learning program is optional.

### Project status

An early-stage system under active development. Version 2.2.0 extends structural
search with Frontier split search, partitions32 and supported typed compositions.
It also improves fold-local preprocessing and supports autonomous trainer export
within qualified contracts. A general predictive benefit from structural evolution
has not yet been established. See the [release notes](https://github.com/lucalullo/morph-tree/blob/main/RELEASE_NOTES.md)
and [qualification scope](https://github.com/lucalullo/morph-tree/blob/main/docs/QUALIFICATION.md).

### When to use it

For research into evolving tree-learning rules, examining structural decisions,
or exploring reuse of a qualified frozen learning program.

### When to consider alternatives

Conventional tree ensembles are better starting points when fast training or
extensively validated predictive performance is the priority. MorphTree's
search requires additional computation and may retain its initial program if
no proposed modification meets the selection criteria.

## Install

```bash
pip install morphtree
```

This installs the latest compatible release available on PyPI. MorphTree 2.2.0
requires Python 3.12-3.14. Prebuilt wheels include native components on supported
platforms; source builds require a C compiler. See the
[installation guide](https://github.com/lucalullo/morph-tree/blob/main/docs/INSTALLATION.md)
for compatibility and build requirements.

## Quick start

The examples use scikit-learn datasets (`pip install scikit-learn`).

```python
from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
from morphtree import MorphTreeClassifier

X, y = load_breast_cancer(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=0.2, random_state=42, stratify=y
)
model = MorphTreeClassifier(random_state=42).fit(X_train, y_train)
print("Test accuracy:", model.score(X_test, y_test))
```

The same classifier accepts multiclass targets; use `MorphTreeRegressor` for
regression. The fitted model can predict directly, with no export step.
See [examples](https://github.com/lucalullo/morph-tree/tree/main/examples/).
This example demonstrates the API, not the benchmark protocol.

## Structural evolution

During `fit()`, MorphTree screens tree families, diagnoses errors, evaluates
structural descendants, retains accepted changes, freezes the selected program,
and runs optional final Optuna tuning followed by configured refit.
The current mutation grammar includes growth and split rules, Frontier split
search and supported typed compositions; it does not generate arbitrary
algorithms. Search adds computation, but is not repeated when predicting with
a saved fitted model.

`mode="baseline"` disables structural evolution; `use_optuna=False` disables
final numerical tuning. See [architecture](https://github.com/lucalullo/morph-tree/blob/main/docs/ARCHITECTURE.md)
and the [API reference](https://github.com/lucalullo/morph-tree/blob/main/docs/API.md).

## Inspect and reuse

```python
print(model.get_algorithm_program())
print(model.get_mutation_history())
model.save("morphtree-model.json")
restored = MorphTreeClassifier.load("morphtree-model.json")
```

Advanced APIs distinguish a standalone fitted predictor (`export_standalone`)
from a trainer of a frozen learning program (`export_algorithm`). In qualified
structural, numerical and environment contracts, the latter can learn new weights
without importing MorphTree or repeating structural search and Optuna. It requires
NumPy and the Python standard library. Unsupported export contracts are refused.
See [autonomous export](https://github.com/lucalullo/morph-tree/blob/main/docs/AUTONOMOUS_EXPORT.md)
and the [API reference](https://github.com/lucalullo/morph-tree/blob/main/docs/API.md).

## Limitations

- Structural evolution is not guaranteed to improve predictive performance; proposed mutations may all be rejected.
- Training cost includes screening and descendant fitting; no universal speed or memory advantage is established.
- Improvement on the internal SEARCH partition does not establish independent predictive benefit; refit can change held-out performance.
- Autonomous trainer export is limited to qualified contracts.
- Performance and resource requirements depend on the dataset, program and search budget.

The direct comparison without external tuning measured 1,462 of 1,488 planned
scores on FIT/SEARCH; it is exploratory. A separate prospective study evaluated
234 complete ten-method allocations on EVAL and did not demonstrate a systematic
advantage over the static parent or prior MorphTree. The original P9 protocol
was not reproduced in full. See the [benchmark overview](https://github.com/lucalullo/morph-tree/blob/main/benchmarks/README.md),
[comparison report](https://github.com/lucalullo/morph-tree/blob/main/docs/COMPARISON.md),
[capacity study](https://github.com/lucalullo/morph-tree/blob/main/docs/CAPACITY.md),
and [benchmark methodology](https://github.com/lucalullo/morph-tree/blob/main/BENCHMARKS.md).

## Documentation

- [Installation](https://github.com/lucalullo/morph-tree/blob/main/docs/INSTALLATION.md)
- [API reference](https://github.com/lucalullo/morph-tree/blob/main/docs/API.md)
- [Architecture](https://github.com/lucalullo/morph-tree/blob/main/docs/ARCHITECTURE.md)
- [Data and resource limits](https://github.com/lucalullo/morph-tree/blob/main/docs/PUBLIC_API_LIMITS.md)
- [Examples](https://github.com/lucalullo/morph-tree/tree/main/examples/)
- [Autonomous export](https://github.com/lucalullo/morph-tree/blob/main/docs/AUTONOMOUS_EXPORT.md)
- [Qualification](https://github.com/lucalullo/morph-tree/blob/main/docs/QUALIFICATION.md)
- [Release notes](https://github.com/lucalullo/morph-tree/blob/main/RELEASE_NOTES.md)
- [Changelog](https://github.com/lucalullo/morph-tree/blob/main/CHANGELOG.md)
- [Roadmap](https://github.com/lucalullo/morph-tree/blob/main/ROADMAP.md)
- [Contributing](https://github.com/lucalullo/morph-tree/blob/main/CONTRIBUTING.md)

## License

MorphTree is created by Luca Lullo and released under the [MIT License](https://github.com/lucalullo/morph-tree/blob/main/LICENSE).

## Author

Created by [Luca Lullo](https://github.com/lucalullo).
