makeprediction


Namemakeprediction JSON
Version 4.1.1 PyPI version JSON
download
home_pagehttps://github.com/HananyTolba/MakePrediction.git
SummaryAutomatic and fast Gaussian process for time serie prediction.
upload_time2023-05-27 11:43:16
maintainer
docs_urlNone
authorHanany Tolba
requires_python>=3.6
licenseGPLv3
keywords gaussian process regression time series prediction machine learning
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
              

<!-- ![alt text](assets/logo.png)

-->

<img src="assets/logo.png" alt="makeprediction logo" width="500px"/>

<!-- <img src="assets/logo_1.png" alt="makeprediction logo" width="300px"/>

-->

  
  

MakePrediction is a package for building an automatic Gaussian process regression (GPR) models for time series prediction in Python. It was originally created by [Hanany Tolba].

* MakePrediction is an open source project. If you have relevant skills and are interested in contributing then please do contact us (hananytolba@yahoo.com).*

  

Gaussian process regression (GPR):

==========================================

The advantages of this Gaussian processes package:

* Very fast training.

* Very fast prediction.

* The prediction can be interpolated as desired.

* The training of the model is automatic: 
            -   *no kernel function needs to be specified*
            -   *an optimal choice of kernel is automatically elaborated.*

* Possibility to choose a kernel function manually.

* The prediction is probabilistic (Gaussian) so that confidence intervals can be calculated and used to decide whether to make a strategic decision.

* The package provides an API for deployment.

  

## Where do you find time series?

* Energy

* Finance

* Medical, Biotech, and Healthcare

* IoT Monitoring

* Supply Chain

* Agriculture

* Retail

  
  

## What does makeprediction do?

* Modelling and analysis time series.

* Automatic time-series prediction (forecasting).

* Real-Time time series prediction.

* Deploy on production the fitted (or saved) makeprediction model.

  

### Applications:

* Energy consumption prediction.

* Energy demand prediction.

* Stock price prediction.

* Stock market prediction.

* ...
## Install MakePrediction package 

### Latest release from PyPI


* pip install makeprediction

  

### Latest source from GitHub

  

*Be aware that the `master` branch may change regularly, and new commits may break your code.*

  

[MakePrediction GitHub repository](https://github.com/HananyTolba/MakePrediction.git), run:

  

* pip install .
*or*
* python setup.py install 



## Get Started with MakePrediction

### Example


  

Here is a simple example:

#### Data 
 

```python
import pandas as pd
import numpy as np
import plotly.graph_objects as go

from makeprediction.gpts import GaussianProcessTimeSerie
from makeprediction.kernels import RBF, White, Linear, Periodic, Matern
from makeprediction.visualization import Visualizer

  

#### generate a random noisy time series
###############################

date = pd.date_range(start  =  '2022/06',periods  =  1000, freq  =  '20T')

# As sum of some Gaussian kernels

# As sum of some Gaussian kernels

kernel =   RBF()  + Periodic()  +  White(variance  =  .01)

# add mean and variance
data = 100 +  10*kernel.simulate(date, seed  = np.random.seed(115))
## generate data without fixe np.random.seed
# data = 100 +  10*kernel.simulate(date)

# create a dataframe with data
df = pd.DataFrame(data  = data, index  = date, columns=['value'])
print(df.head())

# split time serie into train and test
TRAIN_SIZE =  int(.8*len(df))
df_train, df_test = df[:TRAIN_SIZE], df[TRAIN_SIZE:]
# Create an instance of the class GaussianProcessTimeSerie with train data:
#########################################
model =  GaussianProcessTimeSerie(df_train.index, df_train.value)
# Show train data with test data
Visualizer.iplot(model, df_test.index, df_test.value)

```

<img src="assets_images/fig0.png" width="900px"/>



#### Train 

```python

# fit the model

model.fit()

```

  
#### Test (long term prediction)

We will first show a simple prediction without updating with new observations (in other words without ever using df_test.value). We can say that the prediction horizon is infinite.

```python



#predict with model and plot result

model.predict(df_test.index)

Visualizer.iplot(model, df_test.index, df_test.value)

  

```



  <img src="assets_images/fig1.png" width="900px"/>

```python
# Model components
#how the components of the model (decomposition)
fig3 = Visualizer.iplot_components(model,return_fig=True)
fig3.write_image("fig3.png",width = 900,height =700, scale = 5)
```
 <img src="assets_images/fig3.png" width="900px"/>

```python
#plot only test result

fig2 = Visualizer.iplot(model, df_test.index, df_test.value, return_fig=True, test_only=True)
fig2.write_image("fig2.png",width = 1400,height =700)
fig2.show()

  ```
<img src="assets_images/fig2.png" width="900px"/>


#### Online prediction with horizon = 1

Contrary to the previous case, the horizon is 1. In other words, we predict a first value at a given time, then we will update the model by communicating this observation via the update method and so on (see codes). 

```python

  

# Online prediction with updating

ypred = np.empty(shape  = (0,))

ypred_std = np.empty(shape  = (0,))

for x,y in df_test.itertuples():

	# predict for x value

	yp,yp_std = model.predict(x,return_value  =  True)

	ypred = np.append(ypred,yp)

	ypred_std = np.append(ypred_std,yp_std)

	# update the model for (x,y)

	data = {'x_update': x, 'y_update': y}

	model.update(**data)



# Show new prediction

# Show new update prediction

fig2.add_trace(
    go.Scatter(
        x=df_test.index,
        y=ypred,
        mode="lines",
        name='Prediction(horizon = 1)',
        showlegend=True)
)

fig2.write_image("fig2_update_one_head.png",width = 900,height =700, scale = 5)

  


```

   <img src="assets_images/fig2_update_one_head.png" width="900px"/>


  

#### After updating, how to check?
  
Note that each time the model is updated with a new data 	data = {'x_update': x (time), 'y_update': y (value)}
or even data vector. The model learns this data and adjusts itself to become more and more efficient.

```python

#prediction of data already seen(updated)
yupdate, _ = model.predict(df_test.index,return_value = True)

fig2.add_trace(
    go.Scatter(
        x=df_test.index,
        y=ypred,
        mode="lines",
        name='Prediction(horizon = 1)',
        showlegend=True)
)


fig2.add_trace(
    go.Scatter(
        x=df_test.index,
        y=yupdate,
        mode="lines",
        name='Update model',
        showlegend=True)
)
fig2.show()
fig2.write_image("fig2_update.png",width = 900,height =700, scale = 5)



  

```
   <img src="assets_images/fig2_update.png" width="900px"/>

  

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/HananyTolba/MakePrediction.git",
    "name": "makeprediction",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "Gaussian Process Regression,Time series prediction,Machine Learning",
    "author": "Hanany Tolba",
    "author_email": "hananytolba@yahoo.com",
    "download_url": "https://files.pythonhosted.org/packages/6a/f7/769a0e93b5bedf8e3e791d61ca4c108bf080025e7e02017d53f5fec99832/makeprediction-4.1.1.tar.gz",
    "platform": null,
    "description": "  \n\n<!-- ![alt text](assets/logo.png)\n\n-->\n\n<img src=\"assets/logo.png\" alt=\"makeprediction logo\" width=\"500px\"/>\n\n<!-- <img src=\"assets/logo_1.png\" alt=\"makeprediction logo\" width=\"300px\"/>\n\n-->\n\n  \n  \n\nMakePrediction is a package for building an automatic Gaussian process regression (GPR) models for time series prediction in Python. It was originally created by [Hanany Tolba].\n\n* MakePrediction is an open source project. If you have relevant skills and are interested in contributing then please do contact us (hananytolba@yahoo.com).*\n\n  \n\nGaussian process regression (GPR):\n\n==========================================\n\nThe advantages of this Gaussian processes package:\n\n* Very fast training.\n\n* Very fast prediction.\n\n* The prediction can be interpolated as desired.\n\n* The training of the model is automatic: \n            -   *no kernel function needs to be specified*\n            -   *an optimal choice of kernel is automatically elaborated.*\n\n* Possibility to choose a kernel function manually.\n\n* The prediction is probabilistic (Gaussian) so that confidence intervals can be calculated and used to decide whether to make a strategic decision.\n\n* The package provides an API for deployment.\n\n  \n\n## Where do you find time series?\n\n* Energy\n\n* Finance\n\n* Medical, Biotech, and Healthcare\n\n* IoT Monitoring\n\n* Supply Chain\n\n* Agriculture\n\n* Retail\n\n  \n  \n\n## What does makeprediction do?\n\n* Modelling and analysis time series.\n\n* Automatic time-series prediction (forecasting).\n\n* Real-Time time series prediction.\n\n* Deploy on production the fitted (or saved) makeprediction model.\n\n  \n\n### Applications:\n\n* Energy consumption prediction.\n\n* Energy demand prediction.\n\n* Stock price prediction.\n\n* Stock market prediction.\n\n* ...\n## Install MakePrediction package \n\n### Latest release from PyPI\n\n\n* pip install makeprediction\n\n  \n\n### Latest source from GitHub\n\n  \n\n*Be aware that the `master` branch may change regularly, and new commits may break your code.*\n\n  \n\n[MakePrediction GitHub repository](https://github.com/HananyTolba/MakePrediction.git), run:\n\n  \n\n* pip install .\n*or*\n* python setup.py install \n\n\n\n## Get Started with MakePrediction\n\n### Example\n\n\n  \n\nHere is a simple example:\n\n#### Data \n \n\n```python\nimport pandas as pd\nimport numpy as np\nimport plotly.graph_objects as go\n\nfrom makeprediction.gpts import GaussianProcessTimeSerie\nfrom makeprediction.kernels import RBF, White, Linear, Periodic, Matern\nfrom makeprediction.visualization import Visualizer\n\n  \n\n#### generate a random noisy time series\n###############################\n\ndate = pd.date_range(start  =  '2022/06',periods  =  1000, freq  =  '20T')\n\n# As sum of some Gaussian kernels\n\n# As sum of some Gaussian kernels\n\nkernel =   RBF()  + Periodic()  +  White(variance  =  .01)\n\n# add mean and variance\ndata = 100 +  10*kernel.simulate(date, seed  = np.random.seed(115))\n## generate data without fixe np.random.seed\n# data = 100 +  10*kernel.simulate(date)\n\n# create a dataframe with data\ndf = pd.DataFrame(data  = data, index  = date, columns=['value'])\nprint(df.head())\n\n# split time serie into train and test\nTRAIN_SIZE =  int(.8*len(df))\ndf_train, df_test = df[:TRAIN_SIZE], df[TRAIN_SIZE:]\n# Create an instance of the class GaussianProcessTimeSerie with train data:\n#########################################\nmodel =  GaussianProcessTimeSerie(df_train.index, df_train.value)\n# Show train data with test data\nVisualizer.iplot(model, df_test.index, df_test.value)\n\n```\n\n<img src=\"assets_images/fig0.png\" width=\"900px\"/>\n\n\n\n#### Train \n\n```python\n\n# fit the model\n\nmodel.fit()\n\n```\n\n  \n#### Test (long term prediction)\n\nWe will first show a simple prediction without updating with new observations (in other words without ever using df_test.value). We can say that the prediction horizon is infinite.\n\n```python\n\n\n\n#predict with model and plot result\n\nmodel.predict(df_test.index)\n\nVisualizer.iplot(model, df_test.index, df_test.value)\n\n  \n\n```\n\n\n\n  <img src=\"assets_images/fig1.png\" width=\"900px\"/>\n\n```python\n# Model components\n#how the components of the model (decomposition)\nfig3 = Visualizer.iplot_components(model,return_fig=True)\nfig3.write_image(\"fig3.png\",width = 900,height =700, scale = 5)\n```\n <img src=\"assets_images/fig3.png\" width=\"900px\"/>\n\n```python\n#plot only test result\n\nfig2 = Visualizer.iplot(model, df_test.index, df_test.value, return_fig=True, test_only=True)\nfig2.write_image(\"fig2.png\",width = 1400,height =700)\nfig2.show()\n\n  ```\n<img src=\"assets_images/fig2.png\" width=\"900px\"/>\n\n\n#### Online prediction with horizon = 1\n\nContrary to the previous case, the horizon is 1. In other words, we predict a first value at a given time, then we will update the model by communicating this observation via the update method and so on (see codes). \n\n```python\n\n  \n\n# Online prediction with updating\n\nypred = np.empty(shape  = (0,))\n\nypred_std = np.empty(shape  = (0,))\n\nfor x,y in df_test.itertuples():\n\n\t# predict for x value\n\n\typ,yp_std = model.predict(x,return_value  =  True)\n\n\typred = np.append(ypred,yp)\n\n\typred_std = np.append(ypred_std,yp_std)\n\n\t# update the model for (x,y)\n\n\tdata = {'x_update': x, 'y_update': y}\n\n\tmodel.update(**data)\n\n\n\n# Show new prediction\n\n# Show new update prediction\n\nfig2.add_trace(\n    go.Scatter(\n        x=df_test.index,\n        y=ypred,\n        mode=\"lines\",\n        name='Prediction(horizon = 1)',\n        showlegend=True)\n)\n\nfig2.write_image(\"fig2_update_one_head.png\",width = 900,height =700, scale = 5)\n\n  \n\n\n```\n\n   <img src=\"assets_images/fig2_update_one_head.png\" width=\"900px\"/>\n\n\n  \n\n#### After updating, how to check?\n  \nNote that each time the model is updated with a new data \tdata = {'x_update': x (time), 'y_update': y (value)}\nor even data vector. The model learns this data and adjusts itself to become more and more efficient.\n\n```python\n\n#prediction of data already seen(updated)\nyupdate, _ = model.predict(df_test.index,return_value = True)\n\nfig2.add_trace(\n    go.Scatter(\n        x=df_test.index,\n        y=ypred,\n        mode=\"lines\",\n        name='Prediction(horizon = 1)',\n        showlegend=True)\n)\n\n\nfig2.add_trace(\n    go.Scatter(\n        x=df_test.index,\n        y=yupdate,\n        mode=\"lines\",\n        name='Update model',\n        showlegend=True)\n)\nfig2.show()\nfig2.write_image(\"fig2_update.png\",width = 900,height =700, scale = 5)\n\n\n\n  \n\n```\n   <img src=\"assets_images/fig2_update.png\" width=\"900px\"/>\n\n  \n",
    "bugtrack_url": null,
    "license": "GPLv3",
    "summary": "Automatic and fast Gaussian process for time serie prediction.",
    "version": "4.1.1",
    "project_urls": {
        "Download": "https://github.com/HananyTolba/MakePrediction.git",
        "Homepage": "https://github.com/HananyTolba/MakePrediction.git"
    },
    "split_keywords": [
        "gaussian process regression",
        "time series prediction",
        "machine learning"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a8c5b89c5965040fedebeb9904a711102921c7f6e2b203fb3cfaf4ccbbe2f121",
                "md5": "3270322bc28836c697cb15552aa45340",
                "sha256": "1a506f37573c875901654f71132a136bba3162dbcb9ee269aa7d7d231cd548c3"
            },
            "downloads": -1,
            "filename": "makeprediction-4.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3270322bc28836c697cb15552aa45340",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 58630,
            "upload_time": "2023-05-27T11:43:13",
            "upload_time_iso_8601": "2023-05-27T11:43:13.618775Z",
            "url": "https://files.pythonhosted.org/packages/a8/c5/b89c5965040fedebeb9904a711102921c7f6e2b203fb3cfaf4ccbbe2f121/makeprediction-4.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6af7769a0e93b5bedf8e3e791d61ca4c108bf080025e7e02017d53f5fec99832",
                "md5": "94a73b8b807b6ae05dcbb515e37b9f43",
                "sha256": "420fa859d5197f0292966f3a4f70b8299269b8a38724ce2b8bfbaf0c79b83a50"
            },
            "downloads": -1,
            "filename": "makeprediction-4.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "94a73b8b807b6ae05dcbb515e37b9f43",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 50500,
            "upload_time": "2023-05-27T11:43:16",
            "upload_time_iso_8601": "2023-05-27T11:43:16.336505Z",
            "url": "https://files.pythonhosted.org/packages/6a/f7/769a0e93b5bedf8e3e791d61ca4c108bf080025e7e02017d53f5fec99832/makeprediction-4.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-05-27 11:43:16",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "HananyTolba",
    "github_project": "MakePrediction",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "makeprediction"
}
        
Elapsed time: 0.07697s