Skip to main content

Simple linear prediction - fit y = mx + c and predict values

Project description

LinPredict

PyPI version Python 3.8+ License: MIT

Simple linear prediction library. Pass x and y values, get the next predicted value.

Installation

pip install linpredict

Quick Start

from linpredict import quick_predict, fit, predict_next

# Simplest usage - just pass y values
predictions = quick_predict([2, 4, 6, 8])
print(predictions)  # [10.0]

# Predict multiple steps ahead
predictions = quick_predict([2, 4, 6, 8], steps=3)
print(predictions)  # [10.0, 12.0, 14.0]

Full Usage

from linpredict import fit, predict_next

# Fit a line to your data
x = [1, 2, 3, 4, 5]
y = [2.1, 3.9, 6.2, 7.8, 10.1]

# Get the line equation
eq = fit(x, y)
print(eq)  # y = 1.9900x + 0.0600

# Access slope and intercept
print(f"Slope: {eq.slope}")      # ~2.0
print(f"Intercept: {eq.intercept}")  # ~0.0

# Predict specific x values
print(eq.predict(6))      # Single prediction
print(eq.predict([6, 7, 8]))  # Multiple predictions

# Or use predict_next for automatic next value
next_x, next_y = predict_next(x, y, steps=2)
print(f"Next x: {next_x}, Next y: {next_y}")

API Reference

fit(x, y) -> LineEquation

Fit a line (y = mx + c) to data points. Returns a LineEquation object.

predict_next(x, y, steps=1) -> (list, list)

Predict the next value(s) in sequence. Returns tuple of (next_x_values, predicted_y_values).

quick_predict(y, steps=1) -> list

Quick prediction when you only have y values (assumes x is 0, 1, 2, ...).

LineEquation

  • .slope - The m in y = mx + c
  • .intercept - The c in y = mx + c
  • .predict(x) - Predict y for given x value(s)

License

MIT

Author

PRAVIN MR

GitHub: https://github.com/mr-pravin

Email: mrpravin000@gmail.com

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

linpredict-0.1.0.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

linpredict-0.1.0-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file linpredict-0.1.0.tar.gz.

File metadata

  • Download URL: linpredict-0.1.0.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for linpredict-0.1.0.tar.gz
Algorithm Hash digest
SHA256 06d1e6e4f9074c4f20a315036c70c3042e7b9da52e8cd624ea6dc1f9ef25e859
MD5 d2d0329b120a8e7e35ed0038fa25eab9
BLAKE2b-256 1b92b1f74b6c7bf5373f21daf1f0a63477a79f9a0061c5f3a41f58e26c33031d

See more details on using hashes here.

File details

Details for the file linpredict-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: linpredict-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for linpredict-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9885749021e4b8219b3cafbd2f25ac940340ded59c686cf451210a33a54bcdd5
MD5 98f1ba4320b92f794a39c9ed8a0dc728
BLAKE2b-256 4c5e5122fab9b2689fe53bfee2e0ef0d18e24db1c067c56bbecc9a0780f0136a

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