# prfr
Probabilistic random forest regressor: random forest model that accounts for errors in predictors and labels, yields calibrated probabilistic predictions, and corrects for bias.
For a faster and more elaborate calibration routine (highly recommended), a [JAX](https://github.com/google/jax#installation) installation is required. You can install the package with the extra `jax` feature, which will install the necessary dependencies.
## Installation
From PyPI, with `jax` feature:
```bash
pip install "prfr[jax]"
```
From PyPI, without `jax` feature:
```bash
pip install prfr
```
From Github (latest), with `jax` feature:
```bash
pip install "prfr[jax] @ git+https://github.com/al-jshen/prfr"
```
From Github (latest), without `jax` feature:
```bash
pip install "git+https://github.com/al-jshen/prfr"
```
## Example usage
```python
import numpy as np
import prfr
x_obs = np.random.uniform(0., 10., size=10000).reshape(-1, 1)
x_err = np.random.exponential(1., size=10000).reshape(-1, 1)
y_obs = np.random.normal(x_obs, x_err).reshape(-1, 1) * 2. + 1.
y_err = np.ones_like(y_obs)
train, test, valid = prfr.split_arrays(x_obs, y_obs, x_err, y_err, test_size=0.2, valid_size=0.2)
model = prfr.ProbabilisticRandomForestRegressor(n_estimators=250, n_jobs=-1)
model.fit(train[0], train[1], eX=train[2], eY=train[3])
model.fit_bias(valid[0], valid[1], eX=valid[2])
# check whether the calibration routine will run with JAX
print(prfr.has_jax)
model.calibrate(valid[0], valid[1], eX=valid[2])
pred = model.predict(test[0], eX=test[2])
pred_qtls = np.quantile(pred, [0.16, 0.5, 0.84], axis=-1)
print(pred.shape)
```
Raw data
{
"_id": null,
"home_page": "https://github.com/al-jshen/prfr",
"name": "prfr",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8,<4.0",
"maintainer_email": "",
"keywords": "machine learning,random forest,regression,probabilistic,modeling",
"author": "Jeff Shen",
"author_email": "shenjeff@princeton.edu",
"download_url": "https://files.pythonhosted.org/packages/a3/86/b60b88aa53afe24575b5b29f47f306cde861d7f6a98ba8bd3807865ac254/prfr-0.2.4.tar.gz",
"platform": null,
"description": "# prfr\n\nProbabilistic random forest regressor: random forest model that accounts for errors in predictors and labels, yields calibrated probabilistic predictions, and corrects for bias.\n\nFor a faster and more elaborate calibration routine (highly recommended), a [JAX](https://github.com/google/jax#installation) installation is required. You can install the package with the extra `jax` feature, which will install the necessary dependencies. \n\n## Installation\n\nFrom PyPI, with `jax` feature:\n```bash\npip install \"prfr[jax]\" \n```\n\nFrom PyPI, without `jax` feature:\n```bash\npip install prfr\n```\n\nFrom Github (latest), with `jax` feature:\n\n```bash\npip install \"prfr[jax] @ git+https://github.com/al-jshen/prfr\"\n```\n\nFrom Github (latest), without `jax` feature:\n\n```bash\npip install \"git+https://github.com/al-jshen/prfr\"\n```\n\n## Example usage\n\n```python\nimport numpy as np\nimport prfr\n\nx_obs = np.random.uniform(0., 10., size=10000).reshape(-1, 1)\nx_err = np.random.exponential(1., size=10000).reshape(-1, 1)\ny_obs = np.random.normal(x_obs, x_err).reshape(-1, 1) * 2. + 1.\ny_err = np.ones_like(y_obs)\n\ntrain, test, valid = prfr.split_arrays(x_obs, y_obs, x_err, y_err, test_size=0.2, valid_size=0.2)\n\nmodel = prfr.ProbabilisticRandomForestRegressor(n_estimators=250, n_jobs=-1)\nmodel.fit(train[0], train[1], eX=train[2], eY=train[3])\nmodel.fit_bias(valid[0], valid[1], eX=valid[2])\n\n# check whether the calibration routine will run with JAX\nprint(prfr.has_jax)\n\nmodel.calibrate(valid[0], valid[1], eX=valid[2])\n\npred = model.predict(test[0], eX=test[2])\npred_qtls = np.quantile(pred, [0.16, 0.5, 0.84], axis=-1)\n\nprint(pred.shape)\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Probabilitic random forest regression algorithm",
"version": "0.2.4",
"split_keywords": [
"machine learning",
"random forest",
"regression",
"probabilistic",
"modeling"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "6859580b808ea2cb6db6c81b2bcc06109e31e401bacc1067d2719ea4991dc840",
"md5": "2839aff3cb4b50217e98b1a96d56d4c6",
"sha256": "31ef629509d63d84fb8a763aab981c64e9e14d4ce49ca093ee7dbb0b064f6923"
},
"downloads": -1,
"filename": "prfr-0.2.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "2839aff3cb4b50217e98b1a96d56d4c6",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8,<4.0",
"size": 13670,
"upload_time": "2023-01-25T05:54:04",
"upload_time_iso_8601": "2023-01-25T05:54:04.985000Z",
"url": "https://files.pythonhosted.org/packages/68/59/580b808ea2cb6db6c81b2bcc06109e31e401bacc1067d2719ea4991dc840/prfr-0.2.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "a386b60b88aa53afe24575b5b29f47f306cde861d7f6a98ba8bd3807865ac254",
"md5": "7b0469f4414cb8d806b84ff613e09d85",
"sha256": "406bdb6c52bafde4c3f02104def34c02254fcd6b56d0577454bb280b6da87c91"
},
"downloads": -1,
"filename": "prfr-0.2.4.tar.gz",
"has_sig": false,
"md5_digest": "7b0469f4414cb8d806b84ff613e09d85",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8,<4.0",
"size": 13983,
"upload_time": "2023-01-25T05:54:07",
"upload_time_iso_8601": "2023-01-25T05:54:07.122838Z",
"url": "https://files.pythonhosted.org/packages/a3/86/b60b88aa53afe24575b5b29f47f306cde861d7f6a98ba8bd3807865ac254/prfr-0.2.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-01-25 05:54:07",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "al-jshen",
"github_project": "prfr",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "prfr"
}