utelearn 0.1.2026__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.
- utelearn-0.1.2026/PKG-INFO +9 -0
- utelearn-0.1.2026/pyproject.toml +17 -0
- utelearn-0.1.2026/setup.cfg +4 -0
- utelearn-0.1.2026/utelearn/__init__.py +1 -0
- utelearn-0.1.2026/utelearn/kmeans.py +47 -0
- utelearn-0.1.2026/utelearn.egg-info/PKG-INFO +9 -0
- utelearn-0.1.2026/utelearn.egg-info/SOURCES.txt +8 -0
- utelearn-0.1.2026/utelearn.egg-info/dependency_links.txt +1 -0
- utelearn-0.1.2026/utelearn.egg-info/requires.txt +2 -0
- utelearn-0.1.2026/utelearn.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: utelearn
|
|
3
|
+
Version: 0.1.2026
|
|
4
|
+
Summary: A custom machine learning library built from scratch from UTE Vietnam.
|
|
5
|
+
Author-email: Dung Cai <dung.cai@hcmute.edu.vn>
|
|
6
|
+
Requires-Python: >=3.7
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Requires-Dist: numpy
|
|
9
|
+
Requires-Dist: matplotlib
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "utelearn"
|
|
7
|
+
version = "0.1.2026"
|
|
8
|
+
description = "A custom machine learning library built from scratch from UTE Vietnam."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.7"
|
|
11
|
+
dependencies = [
|
|
12
|
+
"numpy",
|
|
13
|
+
"matplotlib"
|
|
14
|
+
]
|
|
15
|
+
authors = [
|
|
16
|
+
{ name = "Dung Cai", email = "dung.cai@hcmute.edu.vn" }
|
|
17
|
+
]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .kmeans import KMeans
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Kmeans_Lib.py
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
import matplotlib.pyplot as plt
|
|
5
|
+
|
|
6
|
+
class KMeans:
|
|
7
|
+
def __init__(self, k, max_iters=10, tol=1e-4):
|
|
8
|
+
self.k = k
|
|
9
|
+
self.max_iters = max_iters
|
|
10
|
+
self.tol = tol
|
|
11
|
+
self.centroids = None
|
|
12
|
+
self.labels = None
|
|
13
|
+
|
|
14
|
+
def fit(self, X):
|
|
15
|
+
np.random.seed(42)
|
|
16
|
+
random_indices = np.random.permutation(X.shape[0])[:self.k]
|
|
17
|
+
self.centroids = X[random_indices]
|
|
18
|
+
|
|
19
|
+
for _ in range(self.max_iters):
|
|
20
|
+
self.labels = self._assign_clusters(X)
|
|
21
|
+
new_centroids = self._calculate_centroids(X)
|
|
22
|
+
|
|
23
|
+
if np.all(np.abs(new_centroids - self.centroids) < self.tol):
|
|
24
|
+
break
|
|
25
|
+
self.centroids = new_centroids
|
|
26
|
+
|
|
27
|
+
def predict(self, X):
|
|
28
|
+
return self._assign_clusters(X)
|
|
29
|
+
|
|
30
|
+
def _assign_clusters(self, X):
|
|
31
|
+
distances = np.linalg.norm(X[:, np.newaxis] - self.centroids, axis=2)
|
|
32
|
+
return np.argmin(distances, axis=1)
|
|
33
|
+
|
|
34
|
+
def _calculate_centroids(self, X):
|
|
35
|
+
new_centroids = []
|
|
36
|
+
for i in range(self.k):
|
|
37
|
+
cluster_points = X[self.labels == i]
|
|
38
|
+
if len(cluster_points) == 0:
|
|
39
|
+
# Handle empty cluster: keep the old centroid or reassign randomly
|
|
40
|
+
new_centroids.append(self.centroids[i])
|
|
41
|
+
else:
|
|
42
|
+
new_centroids.append(cluster_points.mean(axis=0))
|
|
43
|
+
return np.array(new_centroids)
|
|
44
|
+
|
|
45
|
+
def inertia(self, X):
|
|
46
|
+
# Calculate inertia, the sum of squared distances of samples to their closest cluster center.
|
|
47
|
+
return np.sum((X - self.centroids[self.labels]) ** 2)
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: utelearn
|
|
3
|
+
Version: 0.1.2026
|
|
4
|
+
Summary: A custom machine learning library built from scratch from UTE Vietnam.
|
|
5
|
+
Author-email: Dung Cai <dung.cai@hcmute.edu.vn>
|
|
6
|
+
Requires-Python: >=3.7
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Requires-Dist: numpy
|
|
9
|
+
Requires-Dist: matplotlib
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
utelearn
|