Skip to main content

Generate regression models from data

Project description

Regressions Library

A collection of algorithms for fitting data to different functional models by using matrices. This library will be made publically available after it is uploaded to Python's database of libraries. It contains all the code for determining regression equations, as well as the code for evaluating said regressions and presenting their results in a raw format. The published version on PyPI is available here.

Contents

  1. File Structure
  2. Code Examples

File Structure

regressions_library  
|-- matrices  
|   |-- matrix.py  
|   |-- magnitude.py  
|   |-- dot_product.py  
|   |-- column.py  
|   |-- additions.py  
|   |-- scalar.py  
|   |-- multiplication.py  
|   |-- determinant.py  
|   |-- cofactors.py  
|   |-- minors.py  
|   |-- inverse.py  
|   |-- transpose.py  
|-- regressions  
|   |-- run_all.py  
|   |-- best.py  
|   |-- error.py  
|   |-- linear.py  
|   |-- quadratic.py  
|   |-- cubic.py  
|   |-- hyperbolic.py  
|   |-- exponential.py  
|   |-- logarithmic.py  
|   |-- logistic.py  
|   |-- sinusoidal.py  
|-- tests  
|   |-- matrices.py  
|   |-- regressions.py  
|-- READE.md  
|-- .gitignore  

Code Examples

Linear Regression

def linear(data):
    independent_matrix = []
    dependent_matrix = []
    for i in range(len(data)):
        independent_matrix.append([data[i][0], 1])
        dependent_matrix.append([data[i][1]])
    transposition = transpose(independent_matrix)
    product = multiplication(transposition, independent_matrix)
    product_matrix = matrix(product, dtype='float')
    inversion = inv(product_matrix)
    inversion_list = matrix.tolist(inversion)
    second_product = multiplication(inversion_list, transposition)
    solution = multiplication(second_product, dependent_matrix)
    equation = lambda x: solution[0][0]*x + solution[1][0]
    inaccuracy = error(data, equation)
    result = {
        'constants': solution,
        'error': inaccuracy
    }
    return result

Error Calculation

def error(data, equation):
    summation = 0
    for i in range(len(data)):
        summation += (data[i][1] - equation(data[i][0]))**2
    result = summation**(1/4)
    return result

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

regressions-1.0.1.tar.gz (7.7 kB view details)

Uploaded Source

File details

Details for the file regressions-1.0.1.tar.gz.

File metadata

  • Download URL: regressions-1.0.1.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1

File hashes

Hashes for regressions-1.0.1.tar.gz
Algorithm Hash digest
SHA256 1fb47ffafa38f92b2ab85b75ad8ad854201ad21e3c87be30fb137915bf5e2afc
MD5 b11c13734e5b690388e02b10325cee36
BLAKE2b-256 22e3f5555b6dd19964c4c61a4d5e065870549fb530701f605f00d6a038720c9e

See more details on using hashes here.

Supported by

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