Metadata-Version: 2.4
Name: mylinreg-pkg
Version: 1.0.0
Summary: A from-scratch ML package for house price prediction
Home-page: https://github.com/yourusername/mylinreg_pkg
Author: ML
Author-email: ML <your@email.com>
License: MIT
Project-URL: Homepage, https://github.com/yourusername/mylinreg_pkg
Project-URL: Bug Tracker, https://github.com/yourusername/mylinreg_pkg/issues
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Intended Audience :: Education
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=1.21.0
Requires-Dist: pandas>=1.3.0
Requires-Dist: matplotlib>=3.4.0
Dynamic: author
Dynamic: home-page
Dynamic: license-file
Dynamic: requires-python

# 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

```bash
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

```python
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
