GithubHelp home page GithubHelp logo

brendanartley / regressio Goto Github PK

View Code? Open in Web Editor NEW
337.0 6.0 9.0 961 KB

A python library for univariate regression, interpolation, and smoothing.

License: MIT License

Jupyter Notebook 8.74% Python 91.26%
interpolation python regression smoothing time-series

regressio's Introduction

Regressio is a python module for univariate regression, interpolation, and smoothing.

The available models are:

  • Linear regression
  • Ridge regression
  • Linear spline
  • Isotonic regression
  • Bin regression
  • Cubic spline
  • Natural cubic spline
  • Exponential moving average
  • Kernel functions (Gaussian, KNN, Weighted average)

There are also functions implemented to generate data samples.

The available data generators are:

  • Random walk
  • Isotonic sample

Installation

Regressio is supported in Python 3.8+ and requires only NumPy and Matplotlib.

pip install regressio --upgrade

or

pip install git+https://github.com/brendanartley/Regressio

Example Usage

Cubic spline.

# Import modules + classes
from regressio.models import cubic_spline
from regressio.datagen import generate_random_walk
import numpy as np
import matplotlib.pyplot as plt

# Set figsize and seed
plt.rcParams['figure.figsize'] = (10, 5)
np.random.seed(0)

# Generate data sample
x, y = generate_random_walk(150)

# Fit model and plot result
model = cubic_spline(pieces=15)
model.fit(x, y, plot=True, confidence_interval=0.99)

Cubic spline

Linear regression.

# Import modules + classes
from regressio.models import linear_regression
from regressio.datagen import generate_random_walk
import numpy as np
import matplotlib.pyplot as plt

# Set figsize and seed
plt.rcParams['figure.figsize'] = (10, 5)
np.random.seed(1)

# Generate data sample
x, y = generate_random_walk(100)

# Fit model and plot result
model = linear_regression(degree=5)
model.fit(x, y, plot=True, confidence_interval=0.95)

Linear regression

Exponential moving average.

# Import modules + classes
from regressio.models import exp_moving_average
from regressio.datagen import generate_isotonic_sample
import numpy as np
import matplotlib.pyplot as plt

# Set figsize and seed
plt.rcParams['figure.figsize'] = (10, 5)
np.random.seed(6)

# Generate data sample
x, y = generate_isotonic_sample(100)

# Fit model and plot result
model = exp_moving_average(alpha=0.2)
model.fit(x, y, plot=True, confidence_interval=0.90)

Exponential moving average

For more examples, navigate to the examples.ipynb file in this repository.

Contributions

We welcome all to contribute their expertise to the Regressio library. If you are new to open source contributions, this guide gives some great tips on how to get started.

If you have a complex feature in mind or find a large bug in the code, please create a detailed issue and we will get to work on it.

References

  • Hyndman, R.J., & Athanasopoulos, G. (2021) Forecasting: principles and practice, 3rd edition, OTexts: Melbourne, Australia. OTexts.com/fpp3. Accessed July 2022.

  • Kong, Qingkai, et al. Python Programming and Numerical Methods: A Guide for Engineers and Scientists. Academic Press, an Imprint of Elsevier, pythonnumericalmethods.berkeley.edu, Accessed July 2022.

  • Li, Bao, (2022). Stat 508: Applied Data Mining, Statistical Learning: Stat Online. PennState: Statistics Online Courses, online.stat.psu.edu/stat508, Accessed July 2022.

  • Brett, M. (2014, October 26). An introduction to smoothing. Tutorials on imaging, computing and mathematics. matthew-brett.github.io/teaching, Accessed July 2022.

BibText

@misc{Regressio,
      title={Regressio: A python module for univariate regression, interpolation, and smoothing}, 
      author={Brendan Artley},
      year={2022},
      publisher={GitHub},
      journal={GitHub repository},
      Howpublished = {\url{https://github.com/brendanartley/Regressio}}
}

regressio's People

Contributors

brendanartley avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

regressio's Issues

Improve z-score calculation

Currently the only confidence intervals supported are those encoded in a dictionary. Need to implement a method that accepts any confidence interval between 0-1.

Split Interpolation and Regression

  • First need to implement more interpolation methods (Cubic Spline, Natural Cubic Spline)
  • Need to rename Isotonic regression to Isotonic Interpolation
  • Separate interpolation functions from regression models (ex. regression.py, interpolation.py)

Fix examples.ipynb file

Exponential smoothing model uses the old notation. Need to update this file to the new class name

Consider data storage in class

Consider storing the x, y, and smoothed values in the model for prediction interval calculation. This could result in easier confidence interval/prediction interval calculations.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.