avish-lib 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- avish_lib-0.1.0/LICENSE +21 -0
- avish_lib-0.1.0/PKG-INFO +67 -0
- avish_lib-0.1.0/README.md +41 -0
- avish_lib-0.1.0/pyproject.toml +31 -0
- avish_lib-0.1.0/setup.cfg +4 -0
- avish_lib-0.1.0/setup.py +32 -0
- avish_lib-0.1.0/src/avish_lib/__init__.py +22 -0
- avish_lib-0.1.0/src/avish_lib/linear_models.py +187 -0
- avish_lib-0.1.0/src/avish_lib.egg-info/PKG-INFO +67 -0
- avish_lib-0.1.0/src/avish_lib.egg-info/SOURCES.txt +12 -0
- avish_lib-0.1.0/src/avish_lib.egg-info/dependency_links.txt +1 -0
- avish_lib-0.1.0/src/avish_lib.egg-info/requires.txt +1 -0
- avish_lib-0.1.0/src/avish_lib.egg-info/top_level.txt +1 -0
- avish_lib-0.1.0/tests/test_basic.py +15 -0
avish_lib-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Avish
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
avish_lib-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: avish_lib
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Lightweight custom ML algorithms library (avish_lib)
|
|
5
|
+
Home-page: https://github.com/yourusername/avish_lib
|
|
6
|
+
Author: Avish
|
|
7
|
+
Project-URL: Homepage, https://github.com/yourusername/avish_lib
|
|
8
|
+
Project-URL: Repository, https://github.com/yourusername/avish_lib
|
|
9
|
+
Project-URL: Documentation, https://github.com/yourusername/avish_lib#readme
|
|
10
|
+
Keywords: machine learning,regression,pca,numpy,ml
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Requires-Python: >=3.8
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: numpy>=1.21
|
|
23
|
+
Dynamic: home-page
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
Dynamic: requires-python
|
|
26
|
+
|
|
27
|
+
# avish_lib
|
|
28
|
+
|
|
29
|
+
avish_lib is a small collection of custom machine-learning algorithms implemented with minimal dependencies (NumPy).
|
|
30
|
+
|
|
31
|
+
Install for local development:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
python -m pip install -e .
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Quick usage:
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
from avish_lib import LinearRegression, RidgeRegression, KNNRegressor, PCA
|
|
41
|
+
|
|
42
|
+
# Simple linear fit
|
|
43
|
+
X = [[1], [2], [3], [4]]
|
|
44
|
+
y = [2, 4, 6, 8]
|
|
45
|
+
model = LinearRegression()
|
|
46
|
+
model.fit(X, y)
|
|
47
|
+
print("coef:", model.coef_, "intercept:", model.intercept_)
|
|
48
|
+
|
|
49
|
+
# PCA example
|
|
50
|
+
p = PCA(n_components=1)
|
|
51
|
+
X_reduced = p.fit_transform([[1,2],[3,4],[5,6]])
|
|
52
|
+
print(X_reduced)
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Project layout:
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
your_project_name/
|
|
59
|
+
├── src/
|
|
60
|
+
│ └── avish_lib/
|
|
61
|
+
│ ├── __init__.py
|
|
62
|
+
│ └── linear_models.py
|
|
63
|
+
├── tests/
|
|
64
|
+
├── pyproject.toml
|
|
65
|
+
├── README.md
|
|
66
|
+
└── LICENSE
|
|
67
|
+
```
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# avish_lib
|
|
2
|
+
|
|
3
|
+
avish_lib is a small collection of custom machine-learning algorithms implemented with minimal dependencies (NumPy).
|
|
4
|
+
|
|
5
|
+
Install for local development:
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
python -m pip install -e .
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Quick usage:
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
from avish_lib import LinearRegression, RidgeRegression, KNNRegressor, PCA
|
|
15
|
+
|
|
16
|
+
# Simple linear fit
|
|
17
|
+
X = [[1], [2], [3], [4]]
|
|
18
|
+
y = [2, 4, 6, 8]
|
|
19
|
+
model = LinearRegression()
|
|
20
|
+
model.fit(X, y)
|
|
21
|
+
print("coef:", model.coef_, "intercept:", model.intercept_)
|
|
22
|
+
|
|
23
|
+
# PCA example
|
|
24
|
+
p = PCA(n_components=1)
|
|
25
|
+
X_reduced = p.fit_transform([[1,2],[3,4],[5,6]])
|
|
26
|
+
print(X_reduced)
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Project layout:
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
your_project_name/
|
|
33
|
+
├── src/
|
|
34
|
+
│ └── avish_lib/
|
|
35
|
+
│ ├── __init__.py
|
|
36
|
+
│ └── linear_models.py
|
|
37
|
+
├── tests/
|
|
38
|
+
├── pyproject.toml
|
|
39
|
+
├── README.md
|
|
40
|
+
└── LICENSE
|
|
41
|
+
```
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "avish_lib"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Lightweight custom ML algorithms library (avish_lib)"
|
|
9
|
+
authors = [ { name = "Avish" } ]
|
|
10
|
+
readme = "README.md"
|
|
11
|
+
requires-python = ">=3.8"
|
|
12
|
+
dependencies = ["numpy>=1.21"]
|
|
13
|
+
keywords = ["machine learning", "regression", "pca", "numpy", "ml"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 4 - Beta",
|
|
16
|
+
"Intended Audience :: Developers",
|
|
17
|
+
"License :: OSI Approved :: MIT License",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Programming Language :: Python :: 3.8",
|
|
20
|
+
"Programming Language :: Python :: 3.9",
|
|
21
|
+
"Programming Language :: Python :: 3.10",
|
|
22
|
+
"Programming Language :: Python :: 3.11",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
[project.urls]
|
|
26
|
+
Homepage = "https://github.com/yourusername/avish_lib"
|
|
27
|
+
Repository = "https://github.com/yourusername/avish_lib"
|
|
28
|
+
Documentation = "https://github.com/yourusername/avish_lib#readme"
|
|
29
|
+
|
|
30
|
+
[tool.pytest.ini_options]
|
|
31
|
+
addopts = "-q"
|
avish_lib-0.1.0/setup.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
"""
|
|
3
|
+
Alternative setup.py for avish_lib (complements pyproject.toml).
|
|
4
|
+
This is optional but provides backward compatibility.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from setuptools import setup, find_packages
|
|
8
|
+
|
|
9
|
+
setup(
|
|
10
|
+
name="avish_lib",
|
|
11
|
+
version="0.1.0",
|
|
12
|
+
description="Lightweight custom ML algorithms library",
|
|
13
|
+
long_description=open("README.md").read(),
|
|
14
|
+
long_description_content_type="text/markdown",
|
|
15
|
+
author="Avish",
|
|
16
|
+
url="https://github.com/yourusername/avish_lib", # Update this
|
|
17
|
+
license="MIT",
|
|
18
|
+
packages=find_packages(where="src"),
|
|
19
|
+
package_dir={"": "src"},
|
|
20
|
+
python_requires=">=3.8",
|
|
21
|
+
install_requires=["numpy>=1.21"],
|
|
22
|
+
classifiers=[
|
|
23
|
+
"Development Status :: 3 - Alpha",
|
|
24
|
+
"Intended Audience :: Developers",
|
|
25
|
+
"License :: OSI Approved :: MIT License",
|
|
26
|
+
"Programming Language :: Python :: 3",
|
|
27
|
+
"Programming Language :: Python :: 3.8",
|
|
28
|
+
"Programming Language :: Python :: 3.9",
|
|
29
|
+
"Programming Language :: Python :: 3.10",
|
|
30
|
+
"Programming Language :: Python :: 3.11",
|
|
31
|
+
],
|
|
32
|
+
)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"""avish_lib package — lightweight custom ML algorithms.
|
|
2
|
+
|
|
3
|
+
Expose core models for easy importing:
|
|
4
|
+
|
|
5
|
+
from avish_lib import LinearRegression, RidgeRegression, KNNRegressor, PCA
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from .linear_models import (
|
|
9
|
+
LinearRegression,
|
|
10
|
+
RidgeRegression,
|
|
11
|
+
LassoRegression,
|
|
12
|
+
KNNRegressor,
|
|
13
|
+
PCA,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
__all__ = [
|
|
17
|
+
"LinearRegression",
|
|
18
|
+
"RidgeRegression",
|
|
19
|
+
"LassoRegression",
|
|
20
|
+
"KNNRegressor",
|
|
21
|
+
"PCA",
|
|
22
|
+
]
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"""Minimal implementations of a few algorithms for avish_lib.
|
|
2
|
+
|
|
3
|
+
This file intentionally keeps implementations small and dependency-light (only numpy).
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from typing import Optional
|
|
7
|
+
import numpy as np
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class LinearRegression:
|
|
11
|
+
"""Ordinary Least Squares linear regression using the normal equation."""
|
|
12
|
+
|
|
13
|
+
def __init__(self, fit_intercept: bool = True):
|
|
14
|
+
self.fit_intercept = fit_intercept
|
|
15
|
+
self.coef_ = None
|
|
16
|
+
self.intercept_ = 0.0
|
|
17
|
+
|
|
18
|
+
def fit(self, X, y):
|
|
19
|
+
X = np.asarray(X, dtype=float)
|
|
20
|
+
y = np.asarray(y, dtype=float)
|
|
21
|
+
if X.ndim == 1:
|
|
22
|
+
X = X.reshape(-1, 1)
|
|
23
|
+
if self.fit_intercept:
|
|
24
|
+
X_design = np.hstack([np.ones((X.shape[0], 1)), X])
|
|
25
|
+
else:
|
|
26
|
+
X_design = X
|
|
27
|
+
# Normal equation with pseudo-inverse for stability
|
|
28
|
+
theta = np.linalg.pinv(X_design.T.dot(X_design)).dot(X_design.T).dot(y)
|
|
29
|
+
if self.fit_intercept:
|
|
30
|
+
self.intercept_ = float(theta[0])
|
|
31
|
+
self.coef_ = theta[1:]
|
|
32
|
+
else:
|
|
33
|
+
self.coef_ = theta
|
|
34
|
+
self.intercept_ = 0.0
|
|
35
|
+
return self
|
|
36
|
+
|
|
37
|
+
def predict(self, X):
|
|
38
|
+
X = np.asarray(X, dtype=float)
|
|
39
|
+
if X.ndim == 1:
|
|
40
|
+
X = X.reshape(-1, 1)
|
|
41
|
+
return (X.dot(self.coef_) + self.intercept_).astype(float)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class RidgeRegression(LinearRegression):
|
|
45
|
+
"""Closed-form Ridge regression (L2) using normal equation.
|
|
46
|
+
|
|
47
|
+
alpha: regularization strength (>=0)
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
def __init__(self, alpha: float = 1.0, fit_intercept: bool = True):
|
|
51
|
+
super().__init__(fit_intercept=fit_intercept)
|
|
52
|
+
self.alpha = alpha
|
|
53
|
+
|
|
54
|
+
def fit(self, X, y):
|
|
55
|
+
X = np.asarray(X, dtype=float)
|
|
56
|
+
y = np.asarray(y, dtype=float)
|
|
57
|
+
if X.ndim == 1:
|
|
58
|
+
X = X.reshape(-1, 1)
|
|
59
|
+
if self.fit_intercept:
|
|
60
|
+
X_design = np.hstack([np.ones((X.shape[0], 1)), X])
|
|
61
|
+
else:
|
|
62
|
+
X_design = X
|
|
63
|
+
n_features = X_design.shape[1]
|
|
64
|
+
A = X_design.T.dot(X_design)
|
|
65
|
+
# Regularize bias if fit_intercept=False; otherwise don't regularize bias column
|
|
66
|
+
reg = self.alpha * np.eye(n_features)
|
|
67
|
+
if self.fit_intercept:
|
|
68
|
+
reg[0, 0] = 0.0
|
|
69
|
+
theta = np.linalg.inv(A + reg).dot(X_design.T).dot(y)
|
|
70
|
+
if self.fit_intercept:
|
|
71
|
+
self.intercept_ = float(theta[0])
|
|
72
|
+
self.coef_ = theta[1:]
|
|
73
|
+
else:
|
|
74
|
+
self.coef_ = theta
|
|
75
|
+
self.intercept_ = 0.0
|
|
76
|
+
return self
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
class LassoRegression:
|
|
80
|
+
"""A simple Lasso implementation using iterative soft-thresholding (ISTA).
|
|
81
|
+
|
|
82
|
+
Note: This is a small-scale implementation intended for educational use.
|
|
83
|
+
"""
|
|
84
|
+
|
|
85
|
+
def __init__(self, alpha: float = 1.0, lr: float = 1e-3, iterations: int = 1000, fit_intercept: bool = True):
|
|
86
|
+
self.alpha = alpha
|
|
87
|
+
self.lr = lr
|
|
88
|
+
self.iterations = iterations
|
|
89
|
+
self.fit_intercept = fit_intercept
|
|
90
|
+
self.coef_ = None
|
|
91
|
+
self.intercept_ = 0.0
|
|
92
|
+
|
|
93
|
+
def _soft_threshold(self, x, thresh):
|
|
94
|
+
return np.sign(x) * np.maximum(np.abs(x) - thresh, 0.0)
|
|
95
|
+
|
|
96
|
+
def fit(self, X, y):
|
|
97
|
+
X = np.asarray(X, dtype=float)
|
|
98
|
+
y = np.asarray(y, dtype=float)
|
|
99
|
+
if X.ndim == 1:
|
|
100
|
+
X = X.reshape(-1, 1)
|
|
101
|
+
n_samples, n_features = X.shape
|
|
102
|
+
if self.fit_intercept:
|
|
103
|
+
X_design = np.hstack([np.ones((n_samples, 1)), X])
|
|
104
|
+
else:
|
|
105
|
+
X_design = X
|
|
106
|
+
# initialize
|
|
107
|
+
theta = np.zeros(X_design.shape[1])
|
|
108
|
+
L = np.linalg.norm(X_design, ord=2) ** 2 / n_samples
|
|
109
|
+
if L == 0:
|
|
110
|
+
L = 1.0
|
|
111
|
+
t = 1.0 / L
|
|
112
|
+
for _ in range(self.iterations):
|
|
113
|
+
grad = (1.0 / n_samples) * X_design.T.dot(X_design.dot(theta) - y)
|
|
114
|
+
theta = theta - t * grad
|
|
115
|
+
# apply soft-threshold to non-bias terms
|
|
116
|
+
if self.fit_intercept:
|
|
117
|
+
theta[1:] = self._soft_threshold(theta[1:], t * self.alpha)
|
|
118
|
+
else:
|
|
119
|
+
theta = self._soft_threshold(theta, t * self.alpha)
|
|
120
|
+
if self.fit_intercept:
|
|
121
|
+
self.intercept_ = float(theta[0])
|
|
122
|
+
self.coef_ = theta[1:]
|
|
123
|
+
else:
|
|
124
|
+
self.coef_ = theta
|
|
125
|
+
self.intercept_ = 0.0
|
|
126
|
+
return self
|
|
127
|
+
|
|
128
|
+
def predict(self, X):
|
|
129
|
+
X = np.asarray(X, dtype=float)
|
|
130
|
+
if X.ndim == 1:
|
|
131
|
+
X = X.reshape(-1, 1)
|
|
132
|
+
return (X.dot(self.coef_) + self.intercept_).astype(float)
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
class KNNRegressor:
|
|
136
|
+
"""Simple k-NN regressor using Euclidean distance."""
|
|
137
|
+
|
|
138
|
+
def __init__(self, k: int = 5):
|
|
139
|
+
self.k = max(1, int(k))
|
|
140
|
+
self.X_train = None
|
|
141
|
+
self.y_train = None
|
|
142
|
+
|
|
143
|
+
def fit(self, X, y):
|
|
144
|
+
X = np.asarray(X, dtype=float)
|
|
145
|
+
if X.ndim == 1:
|
|
146
|
+
X = X.reshape(-1, 1)
|
|
147
|
+
self.X_train = X
|
|
148
|
+
self.y_train = np.asarray(y, dtype=float)
|
|
149
|
+
return self
|
|
150
|
+
|
|
151
|
+
def predict(self, X):
|
|
152
|
+
X = np.asarray(X, dtype=float)
|
|
153
|
+
if X.ndim == 1:
|
|
154
|
+
X = X.reshape(-1, 1)
|
|
155
|
+
preds = []
|
|
156
|
+
for x in X:
|
|
157
|
+
dists = np.linalg.norm(self.X_train - x, axis=1)
|
|
158
|
+
idx = np.argsort(dists)[: self.k]
|
|
159
|
+
preds.append(np.mean(self.y_train[idx]))
|
|
160
|
+
return np.array(preds)
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
class PCA:
|
|
164
|
+
"""Principal Component Analysis using SVD."""
|
|
165
|
+
|
|
166
|
+
def __init__(self, n_components: Optional[int] = None):
|
|
167
|
+
self.n_components = n_components
|
|
168
|
+
self.components_ = None
|
|
169
|
+
self.mean_ = None
|
|
170
|
+
|
|
171
|
+
def fit(self, X):
|
|
172
|
+
X = np.asarray(X, dtype=float)
|
|
173
|
+
self.mean_ = np.mean(X, axis=0)
|
|
174
|
+
Xc = X - self.mean_
|
|
175
|
+
U, S, Vt = np.linalg.svd(Xc, full_matrices=False)
|
|
176
|
+
if self.n_components is None:
|
|
177
|
+
self.n_components = Vt.shape[0]
|
|
178
|
+
self.components_ = Vt[: self.n_components]
|
|
179
|
+
return self
|
|
180
|
+
|
|
181
|
+
def transform(self, X):
|
|
182
|
+
X = np.asarray(X, dtype=float)
|
|
183
|
+
return (X - self.mean_).dot(self.components_.T)
|
|
184
|
+
|
|
185
|
+
def fit_transform(self, X):
|
|
186
|
+
self.fit(X)
|
|
187
|
+
return self.transform(X)
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: avish_lib
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Lightweight custom ML algorithms library (avish_lib)
|
|
5
|
+
Home-page: https://github.com/yourusername/avish_lib
|
|
6
|
+
Author: Avish
|
|
7
|
+
Project-URL: Homepage, https://github.com/yourusername/avish_lib
|
|
8
|
+
Project-URL: Repository, https://github.com/yourusername/avish_lib
|
|
9
|
+
Project-URL: Documentation, https://github.com/yourusername/avish_lib#readme
|
|
10
|
+
Keywords: machine learning,regression,pca,numpy,ml
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Requires-Python: >=3.8
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: numpy>=1.21
|
|
23
|
+
Dynamic: home-page
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
Dynamic: requires-python
|
|
26
|
+
|
|
27
|
+
# avish_lib
|
|
28
|
+
|
|
29
|
+
avish_lib is a small collection of custom machine-learning algorithms implemented with minimal dependencies (NumPy).
|
|
30
|
+
|
|
31
|
+
Install for local development:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
python -m pip install -e .
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Quick usage:
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
from avish_lib import LinearRegression, RidgeRegression, KNNRegressor, PCA
|
|
41
|
+
|
|
42
|
+
# Simple linear fit
|
|
43
|
+
X = [[1], [2], [3], [4]]
|
|
44
|
+
y = [2, 4, 6, 8]
|
|
45
|
+
model = LinearRegression()
|
|
46
|
+
model.fit(X, y)
|
|
47
|
+
print("coef:", model.coef_, "intercept:", model.intercept_)
|
|
48
|
+
|
|
49
|
+
# PCA example
|
|
50
|
+
p = PCA(n_components=1)
|
|
51
|
+
X_reduced = p.fit_transform([[1,2],[3,4],[5,6]])
|
|
52
|
+
print(X_reduced)
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Project layout:
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
your_project_name/
|
|
59
|
+
├── src/
|
|
60
|
+
│ └── avish_lib/
|
|
61
|
+
│ ├── __init__.py
|
|
62
|
+
│ └── linear_models.py
|
|
63
|
+
├── tests/
|
|
64
|
+
├── pyproject.toml
|
|
65
|
+
├── README.md
|
|
66
|
+
└── LICENSE
|
|
67
|
+
```
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
setup.py
|
|
5
|
+
src/avish_lib/__init__.py
|
|
6
|
+
src/avish_lib/linear_models.py
|
|
7
|
+
src/avish_lib.egg-info/PKG-INFO
|
|
8
|
+
src/avish_lib.egg-info/SOURCES.txt
|
|
9
|
+
src/avish_lib.egg-info/dependency_links.txt
|
|
10
|
+
src/avish_lib.egg-info/requires.txt
|
|
11
|
+
src/avish_lib.egg-info/top_level.txt
|
|
12
|
+
tests/test_basic.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
numpy>=1.21
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
avish_lib
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import math
|
|
2
|
+
from avish_lib import LinearRegression
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def test_linear_regression_simple():
|
|
6
|
+
X = [[1], [2], [3], [4]]
|
|
7
|
+
y = [2, 4, 6, 8]
|
|
8
|
+
model = LinearRegression()
|
|
9
|
+
model.fit(X, y)
|
|
10
|
+
preds = model.predict(X)
|
|
11
|
+
# Expect near perfect fit: slope ~2, intercept ~0
|
|
12
|
+
assert math.isclose(model.coef_[0], 2.0, rel_tol=1e-6)
|
|
13
|
+
assert math.isclose(model.intercept_, 0.0, abs_tol=1e-6)
|
|
14
|
+
for p, t in zip(preds, y):
|
|
15
|
+
assert math.isclose(p, t, rel_tol=1e-6)
|