stockpy-learn


Namestockpy-learn JSON
Version 0.3.2 PyPI version JSON
download
home_pagehttps://github.com/SilvioBaratto/stockpy
SummaryDeep Learning Regression and Classification Library built on top of PyTorch and Pyro
upload_time2023-11-20 00:26:00
maintainer
docs_urlNone
authorSilvio Baratto
requires_python>=3.8
licenseMIT License
keywords
VCS
bugtrack_url
requirements torch pyro-ppl numpy pandas tqdm jupyter matplotlib pandas pillow scikit-learn safetensors sphinx sphinx_rtd_theme
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <div align="center">
  <a href="https://github.com/SilvioBaratto/stockpy"> <img width=600 src="docs/source/_static/img/stockpi_v3.svg"></a>
</div>

![Python package](https://github.com/SilvioBaratto/stockpy/workflows/Python%20package/badge.svg?branch=master)
[![GitHub license](https://img.shields.io/github/license/Naereen/StrapDown.js.svg)](https://github.com/Naereen/StrapDown.js/blob/master/LICENSE)
<img src='https://img.shields.io/badge/Code%20style-Black-%23000000'/>
[![Documentation Status](https://readthedocs.org/projects/stockpy/badge/?version=latest)](https://stockpy.readthedocs.io/?badge=latest)
[![PyPI version](https://badge.fury.io/py/stockpy-learn.svg)](https://badge.fury.io/py/stockpy-learn)

## Table of Contents
* [Description](#description)
* [Documentation](https://stockpy.readthedocs.io/)
* [Installation](#installation)
* [Usage](#usage)
* [Examples](#examples)
* [Data Downloader](#data-downloader)
* [License](#license)
* [Contributing](#contributing)
* [TODOs](#todos)

## Description
**stockpy** is a versatile Python Machine Learning library initially designed for stock market data analysis and predictions. It has now evolved to handle a wider range of datasets, supporting tasks such as regression and classification. It currently supports the following algorithms, each with regression and classification implementations:

- Bayesian Neural Networks (BNN)
- Long Short Term Memory (LSTM)
- Bidirectional Long Short Term Memory (BiLSTM)
- Gated Recurrent Unit (GRU)
- Bidirectional Gated Recurrent Unit (BiGRU)
- Multilayer Perceptron (MLP)
- Deep Markov Model (DMM) 
- Gaussian Hidden Markov Models (GHMM) 

## Usage
To use **stockpy**, start by importing the relevant models from the `stockpy.neural_network` and `stockpy.probabilistic` modules. The library can be used with various types of input data, such as CSV files, pandas dataframes, numpy arrays and torch arrays.

Here's an example to demonstrate the usage of stockpy for regression. In this example, we read a CSV file containing stock market data for Apple (AAPL), split the data into training and testing sets, fit an LSTM model to the training data, and use the model to make predictions on the test data:

```Python
from stockpy.neural_network import CNNRegressor
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler

# Load the dataset
df = pd.read_csv('stock/AAPL.csv', parse_dates=True, index_col='Date').dropna(how="any")

# Define features and target
X = df[['Open', 'High', 'Low', 'Volume']]
y = df['Close']

# Split the dataset
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, shuffle=False)

# Scale the data
scaler = StandardScaler()
X_train = scaler.fit_transform(X_train)
X_test = scaler.transform(X_test)

# Convert the data to torch tensors
X_train = torch.tensor(X_train, dtype=torch.float)
X_test = torch.tensor(X_test, dtype=torch.float)
y_train = torch.tensor(y_train.values, dtype=torch.float)

# Fit the model
predictor = CNNRegressor(hidden_size=32)

predictor.fit(X_train, 
              y_train, 
              batch_size=32, 
              lr=0.01, 
              optimizer=torch.optim.Adam, 
              epochs=50)
```

Here's an example to demonstrate the usage of stockpy for classification. In this example, we read a pickle file containing labeled data, split the data into training and testing sets, fit an LSTM model to the training data, and use the model to make classification on the test data:

```Python
from stockpy.neural_network import LSTMClassifier
from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split

X, y = make_classification(n_samples=10000, 
                           n_features=20, 
                           n_informative=15, 
                           n_redundant=5, 
                           n_classes=5, 
                           random_state=0)


X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.05, shuffle=False)

# Scale the data and convert to torch tensors
from sklearn.preprocessing import MinMaxScaler
scaler = MinMaxScaler()
X_train = scaler.fit_transform(X_train)
X_test = scaler.transform(X_test)

X_train = X_train.astype(np.float32)
X_test = X_test.astype(np.float32)
y_train = y_train.astype(np.int64)

predictor = LSTMClassifier()

predictor.fit(X_train, 
              y_train, 
              batch_size=32, 
              lr=0.01, 
              optimizer=torch.optim.Adam, 
              epochs=50)
```

The above code can be applied to all models in the library, just make sure to import from the correct location, either `stockpy.neural_network` or `stockpy.probabilistic`.


## Dependencies and installation
**stockpy** requires the modules `numpy, torch, pyro-ppl`. The code is tested for _Python 3_. It can be installed using `pip` or directly from the source cod.

### Installing via pip

To install the package:
```bash
> pip install stockpy-learn
```
To uninstall the package:
```bash
> pip uninstall stockpy-learn
```
### Installing from source

You can clone this repository on your local machines using:

```bash
> git clone https://github.com/SilvioBaratto/stockpy
```

To install the package:

```bash
> cd stockpy
> pip install .
```

## TODOs
Below is a list of planned enhancements and features that are in the pipeline for **stockpy**. Contributions and suggestions are always welcome!

- [ ] Implement a dedicated `test` directory with comprehensive unit tests to ensure reliability and facilitate continuous integration.
- [ ] Expand the documentation to include more detailed tutorials and code explanations, aiding users in effectively utilizing **stockpy**.
- [ ] Enrich the algorithmic suite by adding additional models for regression and classification, catering to a broader range of data science needs.
- [ ] Integrate generative models into the library to provide advanced capabilities for data synthesis and pattern discovery.
- [ ] Develop and incorporate sophisticated prediction models that can handle complex forecasting tasks with higher accuracy.

*Note: A checked box (✅) indicates that the task has been completed.*

## Authors and acknowledgements
**stockpy** is currently developed and mantained by **Silvio Baratto**. You can contact me at:
- silvio.baratto22 at gmail.com

## Reporting a bug
The best way to report a bug is using the
[Issues](https://github.com/fAndreuzzi/BisPy/issues) section. Please, be clear,
and give detailed examples on how to reproduce the bug (the best option would
be the graph which triggered the error you are reporting).

## How to contribute

We are more than happy to receive contributions on tests, documentation and
new features. Our [Issues](https://github.com/fAndreuzzi/BisPy/issues)
section is always full of things to do.

Here are the guidelines to submit a patch:

1. Start by opening a new [issue](https://github.com/fAndreuzzi/BisPy/issues)
   describing the bug you want to fix, or the feature you want to introduce.
   This lets us keep track of what is being done at the moment, and possibly
   avoid writing different solutions for the same problem.

2. Fork the project, and setup a **new** branch to work in (_fix-issue-22_, for
   instance). If you do not separate your work in different branches you may
   have a bad time when trying to push a pull request to fix a particular
   issue.

3. Run [black](https://github.com/psf/black) before pushing
   your code for review.

4. Provide menaningful **commit messages** to help us keeping a good _git_
   history.

5. Finally you can submbit your _pull request_!

## License

See the [LICENSE](LICENSE) file for license rights and limitations (MIT).

## stockpy Legal Disclaimer

Please read this legal disclaimer carefully before using stockpy-learn library. By using stockpy-learn library, you agree to be bound by this disclaimer.

stockpy-learn library is provided for informational and educational purposes only and is not intended as a recommendation, offer or solicitation for the purchase or sale of any financial instrument or securities. The information provided in the stockpy-learn library is not to be construed as financial, investment, legal, or tax advice, and the use of any information provided in stockpy-learn library is at your own risk.

stockpy-learn library is not a substitute for professional financial or investment advice and should not be relied upon for making investment decisions. You should consult a qualified financial or investment professional before making any investment decision.

We make no representation or warranty, express or implied, as to the accuracy, completeness, or suitability of any information provided in stockpy, and we shall not be liable for any errors or omissions in such information.

We shall not be liable for any direct, indirect, incidental, special, consequential, or exemplary damages arising from the use of stockpy library or any information provided therein.

stockpy-learn library is provided "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability, fitness for a particular purpose, or non-infringement.

We reserve the right to modify or discontinue stockpy-learn library at any time without notice. We shall not be liable for any modification, suspension, or discontinuance of stockpy-learn library.

By using stockpy-learn library, you agree to indemnify and hold us harmless from any claim or demand, including reasonable attorneys' fees, made by any third party due to or arising out of your use of stockpy-learn library, your violation of this disclaimer, or your violation of any law or regulation.

This legal disclaimer is governed by and construed in accordance with the laws of Italy, and any disputes relating to this disclaimer shall be subject to the exclusive jurisdiction of the courts of Italy.

If you have any questions about this legal disclaimer, please contact us at silvio.baratto22@gmail.com.

By using stockpy-learn library, you acknowledge that you have read and understood this legal disclaimer and agree to be bound by its terms and conditions.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/SilvioBaratto/stockpy",
    "name": "stockpy-learn",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "",
    "author": "Silvio Baratto",
    "author_email": "silvio.baratto22@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/af/c7/b6c0240e74d01191f4adb0cb0e3249a0b1851996a1a027dba1457ff9240d/stockpy-learn-0.3.2.tar.gz",
    "platform": null,
    "description": "<div align=\"center\">\n  <a href=\"https://github.com/SilvioBaratto/stockpy\"> <img width=600 src=\"docs/source/_static/img/stockpi_v3.svg\"></a>\n</div>\n\n![Python package](https://github.com/SilvioBaratto/stockpy/workflows/Python%20package/badge.svg?branch=master)\n[![GitHub license](https://img.shields.io/github/license/Naereen/StrapDown.js.svg)](https://github.com/Naereen/StrapDown.js/blob/master/LICENSE)\n<img src='https://img.shields.io/badge/Code%20style-Black-%23000000'/>\n[![Documentation Status](https://readthedocs.org/projects/stockpy/badge/?version=latest)](https://stockpy.readthedocs.io/?badge=latest)\n[![PyPI version](https://badge.fury.io/py/stockpy-learn.svg)](https://badge.fury.io/py/stockpy-learn)\n\n## Table of Contents\n* [Description](#description)\n* [Documentation](https://stockpy.readthedocs.io/)\n* [Installation](#installation)\n* [Usage](#usage)\n* [Examples](#examples)\n* [Data Downloader](#data-downloader)\n* [License](#license)\n* [Contributing](#contributing)\n* [TODOs](#todos)\n\n## Description\n**stockpy** is a versatile Python Machine Learning library initially designed for stock market data analysis and predictions. It has now evolved to handle a wider range of datasets, supporting tasks such as regression and classification. It currently supports the following algorithms, each with regression and classification implementations:\n\n- Bayesian Neural Networks (BNN)\n- Long Short Term Memory (LSTM)\n- Bidirectional Long Short Term Memory (BiLSTM)\n- Gated Recurrent Unit (GRU)\n- Bidirectional Gated Recurrent Unit (BiGRU)\n- Multilayer Perceptron (MLP)\n- Deep Markov Model (DMM) \n- Gaussian Hidden Markov Models (GHMM) \n\n## Usage\nTo use **stockpy**, start by importing the relevant models from the `stockpy.neural_network` and `stockpy.probabilistic` modules. The library can be used with various types of input data, such as CSV files, pandas dataframes, numpy arrays and torch arrays.\n\nHere's an example to demonstrate the usage of stockpy for regression. In this example, we read a CSV file containing stock market data for Apple (AAPL), split the data into training and testing sets, fit an LSTM model to the training data, and use the model to make predictions on the test data:\n\n```Python\nfrom stockpy.neural_network import CNNRegressor\nimport pandas as pd\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.preprocessing import StandardScaler\n\n# Load the dataset\ndf = pd.read_csv('stock/AAPL.csv', parse_dates=True, index_col='Date').dropna(how=\"any\")\n\n# Define features and target\nX = df[['Open', 'High', 'Low', 'Volume']]\ny = df['Close']\n\n# Split the dataset\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, shuffle=False)\n\n# Scale the data\nscaler = StandardScaler()\nX_train = scaler.fit_transform(X_train)\nX_test = scaler.transform(X_test)\n\n# Convert the data to torch tensors\nX_train = torch.tensor(X_train, dtype=torch.float)\nX_test = torch.tensor(X_test, dtype=torch.float)\ny_train = torch.tensor(y_train.values, dtype=torch.float)\n\n# Fit the model\npredictor = CNNRegressor(hidden_size=32)\n\npredictor.fit(X_train, \n              y_train, \n              batch_size=32, \n              lr=0.01, \n              optimizer=torch.optim.Adam, \n              epochs=50)\n```\n\nHere's an example to demonstrate the usage of stockpy for classification. In this example, we read a pickle file containing labeled data, split the data into training and testing sets, fit an LSTM model to the training data, and use the model to make classification on the test data:\n\n```Python\nfrom stockpy.neural_network import LSTMClassifier\nfrom sklearn.datasets import make_classification\nfrom sklearn.model_selection import train_test_split\n\nX, y = make_classification(n_samples=10000, \n                           n_features=20, \n                           n_informative=15, \n                           n_redundant=5, \n                           n_classes=5, \n                           random_state=0)\n\n\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.05, shuffle=False)\n\n# Scale the data and convert to torch tensors\nfrom sklearn.preprocessing import MinMaxScaler\nscaler = MinMaxScaler()\nX_train = scaler.fit_transform(X_train)\nX_test = scaler.transform(X_test)\n\nX_train = X_train.astype(np.float32)\nX_test = X_test.astype(np.float32)\ny_train = y_train.astype(np.int64)\n\npredictor = LSTMClassifier()\n\npredictor.fit(X_train, \n              y_train, \n              batch_size=32, \n              lr=0.01, \n              optimizer=torch.optim.Adam, \n              epochs=50)\n```\n\nThe above code can be applied to all models in the library, just make sure to import from the correct location, either `stockpy.neural_network` or `stockpy.probabilistic`.\n\n\n## Dependencies and installation\n**stockpy** requires the modules `numpy, torch, pyro-ppl`. The code is tested for _Python 3_. It can be installed using `pip` or directly from the source cod.\n\n### Installing via pip\n\nTo install the package:\n```bash\n> pip install stockpy-learn\n```\nTo uninstall the package:\n```bash\n> pip uninstall stockpy-learn\n```\n### Installing from source\n\nYou can clone this repository on your local machines using:\n\n```bash\n> git clone https://github.com/SilvioBaratto/stockpy\n```\n\nTo install the package:\n\n```bash\n> cd stockpy\n> pip install .\n```\n\n## TODOs\nBelow is a list of planned enhancements and features that are in the pipeline for **stockpy**. Contributions and suggestions are always welcome!\n\n- [ ] Implement a dedicated `test` directory with comprehensive unit tests to ensure reliability and facilitate continuous integration.\n- [ ] Expand the documentation to include more detailed tutorials and code explanations, aiding users in effectively utilizing **stockpy**.\n- [ ] Enrich the algorithmic suite by adding additional models for regression and classification, catering to a broader range of data science needs.\n- [ ] Integrate generative models into the library to provide advanced capabilities for data synthesis and pattern discovery.\n- [ ] Develop and incorporate sophisticated prediction models that can handle complex forecasting tasks with higher accuracy.\n\n*Note: A checked box (\u2705) indicates that the task has been completed.*\n\n## Authors and acknowledgements\n**stockpy** is currently developed and mantained by **Silvio Baratto**. You can contact me at:\n- silvio.baratto22 at gmail.com\n\n## Reporting a bug\nThe best way to report a bug is using the\n[Issues](https://github.com/fAndreuzzi/BisPy/issues) section. Please, be clear,\nand give detailed examples on how to reproduce the bug (the best option would\nbe the graph which triggered the error you are reporting).\n\n## How to contribute\n\nWe are more than happy to receive contributions on tests, documentation and\nnew features. Our [Issues](https://github.com/fAndreuzzi/BisPy/issues)\nsection is always full of things to do.\n\nHere are the guidelines to submit a patch:\n\n1. Start by opening a new [issue](https://github.com/fAndreuzzi/BisPy/issues)\n   describing the bug you want to fix, or the feature you want to introduce.\n   This lets us keep track of what is being done at the moment, and possibly\n   avoid writing different solutions for the same problem.\n\n2. Fork the project, and setup a **new** branch to work in (_fix-issue-22_, for\n   instance). If you do not separate your work in different branches you may\n   have a bad time when trying to push a pull request to fix a particular\n   issue.\n\n3. Run [black](https://github.com/psf/black) before pushing\n   your code for review.\n\n4. Provide menaningful **commit messages** to help us keeping a good _git_\n   history.\n\n5. Finally you can submbit your _pull request_!\n\n## License\n\nSee the [LICENSE](LICENSE) file for license rights and limitations (MIT).\n\n## stockpy Legal Disclaimer\n\nPlease read this legal disclaimer carefully before using stockpy-learn library. By using stockpy-learn library, you agree to be bound by this disclaimer.\n\nstockpy-learn library is provided for informational and educational purposes only and is not intended as a recommendation, offer or solicitation for the purchase or sale of any financial instrument or securities. The information provided in the stockpy-learn library is not to be construed as financial, investment, legal, or tax advice, and the use of any information provided in stockpy-learn library is at your own risk.\n\nstockpy-learn library is not a substitute for professional financial or investment advice and should not be relied upon for making investment decisions. You should consult a qualified financial or investment professional before making any investment decision.\n\nWe make no representation or warranty, express or implied, as to the accuracy, completeness, or suitability of any information provided in stockpy, and we shall not be liable for any errors or omissions in such information.\n\nWe shall not be liable for any direct, indirect, incidental, special, consequential, or exemplary damages arising from the use of stockpy library or any information provided therein.\n\nstockpy-learn library is provided \"as is\" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability, fitness for a particular purpose, or non-infringement.\n\nWe reserve the right to modify or discontinue stockpy-learn library at any time without notice. We shall not be liable for any modification, suspension, or discontinuance of stockpy-learn library.\n\nBy using stockpy-learn library, you agree to indemnify and hold us harmless from any claim or demand, including reasonable attorneys' fees, made by any third party due to or arising out of your use of stockpy-learn library, your violation of this disclaimer, or your violation of any law or regulation.\n\nThis legal disclaimer is governed by and construed in accordance with the laws of Italy, and any disputes relating to this disclaimer shall be subject to the exclusive jurisdiction of the courts of Italy.\n\nIf you have any questions about this legal disclaimer, please contact us at silvio.baratto22@gmail.com.\n\nBy using stockpy-learn library, you acknowledge that you have read and understood this legal disclaimer and agree to be bound by its terms and conditions.\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "Deep Learning Regression and Classification Library built on top of PyTorch and Pyro",
    "version": "0.3.2",
    "project_urls": {
        "Homepage": "https://github.com/SilvioBaratto/stockpy"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "937e41d04ce95afe17dd0679a2c0246837c930bc1e87126b4f23fe6568dc0255",
                "md5": "50edaf1a3700bfd78ad0769805bfd6b5",
                "sha256": "1ef169921b88c69952110ee0e39b321b4a6b259933b40581bb2c9bea05f98598"
            },
            "downloads": -1,
            "filename": "stockpy_learn-0.3.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "50edaf1a3700bfd78ad0769805bfd6b5",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 173325,
            "upload_time": "2023-11-20T00:25:58",
            "upload_time_iso_8601": "2023-11-20T00:25:58.336748Z",
            "url": "https://files.pythonhosted.org/packages/93/7e/41d04ce95afe17dd0679a2c0246837c930bc1e87126b4f23fe6568dc0255/stockpy_learn-0.3.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "afc7b6c0240e74d01191f4adb0cb0e3249a0b1851996a1a027dba1457ff9240d",
                "md5": "9336afe964b07ae0d70890ecc309279d",
                "sha256": "dc04a7047c987a883c81cdf7cb62e036a2421e5df3dd961cb1c015df01ecca77"
            },
            "downloads": -1,
            "filename": "stockpy-learn-0.3.2.tar.gz",
            "has_sig": false,
            "md5_digest": "9336afe964b07ae0d70890ecc309279d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 155049,
            "upload_time": "2023-11-20T00:26:00",
            "upload_time_iso_8601": "2023-11-20T00:26:00.363798Z",
            "url": "https://files.pythonhosted.org/packages/af/c7/b6c0240e74d01191f4adb0cb0e3249a0b1851996a1a027dba1457ff9240d/stockpy-learn-0.3.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-20 00:26:00",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "SilvioBaratto",
    "github_project": "stockpy",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "torch",
            "specs": [
                [
                    ">=",
                    "1.9.1"
                ]
            ]
        },
        {
            "name": "pyro-ppl",
            "specs": [
                [
                    ">=",
                    "1.7.0"
                ]
            ]
        },
        {
            "name": "numpy",
            "specs": [
                [
                    ">=",
                    "1.21.2"
                ]
            ]
        },
        {
            "name": "pandas",
            "specs": [
                [
                    ">=",
                    "1.3.3"
                ]
            ]
        },
        {
            "name": "tqdm",
            "specs": [
                [
                    "==",
                    "4.62.3"
                ]
            ]
        },
        {
            "name": "jupyter",
            "specs": []
        },
        {
            "name": "matplotlib",
            "specs": [
                [
                    ">=",
                    "2.0.2"
                ]
            ]
        },
        {
            "name": "pandas",
            "specs": []
        },
        {
            "name": "pillow",
            "specs": []
        },
        {
            "name": "scikit-learn",
            "specs": [
                [
                    ">=",
                    "0.24.2"
                ]
            ]
        },
        {
            "name": "safetensors",
            "specs": [
                [
                    ">=",
                    "0.3.1"
                ]
            ]
        },
        {
            "name": "sphinx",
            "specs": []
        },
        {
            "name": "sphinx_rtd_theme",
            "specs": []
        }
    ],
    "lcname": "stockpy-learn"
}
        
Elapsed time: 0.14738s