Name | numerblox JSON |
Version |
1.4.0
JSON |
| download |
home_page | None |
Summary | Solid Numerai Pipelines |
upload_time | 2024-09-27 13:59:42 |
maintainer | None |
docs_url | None |
author | CrowdCent |
requires_python | <4,>=3.10 |
license | MIT |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
![](https://img.shields.io/pypi/v/numerblox.png)
![](https://img.shields.io/pypi/pyversions/numerblox.png)
![](https://img.shields.io/github/contributors/crowdcent/numerblox.png)
![](https://img.shields.io/codecov/c/gh/carlolepelaars/numerblox/master)
![](https://img.shields.io/pypi/dm/numerblox)
# NumerBlox
NumerBlox offers components that help with developing strong Numerai models and inference pipelines. From downloading data to submitting predictions, NumerBlox has you covered.
All components can be used standalone and all processors are fully compatible to use within [scikit-learn](https://scikit-learn.org/) pipelines.
**Documentation:**
[crowdcent.github.io/numerblox](https://crowdcent.github.io/numerblox)
## 1. Installation
### Recommended
Simply install numerblox from PyPi by running:
```bash
pip install numerblox
```
### Development
Alternatively you can clone this repository and install it in development mode using `poetry`:
```bash
git clone https://github.com/crowdcent/numerblox.git
pip install poetry
cd numerblox
poetry install
```
Installation without dev dependencies can be done by adding `--only main` to the `poetry install` line.
Test your installation using one of the education notebooks in
[examples](https://github.com/crowdcent/numerblox/examples). Good places to start are [quickstart.ipynb](https://github.com/crowdcent/numerblox/examples/quickstart.ipynb) and [numerframe_tutorial.ipynb](https://github.com/crowdcent/numerblox/examples/numerframe_tutorial.ipynb). Run it in your notebook environment to quickly test if your installation has succeeded. The documentation contains examples and explanations for each component of NumerBlox.
## 2. Core functionality
NumerBlox has the following features for both Numerai Classic and Signals:
**[Data Download](https://crowdcent.github.io/numerblox/download/):** Automated retrieval of Numerai datasets.
**[NumerFrame](https://crowdcent.github.io/numerblox/numerframe/):** A custom Pandas DataFrame for easier Numerai data manipulation.
**[Preprocessors](https://crowdcent.github.io/numerblox/preprocessing/):** Customizable techniques for data preprocessing.
**[Target Engineering](https://crowdcent.github.io/numerblox/targets/):** Tools for creating new target variables.
**[Postprocessors](https://crowdcent.github.io/numerblox/neutralization/):** Ensembling, neutralization, and penalization.
**[MetaPipeline](https://crowdcent.github.io/numerblox/meta/):** An era-aware pipeline extension of scikit-learn's Pipeline. Specifically designed to integrate with era-specific Postprocessors such as neutralization and ensembling. Can be optionally bypassed for custom implementations.
**[MetaEstimators](https://crowdcent.github.io/numerblox/meta/):** Era-aware estimators that extend scikit-learn's functionality. Includes features like CrossValEstimator which allow for era-specific, multiple-folds fitting seamlessly integrated into the pipeline.
**[Evaluation](https://crowdcent.github.io/numerblox/evaluation/):** Comprehensive metrics aligned with Numerai's evaluation criteria.
**[Submitters](https://crowdcent.github.io/numerblox/submission/):** Facilitates secure and easy submission of predictions.
**[Model Upload](https://crowdcent.github.io/numerblox/model_upload/):** Assists in the process of uploading trained models to Numerai for automated submissions.
Example notebooks for each of these components can be found in the [examples](https://github.com/crowdcent/numerblox/examples). Also check out [the documentation](https://crowdcent.github.io/numerblox) for more information.
## 3. Quick Start
Below are two examples of how NumerBlox can be used to train and do inference on Numerai data. For a full overview of all components check out the documentation. More advanced examples to leverage NumerBlox to the fullest can be found in the [End-To-End Example section](https://crowdcent.github.io/numerblox/end_to_end/).
### 3.1. Simple example
The example below shows how NumerBlox can simplify the process of downloading, loading, training, evaluating, inferring and submitting data for Numerai Classic.
NumerBlox is used here for easy downloading, data parsing, evaluation, inference and submission. You can experiment with this setup yourself in the example notebook [quickstart.ipynb](https://github.com/crowdcent/numerblox/examples/quickstart.ipynb).
#### Downloading, loading, and training
```python
from numerblox.download import NumeraiClassicDownloader
from numerblox.numerframe import create_numerframe
from xgboost import XGBRegressor
downloader = NumeraiClassicDownloader("data")
downloader.download_training_data("train_val", version="5.0")
df = create_numerframe("data/train_val/train.parquet")
X, y = df.get_feature_target_pair(multi_target=False)
model = XGBRegressor()
model.fit(X.values, y.values)
```
#### Evaluation
```python
from numerblox.prediction_loaders import ExamplePredictions
from numerblox.evaluation import NumeraiClassicEvaluator
val_df = create_numerframe("data/train_val/validation.parquet")
val_df['prediction'] = model.predict(val_df.get_feature_data)
val_df['example_preds'] = ExamplePredictions("v5.0/validation_example_preds.parquet").fit_transform(None)['prediction'].values
evaluator = NumeraiClassicEvaluator()
metrics = evaluator.full_evaluation(val_df,
example_col="example_preds",
pred_cols=["prediction"],
target_col="target")
```
#### Live Inference
```python
downloader.download_live_data("current_round", version="5.0")
live_df = create_numerframe(file_path="data/current_round/live.parquet")
live_X, live_y = live_df.get_feature_target_pair(multi_target=False)
preds = model.predict(live_X)
```
#### Submission
```python
from numerblox.misc import Key
from numerblox.submission import NumeraiClassicSubmitter
NUMERAI_PUBLIC_ID = "YOUR_PUBLIC_ID"
NUMERAI_SECRET_KEY = "YOUR_SECRET_KEY"
key = Key(pub_id=NUMERAI_PUBLIC_ID, secret_key=NUMERAI_SECRET_KEY)
submitter = NumeraiClassicSubmitter(directory_path="sub_current_round", key=key)
pred_dataf = pd.DataFrame(preds, index=live_df.index, columns=["prediction"])
submitter.full_submission(dataf=pred_dataf,
cols="prediction",
file_name="submission.csv",
model_name="MY_MODEL_NAME")
```
#### Model Upload
```python
from numerblox.submission import NumeraiModelUpload
uploader = NumeraiModelUpload(key=key, max_retries=3, sleep_time=15, fail_silently=True)
uploader.create_and_upload_model(model=model,
model_name="MY_MODEL_NAME",
file_path="models/my_model.pkl")
```
### 3.2. Advanced NumerBlox modeling
Building on the simple example, this advanced setup showcases how to leverage NumerBlox's powerful components to create a sophisticated pipeline that can replace the "simple" XGBoost model in the example above. This advanced example creates an extensible scikit-learn pipeline with metadata routing that:
- Approaches Numerai Classic as a classification problem
- Uses cross-validation with multiple folds
- Reduces classification probabilities to single values
- Creates a weighted ensemble favoring recent folds
- Applies neutralization to the predictions
#### Creating the pipeline
```python
from xgboost import XGBClassifier
from sklearn.model_selection import TimeSeriesSplit
from numerblox.meta import CrossValEstimator, make_meta_pipeline
from numerblox.ensemble import NumeraiEnsemble, PredictionReducer
from numerblox.neutralizers import FeatureNeutralizer
model = XGBClassifier()
crossval = CrossValEstimator(estimator=model, cv=TimeSeriesSplit(n_splits=5), predict_func='predict_proba')
pred_rud = PredictionReducer(n_models=5, n_classes=5)
ens = NumeraiEnsemble(donate_weighted=True)
neut = FeatureNeutralizer(proportion=0.5)
full_pipe = make_meta_pipeline(crossval, pred_rud, ens, neut)
```
#### Training
```python
# ... Assume df is already defined as in the simple example ...
X, y = df.get_feature_target_pair(multi_target=False)
y_int = (y * 4).astype(int) # Convert targets to integer classes for classification
era_series = df.get_era_data
features = df.get_feature_data
full_pipe.fit(X, y_int, era_series=era_series)
```
#### Inference
```python
live_eras = live_df.get_era_data
live_features = live_df.get_feature_data
preds = full_pipe.predict(live_X, era_series=live_eras, features=live_features)
```
Scikit-learn estimators, pipelines, and metadata routing are used to make sure we pass the correct era and feature information to estimators in the pipeline that require those parameters. It is worth familiarizing yourself with these concepts before using the advanced modeling features of NumerBlox:
- [scikit-learn pipelines](https://scikit-learn.org/stable/modules/compose.html)
- [scikit-learn metadata routing](https://scikit-learn.org/stable/metadata_routing.html)
## 4. Contributing
Be sure to read the [How To Contribute section](https://crowdcent.github.io/numerblox/contributing/) section in the documentation for detailed instructions on contributing.
If you have questions or want to discuss new ideas for NumerBlox, please create a Github issue first.
## 5. Crediting sources
Some of the components in this library may be based on forum posts, notebooks or ideas made public by the Numerai community. We have done our best to ask all parties who posted a specific piece of code for their permission and credit their work in docstrings and documentation. If your code is public and used in this library without credits, please let us know, so we can add a link to your article/code. We want to always give credit where credit is due.
If you are contributing to NumerBlox and are using ideas posted earlier by someone else, make sure to credit them by posting a link to their article/code in docstrings and documentation.
Raw data
{
"_id": null,
"home_page": null,
"name": "numerblox",
"maintainer": null,
"docs_url": null,
"requires_python": "<4,>=3.10",
"maintainer_email": null,
"keywords": null,
"author": "CrowdCent",
"author_email": "support@crowdcent.com",
"download_url": "https://files.pythonhosted.org/packages/78/1e/35723eba44f38feea77fe8d2651e5749de27c5afd538eb112ef64f52a5ea/numerblox-1.4.0.tar.gz",
"platform": null,
"description": "![](https://img.shields.io/pypi/v/numerblox.png)\n![](https://img.shields.io/pypi/pyversions/numerblox.png)\n![](https://img.shields.io/github/contributors/crowdcent/numerblox.png)\n![](https://img.shields.io/codecov/c/gh/carlolepelaars/numerblox/master)\n![](https://img.shields.io/pypi/dm/numerblox)\n\n\n# NumerBlox\n\nNumerBlox offers components that help with developing strong Numerai models and inference pipelines. From downloading data to submitting predictions, NumerBlox has you covered.\n\nAll components can be used standalone and all processors are fully compatible to use within [scikit-learn](https://scikit-learn.org/) pipelines. \n\n**Documentation:**\n[crowdcent.github.io/numerblox](https://crowdcent.github.io/numerblox)\n\n## 1. Installation\n### Recommended\nSimply install numerblox from PyPi by running:\n\n```bash\npip install numerblox\n```\n\n### Development\nAlternatively you can clone this repository and install it in development mode using `poetry`:\n\n```bash\ngit clone https://github.com/crowdcent/numerblox.git\npip install poetry\ncd numerblox\npoetry install\n```\n\nInstallation without dev dependencies can be done by adding `--only main` to the `poetry install` line.\n\nTest your installation using one of the education notebooks in\n[examples](https://github.com/crowdcent/numerblox/examples). Good places to start are [quickstart.ipynb](https://github.com/crowdcent/numerblox/examples/quickstart.ipynb) and [numerframe_tutorial.ipynb](https://github.com/crowdcent/numerblox/examples/numerframe_tutorial.ipynb). Run it in your notebook environment to quickly test if your installation has succeeded. The documentation contains examples and explanations for each component of NumerBlox.\n\n## 2. Core functionality\n\nNumerBlox has the following features for both Numerai Classic and Signals:\n\n**[Data Download](https://crowdcent.github.io/numerblox/download/):** Automated retrieval of Numerai datasets.\n\n**[NumerFrame](https://crowdcent.github.io/numerblox/numerframe/):** A custom Pandas DataFrame for easier Numerai data manipulation.\n\n**[Preprocessors](https://crowdcent.github.io/numerblox/preprocessing/):** Customizable techniques for data preprocessing.\n\n**[Target Engineering](https://crowdcent.github.io/numerblox/targets/):** Tools for creating new target variables.\n\n**[Postprocessors](https://crowdcent.github.io/numerblox/neutralization/):** Ensembling, neutralization, and penalization.\n\n**[MetaPipeline](https://crowdcent.github.io/numerblox/meta/):** An era-aware pipeline extension of scikit-learn's Pipeline. Specifically designed to integrate with era-specific Postprocessors such as neutralization and ensembling. Can be optionally bypassed for custom implementations.\n\n**[MetaEstimators](https://crowdcent.github.io/numerblox/meta/):** Era-aware estimators that extend scikit-learn's functionality. Includes features like CrossValEstimator which allow for era-specific, multiple-folds fitting seamlessly integrated into the pipeline.\n\n**[Evaluation](https://crowdcent.github.io/numerblox/evaluation/):** Comprehensive metrics aligned with Numerai's evaluation criteria.\n\n**[Submitters](https://crowdcent.github.io/numerblox/submission/):** Facilitates secure and easy submission of predictions.\n\n**[Model Upload](https://crowdcent.github.io/numerblox/model_upload/):** Assists in the process of uploading trained models to Numerai for automated submissions.\n\nExample notebooks for each of these components can be found in the [examples](https://github.com/crowdcent/numerblox/examples). Also check out [the documentation](https://crowdcent.github.io/numerblox) for more information.\n\n\n## 3. Quick Start\n\nBelow are two examples of how NumerBlox can be used to train and do inference on Numerai data. For a full overview of all components check out the documentation. More advanced examples to leverage NumerBlox to the fullest can be found in the [End-To-End Example section](https://crowdcent.github.io/numerblox/end_to_end/).\n\n### 3.1. Simple example\n\nThe example below shows how NumerBlox can simplify the process of downloading, loading, training, evaluating, inferring and submitting data for Numerai Classic.\n\nNumerBlox is used here for easy downloading, data parsing, evaluation, inference and submission. You can experiment with this setup yourself in the example notebook [quickstart.ipynb](https://github.com/crowdcent/numerblox/examples/quickstart.ipynb).\n\n#### Downloading, loading, and training\n```python\nfrom numerblox.download import NumeraiClassicDownloader\nfrom numerblox.numerframe import create_numerframe\nfrom xgboost import XGBRegressor\n\ndownloader = NumeraiClassicDownloader(\"data\")\ndownloader.download_training_data(\"train_val\", version=\"5.0\")\ndf = create_numerframe(\"data/train_val/train.parquet\")\n\nX, y = df.get_feature_target_pair(multi_target=False)\nmodel = XGBRegressor()\nmodel.fit(X.values, y.values)\n```\n\n#### Evaluation\n```python\nfrom numerblox.prediction_loaders import ExamplePredictions\nfrom numerblox.evaluation import NumeraiClassicEvaluator\n\nval_df = create_numerframe(\"data/train_val/validation.parquet\")\nval_df['prediction'] = model.predict(val_df.get_feature_data)\nval_df['example_preds'] = ExamplePredictions(\"v5.0/validation_example_preds.parquet\").fit_transform(None)['prediction'].values\nevaluator = NumeraiClassicEvaluator()\nmetrics = evaluator.full_evaluation(val_df, \n example_col=\"example_preds\", \n pred_cols=[\"prediction\"], \n target_col=\"target\")\n```\n\n#### Live Inference\n```python\ndownloader.download_live_data(\"current_round\", version=\"5.0\")\nlive_df = create_numerframe(file_path=\"data/current_round/live.parquet\")\nlive_X, live_y = live_df.get_feature_target_pair(multi_target=False)\npreds = model.predict(live_X)\n```\n\n#### Submission\n```python\nfrom numerblox.misc import Key\nfrom numerblox.submission import NumeraiClassicSubmitter\n\nNUMERAI_PUBLIC_ID = \"YOUR_PUBLIC_ID\"\nNUMERAI_SECRET_KEY = \"YOUR_SECRET_KEY\"\nkey = Key(pub_id=NUMERAI_PUBLIC_ID, secret_key=NUMERAI_SECRET_KEY)\nsubmitter = NumeraiClassicSubmitter(directory_path=\"sub_current_round\", key=key)\npred_dataf = pd.DataFrame(preds, index=live_df.index, columns=[\"prediction\"])\nsubmitter.full_submission(dataf=pred_dataf,\n cols=\"prediction\",\n file_name=\"submission.csv\",\n model_name=\"MY_MODEL_NAME\")\n```\n\n#### Model Upload\n```python\nfrom numerblox.submission import NumeraiModelUpload\n\nuploader = NumeraiModelUpload(key=key, max_retries=3, sleep_time=15, fail_silently=True)\nuploader.create_and_upload_model(model=model, \n model_name=\"MY_MODEL_NAME\", \n file_path=\"models/my_model.pkl\")\n```\n\n### 3.2. Advanced NumerBlox modeling\n\nBuilding on the simple example, this advanced setup showcases how to leverage NumerBlox's powerful components to create a sophisticated pipeline that can replace the \"simple\" XGBoost model in the example above. This advanced example creates an extensible scikit-learn pipeline with metadata routing that:\n\n- Approaches Numerai Classic as a classification problem\n- Uses cross-validation with multiple folds\n- Reduces classification probabilities to single values\n- Creates a weighted ensemble favoring recent folds\n- Applies neutralization to the predictions\n\n#### Creating the pipeline\n```python\nfrom xgboost import XGBClassifier\nfrom sklearn.model_selection import TimeSeriesSplit\nfrom numerblox.meta import CrossValEstimator, make_meta_pipeline\nfrom numerblox.ensemble import NumeraiEnsemble, PredictionReducer\nfrom numerblox.neutralizers import FeatureNeutralizer\n\nmodel = XGBClassifier()\ncrossval = CrossValEstimator(estimator=model, cv=TimeSeriesSplit(n_splits=5), predict_func='predict_proba')\npred_rud = PredictionReducer(n_models=5, n_classes=5)\nens = NumeraiEnsemble(donate_weighted=True)\nneut = FeatureNeutralizer(proportion=0.5)\nfull_pipe = make_meta_pipeline(crossval, pred_rud, ens, neut)\n```\n\n#### Training\n```python\n# ... Assume df is already defined as in the simple example ...\nX, y = df.get_feature_target_pair(multi_target=False)\ny_int = (y * 4).astype(int) # Convert targets to integer classes for classification\nera_series = df.get_era_data\nfeatures = df.get_feature_data\nfull_pipe.fit(X, y_int, era_series=era_series)\n```\n\n#### Inference\n```python\nlive_eras = live_df.get_era_data\nlive_features = live_df.get_feature_data\npreds = full_pipe.predict(live_X, era_series=live_eras, features=live_features)\n```\n\nScikit-learn estimators, pipelines, and metadata routing are used to make sure we pass the correct era and feature information to estimators in the pipeline that require those parameters. It is worth familiarizing yourself with these concepts before using the advanced modeling features of NumerBlox: \n- [scikit-learn pipelines](https://scikit-learn.org/stable/modules/compose.html)\n- [scikit-learn metadata routing](https://scikit-learn.org/stable/metadata_routing.html)\n\n## 4. Contributing\n\nBe sure to read the [How To Contribute section](https://crowdcent.github.io/numerblox/contributing/) section in the documentation for detailed instructions on contributing.\n\nIf you have questions or want to discuss new ideas for NumerBlox, please create a Github issue first.\n\n## 5. Crediting sources\n\nSome of the components in this library may be based on forum posts, notebooks or ideas made public by the Numerai community. We have done our best to ask all parties who posted a specific piece of code for their permission and credit their work in docstrings and documentation. If your code is public and used in this library without credits, please let us know, so we can add a link to your article/code. We want to always give credit where credit is due.\n\nIf you are contributing to NumerBlox and are using ideas posted earlier by someone else, make sure to credit them by posting a link to their article/code in docstrings and documentation.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Solid Numerai Pipelines",
"version": "1.4.0",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "cf4089fcc696316e26153024f628e211665bea9d386ea521f638f0e123fce525",
"md5": "da4cd3b16f778a6b40c2b13d4bcc67d8",
"sha256": "d2a1fa706ede6b24f04c2233547bf74a3155f50ff4861a68332ca310cbcdffb2"
},
"downloads": -1,
"filename": "numerblox-1.4.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "da4cd3b16f778a6b40c2b13d4bcc67d8",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4,>=3.10",
"size": 104935,
"upload_time": "2024-09-27T13:59:40",
"upload_time_iso_8601": "2024-09-27T13:59:40.720998Z",
"url": "https://files.pythonhosted.org/packages/cf/40/89fcc696316e26153024f628e211665bea9d386ea521f638f0e123fce525/numerblox-1.4.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "781e35723eba44f38feea77fe8d2651e5749de27c5afd538eb112ef64f52a5ea",
"md5": "ef27918ea9731b27e341c4ca20110b79",
"sha256": "2ba955913559390be7cdcfbd9b0d1d7c1a7be5bb0b359c3503db75561f54262a"
},
"downloads": -1,
"filename": "numerblox-1.4.0.tar.gz",
"has_sig": false,
"md5_digest": "ef27918ea9731b27e341c4ca20110b79",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4,>=3.10",
"size": 100354,
"upload_time": "2024-09-27T13:59:42",
"upload_time_iso_8601": "2024-09-27T13:59:42.151269Z",
"url": "https://files.pythonhosted.org/packages/78/1e/35723eba44f38feea77fe8d2651e5749de27c5afd538eb112ef64f52a5ea/numerblox-1.4.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-27 13:59:42",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "numerblox"
}