Skip to main content

Educational regression models built from scratch in Python

Project description

LinearRegression From Scratch

A minimal, easy-to-understand implementation of Linear Regression in Python using only NumPy.
Designed for educational purposes to show how gradient descent optimizes linear models step by step.

🚀 Features

  • Fits simple linear models with gradient descent
  • Clean OOP class structure
  • Pure NumPy implementation (no scikit-learn)
  • Supports multi-feature data
  • Easy to extend for regularization
  • Printed training loss progress
  • Simple fit, predict, and evaluate interface

📦 Installation

You can simply copy the linear_regression.py file into your project.
No external dependencies are required except NumPy.

import numpy as np from linear_regression import LinearRegression

toy dataset

X_train = np.array([[1], [2], [3], [4], [5]]) y_train = np.array([2, 4, 6, 8, 10])

initialize model

model = LinearRegression(learning_rate=0.01, epochs=1000)

train

model.fit(X_train, y_train)

predict

predictions = model.predict(X_train)

evaluate

mse, r2 = model.evaluate(X_train, y_train)

print("Predictions:", predictions) print(f"MSE: {mse:.4f}, R2: {r2:.4f}")

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

MLPredictiveModels-0.4-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file MLPredictiveModels-0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for MLPredictiveModels-0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 3538faa9f96af48b57e1cc7bff3abea9c457f47fa54dcac854574e7e41cbd5be
MD5 ec70f0ad0f6d20da9cc761fe1c2e658f
BLAKE2b-256 2a01bd39c7bcdd77b8fba1eb4bd2ade5f6579029ba7777ebdd4b8536b8b3167f

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