# Phosadsorption

**Phosadsorption** is a Python library for predicting phosphorus (P) adsorption in soils using machine learning. It replaces traditional empirical models like the Langmuir isotherm with a data-driven approach built on XGBoost.

## Why Phosadsorption?

While the Langmuir isotherm has been widely used to model phosphorus adsorption, it often fails to capture the variability seen in real-world soils with diverse physicochemical characteristics. This library introduces a **multioutput XGBoost regressor** trained on soil data to predict phosphorus adsorption across multiple equilibrium concentrations simultaneously.

## Key Features

- 🔬 Predicts phosphorus adsorption at 1, 2, 4, 6, and 10 mg/L equilibrium concentrations.
- 📈 Outperforms traditional models like Langmuir in predictive accuracy.
- 🧪 Built for soil scientists, agronomists, and environmental engineers.
- 📦 Easy to install and use with just a few lines of code.

## Installation

Install from PyPI:

```bash
pip install phosadsorption
```

Or install from TestPyPI for pre-release versions:

```bash
pip install --index-url https://test.pypi.org/simple/ phosadsorption
```

## Example Usage

```python
from phosadsorption import PhosAdsorption
from phosadsorption.visuals.plot import plot_pfp_vs_applied
import pandas as pd

# Load your input data
df = pd.read_excel("your_input.xlsx")

# Initialize and run the model
model = PhosAdsorption()
result = model.predict(df)

# Plot results for first sample
plot_pfp_vs_applied(result, sample_index=0)
```

## Project Structure

```
phosadsorption/
├── model/
│   ├── model.py
│   └── multioutput_xgb_model.json
├── visuals/
│   └── plot.py
├── utils.py
```

## License

MIT License

## Citation

If you use this library in your work, please cite:

> Iatrou, M. et al. (2025). Predicting Phosphorus Adsorption in Soils Using Machine Learning.  
> *GitHub Repository:* [https://github.com/Mil-afk/soil_phosphorus_adsorption_data](https://github.com/Mil-afk/soil_phosphorus_adsorption_data)
