Skip to main content

mylinreg-pkg

A from-scratch machine learning package for house price prediction, implementing OLS, Ridge, Lasso, KNN, and Perceptron — built with only NumPy, Pandas, and Matplotlib.

Installation

pip install mylinreg-pkg

Features

Module Class Algorithm
linear_model LinearRegressionOLS Ordinary Least Squares
ridge RidgeRegression Ridge (L2 regularisation)
lasso LassoRegression Lasso (L1 coordinate descent)
preprocessing Preprocessing Missing values, outliers, standardisation
metrics Metrics MAE, MSE, R²
feature_selection FeatureSelection Forward selection, backward elimination
diagnostics Diagnostics Multicollinearity, residuals
visualization Visualization Actual vs predicted, residual plots

Quick Start

import numpy as np
import pandas as pd
from mylinreg_pkg import LinearRegressionOLS, RidgeRegression, LassoRegression
from mylinreg_pkg import Metrics, Preprocessing

# Load and preprocess data
df = pd.read_csv("dataset.csv")
df = Preprocessing.missing_values(df)

# Prepare features and target
X = df[["bhk", "area_sqft", "price_per_sqft"]].to_numpy(dtype=float)
y = df["price_lakhs"].to_numpy(dtype=float)

# Train/test split
split = int(len(X) * 0.8)
X_train, X_test = X[:split], X[split:]
y_train, y_test = y[:split], y[split:]

# Normalise
mean, std = X_train.mean(0), X_train.std(0)
std[std == 0] = 1
X_train = (X_train - mean) / std
X_test  = (X_test  - mean) / std

# OLS
ols = LinearRegressionOLS()
ols.fit(X_train, y_train)
y_pred = ols.predict(X_test)
print("OLS  R²:", round(Metrics.r2(y_test, y_pred), 4))

# Ridge
ridge = RidgeRegression(alpha=1.0)
ridge.fit(X_train, y_train)
y_pred = ridge.predict(X_test)
print("Ridge R²:", round(Metrics.r2(y_test, y_pred), 4))

# Lasso
lasso = LassoRegression(alpha=10.0, iterations=1000)
lasso.fit(X_train, y_train)
y_pred = lasso.predict(X_test)
print("Lasso R²:", round(Metrics.r2(y_test, y_pred), 4))

Algorithms

OLS Regression

Closed-form solution: β = (XᵀX)⁻¹ Xᵀy using Moore-Penrose pseudo-inverse for numerical stability.

Ridge Regression

L2-penalised: β = (XᵀX + αI)⁻¹ Xᵀy — shrinks coefficients to reduce variance.

Lasso Regression

L1-penalised via coordinate descent with soft-thresholding — can zero out coefficients for feature selection.

KNN Classifier (standalone knn.py)

Euclidean distance with min-max normalisation. Use odd k to avoid tie votes.

Perceptron (standalone perceptron.py)

Single-layer binary classifier with Heaviside activation and online weight updates.

Results on Pune Housing Dataset (N=150)

Model MAE RMSE R²
OLS 7,957 11,002 0.6844
Ridge (α=1.0) 7,757 10,678 0.7027
Lasso (α=10.0) 7,953 10,993 0.6849

KNN BHK classification accuracy: 73.3% at k=3.

License

MIT

Metadata

Release files for mylinreg-pkg 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mylinreg-pkg 1.0.0
File Size Uploaded Provenance Actions
mylinreg_pkg-1.0.0.tar.gz 8.0 kB Without provenance Details for mylinreg_pkg-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mylinreg-pkg 1.0.0
File Interpreter ABI Platform Actions
mylinreg_pkg-1.0.0-py3-none-any.whl Python 3 none any Details for mylinreg_pkg-1.0.0-py3-none-any.whl

Total release size: 17.0 kB

Release files / mylinreg_pkg-1.0.0.tar.gz

Download URL mylinreg_pkg-1.0.0.tar.gz
Size 8.0 kB
Tags Source
SHA-256 checksum
How to use checksums
6e8c016ad64e916a814de343c4564f7916a232f1768e4b1f21f3c38bda68d5c5
BLAKE2b-256 checksum
How to use checksums
709a66d1e2570c1c7941c1341eed835510f8c57c562187764ef42b8b180d5ef1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.11

Release files / mylinreg_pkg-1.0.0-py3-none-any.whl

Download URL mylinreg_pkg-1.0.0-py3-none-any.whl
Size 9.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dd5ea7874d9982b561a78a1ce02590cc632f33e023f4e816dd8fed9070eaec0d
BLAKE2b-256 checksum
How to use checksums
2333e30f9b757dec076e0bb7cdc042456837c5256131af9906396429c67d0377
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.11

Security for mylinreg-pkg 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page