Metadata-Version: 2.4
Name: tosa-ml
Version: 0.4.0
Summary: Reusable machine-learning preprocessing and training components
Author: Tosa ML contributors
License: MIT
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=1.24
Requires-Dist: pandas>=2.0
Requires-Dist: scikit-learn>=1.3
Requires-Dist: joblib>=1.2
Provides-Extra: test
Requires-Dist: pytest>=7.4; extra == "test"
Dynamic: license-file

# Tosa ML

Preprocess and train a tabular ML model in **one line**.

```bash
pip install tosa-ml
```

> The pip name is `tosa-ml`; you import it as `tosa_ml` (Python imports cannot contain hyphens).

## Preprocess in one line

```python
from tosa_ml import preprocess

X_train, X_test, y_train, y_test = preprocess("data.csv", target="price")
```

`data` can be a DataFrame or a file path (csv, tsv, xlsx, json, parquet). Automatically done, in order:
remove duplicate rows -> drop rows with missing target -> train/test split (stratified for classification)
-> fill missing values -> expand datetime columns -> one-hot encode text columns -> scale numbers.
Everything is learned on the train split only, so nothing leaks from the test split.

Optional: `missing="none"`, `encoding="none"`, `scaling="standard|minmax|robust|none"`, `outliers="iqr"`, `test_size=0.2`, `random_state=42`.

## Preprocess + train + evaluate in one line

```python
from tosa_ml import train

result = train("data.csv", target="price", model="random_forest")

print(result.metrics)                 # test-set metrics
print(result.predict(new_raw_rows))   # predict on RAW rows, preprocessing is applied for you
result.save("model.joblib")           # model + preprocessing in one file
```

- `task` is auto-detected (`"classification"` / `"regression"`); pass `task=...` to override.
- `model` is a name from `tosa_ml.available_models()` or any scikit-learn estimator, e.g. `model=RidgeClassifier()`.
- Trees (random_forest, decision_tree, gradient_boosting, extra_trees) skip scaling; other models are scaled.
- Nothing is written to disk unless you pass `save=True` or `save="path.joblib"`.
- A short step-by-step summary is printed; use `verbose=False` to silence it.

Reload later:

```python
import tosa_ml
model = tosa_ml.load("model.joblib")
model.predict(new_raw_rows)           # only load files you trust (joblib can run code)
```

Models: `tosa_ml.available_models()`
- classification: random_forest, decision_tree, logistic_regression, gradient_boosting, svc, knn, extra_trees, naive_bayes
- regression: random_forest, decision_tree, linear_regression, ridge, lasso, gradient_boosting, svr, knn, extra_trees

### Extras (optional)

```python
train("data.csv", "label", "random_forest",
      tune=True, param_space={"n_estimators": [50, 100], "max_depth": [None, 10]},
      cross_validate=True, cv=5)
```

Time-series data: random splitting is not appropriate, do not use the default split.

## Tests

```bash
pip install -e ".[test]"
pytest                      # the tests/ folder: every test uses the one-line API
python tests/try_it.py      # prints the one-line workflow on the iris dataset
```

## Publish to PyPI (so `pip install tosa-ml` works for everyone)

```bash
pip install build twine
python -m build
twine upload dist/*
```
