Skip to main content

Library/framework for making predictions.

Project description

predictit

PyPI pyversions PyPI version Language grade: Python Build Status Documentation Status License: MIT

Library/framework for making predictions. Choose best of 20 models (ARIMA, regressions, LSTM...) from libraries like statsmodels, scikit-learn, tensorflow and some own models. There are hundreds of customizable options (it's not necessary of course) as well as some config presets.

Library contain model hyperparameters optimization as well as option variable optimization. That means, that library can find optimal preprocessing (smoothing, dropping non correlated columns, standardization) and on top of that it can find optimal models inner parameters such as number of neuron layers.

Output

Most common output is plotly interactive graph, numpy array of results or deploying to database.

Plot of results

Table of results

Return type of main predict function depends on configation.py. It can return best prediction as array or all predictions as dataframe. Interactive html plot is also created.

Oficial repo and documentation links

Repo on github

Official readthedocs documentation

Installation

Python >=3.6. Python 2 is not supported. Install just with

pip install predictit

Sometime you can have issues with installing some libraries from requirements (e.g. numpy because not BLAS / LAPACK). There are also two libraries - Tensorflow and pyodbc not in requirements, because not necessary, but troublesome. If library not installed with pip, check which library don't work, install manually with stackoverflow and repeat...

How to

Software can be used in three ways. As a python library or with command line arguments or as normal python scripts. Main function is predict in main.py script. There is also predict_multiple_columns if you want to predict more at once (columns or time frequentions) and also compare_models function that evaluate defined test data and can tell you which models are best. Then you can use only such a models.

Simple example of using predictit as a python library and function arguments

import predictit
import numpy as np

predictions = predictit.main.predict(data=np.random.randn(1, 100), predicts=3, plotit=1)

Simple example of using as a python library and editing config

import predictit
from predictit.configuration import config

# You can edit config in two ways
config.data_source = 'csv'
config.csv_full_path = 'https://datahub.io/core/global-temp/r/monthly.csv'  # You can use local path on pc as well... "/home/dan/..."
config.predicted_column = 'Mean'
config.datetime_index = 'Date'

# Or
config.update({
    'predicts': 3,
    'default_n_steps_in': 15
})

predictions = predictit.main.predict()

Simple example of using main.py as a script

Open configuration.py (only script you need to edit (very simple)), do the setup. Mainly used_function and data or data_source and path. Then just run main.py.

Simple example of using command line arguments

Run code below in terminal in predictit folder. Use python main.py --help for more parameters info.

python main.py --used_function predict --data_source 'csv' --csv_full_path 'https://datahub.io/core/global-temp/r/monthly.csv' --predicted_column "'Mean'"

Explore config

To see all the possible values in configuration.py from your IDE, use

predictit.configuration.print_config()

Example of compare_models function

import predictit
from predictit.configuration import config

my_data_array = np.random.randn(2000, 4)  # Define your data here

# You can compare it on same data in various parts or on different data (check configuration on how to insert dictionary with data names)
config.update({
    'data_all': (my_data_array[-2000:], my_data_array[-1500:], my_data_array[-1000:])
})

predictit.main.compare_models()

Example of predict_multiple function

import predictit
from predictit.configuration import config

config.data = pd.read_csv("https://datahub.io/core/global-temp/r/monthly.csv")

# Define list of columns or '*' for predicting all of the columns
config.predicted_columns = ['*']

predictit.main.predict_multiple_columns()

Example of config variable optimization

config.update({
    'data_source': 'csv',
    'csv_full_path': "https://datahub.io/core/global-temp/r/monthly.csv",
    'predicted_column': 'Mean',
    'return_type': 'all_dataframe',
    'optimization': 1,
    'optimization_variable': 'default_n_steps_in',
    'optimization_values': [12, 20, 40],
    'plot_all_optimized_models': 1,
    'print_detailed_result': 1
})

predictions = predictit.main.predict()

Hyperparameters tuning

To optmize hyperparameters, just set optimizeit: 1, and model parameters limits. It is commented in config.py how to use it. It's not grid bruteforce. Heuristic method based on halving interval is used, but still it can be time consuming. It is recomend only to tune parameters worth of it. Or tune it by parts.

GUI

It is possible to use basic GUI. But only with CSV data source. Just run gui_start.py if you have downloaded software or call predictit.gui_start.run_gui() if you are importing via PyPI.

Example of using library as a pro with deeper editting config

import predictit
from predictit.configuration import config

config.update({
    'data_source': 'test',  # Data source. ('csv' or 'sql' or 'test')
    'csv_full_path': r'C:\Users\truton\ownCloud\Github\predictit_library\predictit\test_data\5000 Sales Records.csv',  # Full CSV path with suffix
    'predicted_column': '',  # Column name that we want to predict

    'predicts': 7,  # Number of predicted values - 7 by default
    'print_number_of_models': 6,  # Visualize 6 best models
    'repeatit': 50,  # Repeat calculation times on shifted data to evaluate error criterion
    'other_columns': 0,  # Whether use other columns or not
    'debug': 1,  # Whether print details and warnings

    # Chose models that will be computed - remove if you want to use all the models
    'used_models': [
        "AR (Autoregression)",
        "ARIMA (Autoregression integrated moving average)",
        "Autoregressive Linear neural unit",
        "Conjugate gradient",
        "Sklearn regression",
        'Bayes ridge regression one step',
        'Decision tree regression',
    ],

    # Define parameters of models

    'models_parameters': {

        'AR (Autoregression)': {'used_model': 'ar', 'method': 'cmle', 'ic': 'aic', 'trend': 'nc', 'solver': 'lbfgs'},
        'ARIMA (Autoregression integrated moving average)': {'used_model': 'arima', 'p': 6, 'd': 0, 'q': 0, 'method': 'css', 'ic': 'aic', 'trend': 'nc', 'solver': 'nm'},

        'Autoregressive Linear neural unit': {'mi_multiple': 1, 'mi_linspace': (1e-5, 1e-4, 3), 'epochs': 10, 'w_predict': 0, 'minormit': 0},
        'Conjugate gradient': {'epochs': 200},

        'Bayes ridge regression': {'regressor': 'bayesianridge', 'n_iter': 300, 'alpha_1': 1.e-6, 'alpha_2': 1.e-6, 'lambda_1': 1.e-6, 'lambda_2': 1.e-6},

})

predictions = predictit.main.predict()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

predictit-1.46.5.tar.gz (50.4 kB view details)

Uploaded Source

Built Distributions

predictit-1.46.5-py3.7.egg (115.1 kB view details)

Uploaded Source

predictit-1.46.5-py3-none-any.whl (57.2 kB view details)

Uploaded Python 3

File details

Details for the file predictit-1.46.5.tar.gz.

File metadata

  • Download URL: predictit-1.46.5.tar.gz
  • Upload date:
  • Size: 50.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.1

File hashes

Hashes for predictit-1.46.5.tar.gz
Algorithm Hash digest
SHA256 652ae0221994dcc5b468692cc1a29a586e28779d6b756669ba8817dccb61de13
MD5 de2daa32f44b4b6f96f52e54f6ee6097
BLAKE2b-256 7b477ad0f95c7292e402b3c50749dec2cc2359ec4baa1fd6e3f701f08cdd3982

See more details on using hashes here.

File details

Details for the file predictit-1.46.5-py3.7.egg.

File metadata

  • Download URL: predictit-1.46.5-py3.7.egg
  • Upload date:
  • Size: 115.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.1

File hashes

Hashes for predictit-1.46.5-py3.7.egg
Algorithm Hash digest
SHA256 d3fb19cc41cde6a5d08520070f8de76583425370c5e2ea23f6dbeb755dd5fe31
MD5 429aed99054c60e2bb84e037fdbf82c1
BLAKE2b-256 671195c130c6eebf1fe9e5b62bd944b2b27eb948ad5ed5660d28abbad8c65599

See more details on using hashes here.

File details

Details for the file predictit-1.46.5-py3-none-any.whl.

File metadata

  • Download URL: predictit-1.46.5-py3-none-any.whl
  • Upload date:
  • Size: 57.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.1

File hashes

Hashes for predictit-1.46.5-py3-none-any.whl
Algorithm Hash digest
SHA256 2654faf1f43d1eea4bfce27a73d2fadb87d13807c5250b9ba53c4704d3b62099
MD5 2bf0af237b0a22c5614d470a116067ca
BLAKE2b-256 c2fb24cca805fccab048293f890f35d9a74df511b4cc45ffbd0cd31d97206679

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page