simpmnct 0.1.3__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.
- simpmnct-0.1.3/PKG-INFO +83 -0
- simpmnct-0.1.3/README.md +66 -0
- simpmnct-0.1.3/pyproject.toml +34 -0
- simpmnct-0.1.3/setup.cfg +4 -0
- simpmnct-0.1.3/setup.py +10 -0
- simpmnct-0.1.3/simpmnct/__init__.py +0 -0
- simpmnct-0.1.3/simpmnct/dataset/__init__.py +0 -0
- simpmnct-0.1.3/simpmnct/dataset/loader.py +35 -0
- simpmnct-0.1.3/simpmnct/models/__init__.py +2 -0
- simpmnct-0.1.3/simpmnct/models/base_model.py +21 -0
- simpmnct-0.1.3/simpmnct/models/linear.py +35 -0
- simpmnct-0.1.3/simpmnct/models/logistic.py +33 -0
- simpmnct-0.1.3/simpmnct/utils/__init__.py +0 -0
- simpmnct-0.1.3/simpmnct/utils/metrics.py +17 -0
- simpmnct-0.1.3/simpmnct/utils/normalize.py +8 -0
- simpmnct-0.1.3/simpmnct/utils/train_test_split.py +14 -0
- simpmnct-0.1.3/simpmnct.egg-info/PKG-INFO +83 -0
- simpmnct-0.1.3/simpmnct.egg-info/SOURCES.txt +19 -0
- simpmnct-0.1.3/simpmnct.egg-info/dependency_links.txt +1 -0
- simpmnct-0.1.3/simpmnct.egg-info/requires.txt +6 -0
- simpmnct-0.1.3/simpmnct.egg-info/top_level.txt +1 -0
simpmnct-0.1.3/PKG-INFO
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: simpmnct
|
|
3
|
+
Version: 0.1.3
|
|
4
|
+
Summary: Simple Machine Learning library from scratch using NumPy
|
|
5
|
+
Author: Nguyễn Chính Thanh
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/thanhtaysimplo/simpmnct
|
|
8
|
+
Project-URL: Bug Tracker, https://github.com/thanhtaysimplo/simpmnct/issues
|
|
9
|
+
Project-URL: Source Code, https://github.com/thanhtaysimplo/simpmnct
|
|
10
|
+
Requires-Python: >=3.9
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
Requires-Dist: numpy
|
|
13
|
+
Provides-Extra: vision
|
|
14
|
+
Requires-Dist: torch; extra == "vision"
|
|
15
|
+
Requires-Dist: torchvision; extra == "vision"
|
|
16
|
+
Requires-Dist: Pillow; extra == "vision"
|
|
17
|
+
|
|
18
|
+
simpmnct
|
|
19
|
+
đây là thư viện cho người mới học Machine learning , chạy hết đá số các trường hợp , có hàm có sẵn nhiều bạn sẽ phải tự xử lí bằng tay và gần như nó giúp bạn hiểu hơn về ML thay vì cứ họi hàm sẵn có.
|
|
20
|
+
dựa trên nền tẳng numpy , pickle , torch , torchvision , pillow
|
|
21
|
+
|
|
22
|
+
This is a library for beginners in Machine Learning. It runs through most cases, has built-in functions, and many users will have to handle manually. It helps you understand ML better than just relying on ready-made functions.
|
|
23
|
+
It's based on NumPy, Pickle, Torch, TorchVision, and Pillow.
|
|
24
|
+
|
|
25
|
+
Thư viện hỗ trợ:
|
|
26
|
+
Linear Regression
|
|
27
|
+
Logistic Regression
|
|
28
|
+
Train/Test Split
|
|
29
|
+
Normalize dữ liệu (data)
|
|
30
|
+
Metrics cơ bản
|
|
31
|
+
Save/Load model (.best)
|
|
32
|
+
|
|
33
|
+
Example 1 — Linear Regression
|
|
34
|
+
import numpy as np
|
|
35
|
+
from simpmnct.models.liner import Linear
|
|
36
|
+
from simpmnct.utils.train_test_split import train_test_split
|
|
37
|
+
X = np.random.rand(100,1)
|
|
38
|
+
y = 3*X + 2
|
|
39
|
+
X_train,X_test,y_train,y_test = train_test_split(X,y)
|
|
40
|
+
model = Linear(lr=0.01,epochs=1000)
|
|
41
|
+
model.fit(X_train,y_train)
|
|
42
|
+
pred = model.predict(X_test)
|
|
43
|
+
print(pred[:5])
|
|
44
|
+
|
|
45
|
+
Example 2 — Logistic Regression
|
|
46
|
+
import numpy as np
|
|
47
|
+
from simpmnct.models.logictic import Logistic
|
|
48
|
+
X = np.random.rand(100,2)
|
|
49
|
+
y = (X[:,0] + X[:,1] > 1).astype(int)
|
|
50
|
+
model = Logistic(lr=0.1,epochs=1000)
|
|
51
|
+
model.fit(X,y)
|
|
52
|
+
print(model.predict(X[:5]))
|
|
53
|
+
|
|
54
|
+
Train Test Split
|
|
55
|
+
from simpmnct.utils.train_test_split import train_test_split
|
|
56
|
+
X_train,X_test,y_train,y_test = train_test_split(X,y)
|
|
57
|
+
Normalize
|
|
58
|
+
from simpmnct.utils.normalize import normalize
|
|
59
|
+
X_norm = normalize(X)
|
|
60
|
+
|
|
61
|
+
Metrics
|
|
62
|
+
from simpmnct.metrics.metrics import accuracy
|
|
63
|
+
from simpmnct.metrics.metrics import mse
|
|
64
|
+
|
|
65
|
+
Save Model
|
|
66
|
+
model.save("model.best")
|
|
67
|
+
File .best sẽ chứa toàn bộ model đã train.
|
|
68
|
+
|
|
69
|
+
Load Model
|
|
70
|
+
from simpmnct.models.liner import Linear
|
|
71
|
+
model = Linear.load("model.best")
|
|
72
|
+
|
|
73
|
+
Dataset Loader (Depth Estimation)
|
|
74
|
+
from simpmnct.dataset.depth_dataset import DepthDataset
|
|
75
|
+
dataset = DepthDataset(img_dir="images",depth_dir="depth")
|
|
76
|
+
img,depth = dataset[0]
|
|
77
|
+
Output:
|
|
78
|
+
image -> Tensor (3,H,W)
|
|
79
|
+
depth -> Tensor (1,H,W)
|
|
80
|
+
|
|
81
|
+
lưu ý : model này là do thằng sinh viên năm 2 viết ko dùng cho dự án lớn hay dẫn đường tên lửa , có thể sai số hoặc nhiều bug tiềm ẩn , chỉ sử dụng để học hoặc làm dự án nhỏ
|
|
82
|
+
|
|
83
|
+
Please note: this model was written by a second-year student and is not intended for large projects or missile guidance. It may contain errors or potential bugs; it is only for learning or small projects.
|
simpmnct-0.1.3/README.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
simpmnct
|
|
2
|
+
đây là thư viện cho người mới học Machine learning , chạy hết đá số các trường hợp , có hàm có sẵn nhiều bạn sẽ phải tự xử lí bằng tay và gần như nó giúp bạn hiểu hơn về ML thay vì cứ họi hàm sẵn có.
|
|
3
|
+
dựa trên nền tẳng numpy , pickle , torch , torchvision , pillow
|
|
4
|
+
|
|
5
|
+
This is a library for beginners in Machine Learning. It runs through most cases, has built-in functions, and many users will have to handle manually. It helps you understand ML better than just relying on ready-made functions.
|
|
6
|
+
It's based on NumPy, Pickle, Torch, TorchVision, and Pillow.
|
|
7
|
+
|
|
8
|
+
Thư viện hỗ trợ:
|
|
9
|
+
Linear Regression
|
|
10
|
+
Logistic Regression
|
|
11
|
+
Train/Test Split
|
|
12
|
+
Normalize dữ liệu (data)
|
|
13
|
+
Metrics cơ bản
|
|
14
|
+
Save/Load model (.best)
|
|
15
|
+
|
|
16
|
+
Example 1 — Linear Regression
|
|
17
|
+
import numpy as np
|
|
18
|
+
from simpmnct.models.liner import Linear
|
|
19
|
+
from simpmnct.utils.train_test_split import train_test_split
|
|
20
|
+
X = np.random.rand(100,1)
|
|
21
|
+
y = 3*X + 2
|
|
22
|
+
X_train,X_test,y_train,y_test = train_test_split(X,y)
|
|
23
|
+
model = Linear(lr=0.01,epochs=1000)
|
|
24
|
+
model.fit(X_train,y_train)
|
|
25
|
+
pred = model.predict(X_test)
|
|
26
|
+
print(pred[:5])
|
|
27
|
+
|
|
28
|
+
Example 2 — Logistic Regression
|
|
29
|
+
import numpy as np
|
|
30
|
+
from simpmnct.models.logictic import Logistic
|
|
31
|
+
X = np.random.rand(100,2)
|
|
32
|
+
y = (X[:,0] + X[:,1] > 1).astype(int)
|
|
33
|
+
model = Logistic(lr=0.1,epochs=1000)
|
|
34
|
+
model.fit(X,y)
|
|
35
|
+
print(model.predict(X[:5]))
|
|
36
|
+
|
|
37
|
+
Train Test Split
|
|
38
|
+
from simpmnct.utils.train_test_split import train_test_split
|
|
39
|
+
X_train,X_test,y_train,y_test = train_test_split(X,y)
|
|
40
|
+
Normalize
|
|
41
|
+
from simpmnct.utils.normalize import normalize
|
|
42
|
+
X_norm = normalize(X)
|
|
43
|
+
|
|
44
|
+
Metrics
|
|
45
|
+
from simpmnct.metrics.metrics import accuracy
|
|
46
|
+
from simpmnct.metrics.metrics import mse
|
|
47
|
+
|
|
48
|
+
Save Model
|
|
49
|
+
model.save("model.best")
|
|
50
|
+
File .best sẽ chứa toàn bộ model đã train.
|
|
51
|
+
|
|
52
|
+
Load Model
|
|
53
|
+
from simpmnct.models.liner import Linear
|
|
54
|
+
model = Linear.load("model.best")
|
|
55
|
+
|
|
56
|
+
Dataset Loader (Depth Estimation)
|
|
57
|
+
from simpmnct.dataset.depth_dataset import DepthDataset
|
|
58
|
+
dataset = DepthDataset(img_dir="images",depth_dir="depth")
|
|
59
|
+
img,depth = dataset[0]
|
|
60
|
+
Output:
|
|
61
|
+
image -> Tensor (3,H,W)
|
|
62
|
+
depth -> Tensor (1,H,W)
|
|
63
|
+
|
|
64
|
+
lưu ý : model này là do thằng sinh viên năm 2 viết ko dùng cho dự án lớn hay dẫn đường tên lửa , có thể sai số hoặc nhiều bug tiềm ẩn , chỉ sử dụng để học hoặc làm dự án nhỏ
|
|
65
|
+
|
|
66
|
+
Please note: this model was written by a second-year student and is not intended for large projects or missile guidance. It may contain errors or potential bugs; it is only for learning or small projects.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "simpmnct"
|
|
7
|
+
version = "0.1.3"
|
|
8
|
+
description = "Simple Machine Learning library from scratch using NumPy"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = {text = "MIT"}
|
|
11
|
+
authors = [
|
|
12
|
+
{name = "Nguyễn Chính Thanh"}
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
requires-python = ">=3.9"
|
|
16
|
+
|
|
17
|
+
dependencies = [
|
|
18
|
+
"numpy"
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
[project.optional-dependencies]
|
|
22
|
+
vision = [
|
|
23
|
+
"torch",
|
|
24
|
+
"torchvision",
|
|
25
|
+
"Pillow"
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
[project.urls]
|
|
29
|
+
"Homepage" = "https://github.com/thanhtaysimplo/simpmnct"
|
|
30
|
+
"Bug Tracker" = "https://github.com/thanhtaysimplo/simpmnct/issues"
|
|
31
|
+
"Source Code" = "https://github.com/thanhtaysimplo/simpmnct"
|
|
32
|
+
|
|
33
|
+
[tool.setuptools.packages.find]
|
|
34
|
+
include = ["simpmnct*"]
|
simpmnct-0.1.3/setup.cfg
ADDED
simpmnct-0.1.3/setup.py
ADDED
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import torch
|
|
3
|
+
import numpy as np
|
|
4
|
+
from torch.utils.data import Dataset
|
|
5
|
+
from PIL import Image
|
|
6
|
+
import torchvision.transforms.functional as TF
|
|
7
|
+
import random
|
|
8
|
+
class DepthDataset(Dataset):
|
|
9
|
+
def __init__(self, img_dir, depth_dir, transform=None):
|
|
10
|
+
self.img_dir = img_dir
|
|
11
|
+
self.depth_dir = depth_dir
|
|
12
|
+
self.transform = transform
|
|
13
|
+
self.images = sorted([f for f in os.listdir(img_dir) if not f.startswith('.')])
|
|
14
|
+
self.depths = sorted([f for f in os.listdir(depth_dir) if not f.startswith('.')])
|
|
15
|
+
assert len(self.images) == len(self.depths), "images == depths ( sổ ảnh phải bằng depths)"
|
|
16
|
+
|
|
17
|
+
def __len__(self):
|
|
18
|
+
return len(self.images)
|
|
19
|
+
|
|
20
|
+
def __getitem__(self, index):
|
|
21
|
+
img_path = os.path.join(self.img_dir, self.images[index])
|
|
22
|
+
depth_path = os.path.join(self.depth_dir, self.depths[index])
|
|
23
|
+
image = Image.open(img_path).convert('RGB')
|
|
24
|
+
depth = Image.open(depth_path)
|
|
25
|
+
if self.transform:
|
|
26
|
+
image = TF.resize(image, (256, 256))
|
|
27
|
+
depth = TF.resize(depth, (256, 256), interpolation=TF.InterpolationMode.NEAREST)
|
|
28
|
+
if random.random() > 0.5:
|
|
29
|
+
image = TF.hflip(image)
|
|
30
|
+
depth = TF.hflip(depth)
|
|
31
|
+
image = TF.to_tensor(image)
|
|
32
|
+
depth = np.array(depth).astype(np.float32)
|
|
33
|
+
depth = torch.from_numpy(depth).unsqueeze(0)
|
|
34
|
+
|
|
35
|
+
return image, depth
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import pickle
|
|
3
|
+
class BaseModel:
|
|
4
|
+
def fit(self, X, y):
|
|
5
|
+
pass
|
|
6
|
+
|
|
7
|
+
def predict(self, X):
|
|
8
|
+
pass
|
|
9
|
+
|
|
10
|
+
def score(self,X,y):
|
|
11
|
+
y_pred = self.predict(X)
|
|
12
|
+
return np.mean(y_pred == y)
|
|
13
|
+
|
|
14
|
+
def save(self, path="model.best"):
|
|
15
|
+
with open(path, "wb") as f:
|
|
16
|
+
pickle.dump(self, f)
|
|
17
|
+
|
|
18
|
+
@staticmethod
|
|
19
|
+
def load(path="model.best"):
|
|
20
|
+
with open(path, "rb") as f:
|
|
21
|
+
return pickle.load(f)
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
from .base_model import BaseModel
|
|
3
|
+
class Linear(BaseModel):
|
|
4
|
+
|
|
5
|
+
def __init__(self,lr=0.01,epochs=1000):
|
|
6
|
+
self.lr=lr
|
|
7
|
+
self.epochs=epochs
|
|
8
|
+
self.weight = None
|
|
9
|
+
self.bias = None
|
|
10
|
+
|
|
11
|
+
def fit(self,X,y):
|
|
12
|
+
n_sample,n_feature=X.shape
|
|
13
|
+
|
|
14
|
+
self.weight = np.zeros(n_feature)
|
|
15
|
+
self.bias = 0
|
|
16
|
+
|
|
17
|
+
for i in range(self.epochs):
|
|
18
|
+
y_pred = X.dot(self.weight) + self.bias
|
|
19
|
+
|
|
20
|
+
loss = (1/n_sample) * np.sum((y-y_pred)**2)
|
|
21
|
+
|
|
22
|
+
dw = (2/n_sample) * X.T @ (y_pred-y)
|
|
23
|
+
gd = (2/n_sample) * np.sum(y_pred - y)
|
|
24
|
+
|
|
25
|
+
self.weight = self.weight - self.lr * dw
|
|
26
|
+
self.bias = self.bias - self.lr * gd
|
|
27
|
+
|
|
28
|
+
def predict(self,X):
|
|
29
|
+
return X.dot(self.weight)+self.bias
|
|
30
|
+
def score(self, X, y):
|
|
31
|
+
y_pred = self.predict(X)
|
|
32
|
+
ss_res = np.sum((y - y_pred)**2)
|
|
33
|
+
ss_tot = np.sum((y - np.mean(y))**2)
|
|
34
|
+
return 1 - (ss_res / (ss_tot + 1e-8))
|
|
35
|
+
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
from .base_model import BaseModel
|
|
2
|
+
import numpy as np
|
|
3
|
+
|
|
4
|
+
class logistic(BaseModel):
|
|
5
|
+
|
|
6
|
+
def __init__(self,lr=0.01,epochs=1000):
|
|
7
|
+
self.lr=lr
|
|
8
|
+
self.epochs=epochs
|
|
9
|
+
|
|
10
|
+
def sigmoid(self,z):
|
|
11
|
+
return 1/(1+np.exp(-z))
|
|
12
|
+
|
|
13
|
+
def fit(self,X,y):
|
|
14
|
+
n_sample , n_feature = X.shape
|
|
15
|
+
self.weight = np.zeros(n_feature)
|
|
16
|
+
self.bias=0
|
|
17
|
+
|
|
18
|
+
for i in range(self.epochs):
|
|
19
|
+
y_pred = 1 / (1 + np.exp(-(X.dot(self.weight) + self.bias)))
|
|
20
|
+
|
|
21
|
+
loss = (-1/n_sample) * np.sum(y*np.log(y_pred)+(1-y)*np.log(1-y_pred))
|
|
22
|
+
|
|
23
|
+
dw = (1/n_sample)* X.T @ (y_pred-y)
|
|
24
|
+
gd = (1/n_sample) * np.sum(y_pred-y)
|
|
25
|
+
|
|
26
|
+
self.weight-= self.lr * dw
|
|
27
|
+
self.bias-= self.lr * gd
|
|
28
|
+
|
|
29
|
+
def predict(self,X):
|
|
30
|
+
z = X.dot(self.weight) + self.bias
|
|
31
|
+
y_pred = self.sigmoid(z)
|
|
32
|
+
return (y_pred > 0.5).astype(int)
|
|
33
|
+
|
|
File without changes
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def mse(y_true, y_pred):
|
|
7
|
+
return np.mean((y_true - y_pred)**2)
|
|
8
|
+
|
|
9
|
+
def mae(y_true, y_pred):
|
|
10
|
+
return np.mean(np.abs(y_true - y_pred))
|
|
11
|
+
|
|
12
|
+
def rmse(y_true, y_pred):
|
|
13
|
+
return np.sqrt(mse(y_true, y_pred))
|
|
14
|
+
|
|
15
|
+
def accuracy(y_true, y_pred):
|
|
16
|
+
y_pred = (y_pred > 0.5).astype(int)
|
|
17
|
+
return np.mean(y_true == y_pred)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
|
|
3
|
+
def train_test_split(X,y,test_size=0.2):
|
|
4
|
+
n_sample = X.shape[0]
|
|
5
|
+
indices = np.arange(n_sample)
|
|
6
|
+
np.random.shuffle(indices)
|
|
7
|
+
n_test = int(n_sample*test_size)
|
|
8
|
+
test_index = indices[:n_test]
|
|
9
|
+
train_index = indices[n_test:]
|
|
10
|
+
X_train = X[train_index]
|
|
11
|
+
X_test = X[test_index]
|
|
12
|
+
y_train = y[train_index]
|
|
13
|
+
y_test = y[test_index]
|
|
14
|
+
return X_train, X_test, y_train, y_test
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: simpmnct
|
|
3
|
+
Version: 0.1.3
|
|
4
|
+
Summary: Simple Machine Learning library from scratch using NumPy
|
|
5
|
+
Author: Nguyễn Chính Thanh
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/thanhtaysimplo/simpmnct
|
|
8
|
+
Project-URL: Bug Tracker, https://github.com/thanhtaysimplo/simpmnct/issues
|
|
9
|
+
Project-URL: Source Code, https://github.com/thanhtaysimplo/simpmnct
|
|
10
|
+
Requires-Python: >=3.9
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
Requires-Dist: numpy
|
|
13
|
+
Provides-Extra: vision
|
|
14
|
+
Requires-Dist: torch; extra == "vision"
|
|
15
|
+
Requires-Dist: torchvision; extra == "vision"
|
|
16
|
+
Requires-Dist: Pillow; extra == "vision"
|
|
17
|
+
|
|
18
|
+
simpmnct
|
|
19
|
+
đây là thư viện cho người mới học Machine learning , chạy hết đá số các trường hợp , có hàm có sẵn nhiều bạn sẽ phải tự xử lí bằng tay và gần như nó giúp bạn hiểu hơn về ML thay vì cứ họi hàm sẵn có.
|
|
20
|
+
dựa trên nền tẳng numpy , pickle , torch , torchvision , pillow
|
|
21
|
+
|
|
22
|
+
This is a library for beginners in Machine Learning. It runs through most cases, has built-in functions, and many users will have to handle manually. It helps you understand ML better than just relying on ready-made functions.
|
|
23
|
+
It's based on NumPy, Pickle, Torch, TorchVision, and Pillow.
|
|
24
|
+
|
|
25
|
+
Thư viện hỗ trợ:
|
|
26
|
+
Linear Regression
|
|
27
|
+
Logistic Regression
|
|
28
|
+
Train/Test Split
|
|
29
|
+
Normalize dữ liệu (data)
|
|
30
|
+
Metrics cơ bản
|
|
31
|
+
Save/Load model (.best)
|
|
32
|
+
|
|
33
|
+
Example 1 — Linear Regression
|
|
34
|
+
import numpy as np
|
|
35
|
+
from simpmnct.models.liner import Linear
|
|
36
|
+
from simpmnct.utils.train_test_split import train_test_split
|
|
37
|
+
X = np.random.rand(100,1)
|
|
38
|
+
y = 3*X + 2
|
|
39
|
+
X_train,X_test,y_train,y_test = train_test_split(X,y)
|
|
40
|
+
model = Linear(lr=0.01,epochs=1000)
|
|
41
|
+
model.fit(X_train,y_train)
|
|
42
|
+
pred = model.predict(X_test)
|
|
43
|
+
print(pred[:5])
|
|
44
|
+
|
|
45
|
+
Example 2 — Logistic Regression
|
|
46
|
+
import numpy as np
|
|
47
|
+
from simpmnct.models.logictic import Logistic
|
|
48
|
+
X = np.random.rand(100,2)
|
|
49
|
+
y = (X[:,0] + X[:,1] > 1).astype(int)
|
|
50
|
+
model = Logistic(lr=0.1,epochs=1000)
|
|
51
|
+
model.fit(X,y)
|
|
52
|
+
print(model.predict(X[:5]))
|
|
53
|
+
|
|
54
|
+
Train Test Split
|
|
55
|
+
from simpmnct.utils.train_test_split import train_test_split
|
|
56
|
+
X_train,X_test,y_train,y_test = train_test_split(X,y)
|
|
57
|
+
Normalize
|
|
58
|
+
from simpmnct.utils.normalize import normalize
|
|
59
|
+
X_norm = normalize(X)
|
|
60
|
+
|
|
61
|
+
Metrics
|
|
62
|
+
from simpmnct.metrics.metrics import accuracy
|
|
63
|
+
from simpmnct.metrics.metrics import mse
|
|
64
|
+
|
|
65
|
+
Save Model
|
|
66
|
+
model.save("model.best")
|
|
67
|
+
File .best sẽ chứa toàn bộ model đã train.
|
|
68
|
+
|
|
69
|
+
Load Model
|
|
70
|
+
from simpmnct.models.liner import Linear
|
|
71
|
+
model = Linear.load("model.best")
|
|
72
|
+
|
|
73
|
+
Dataset Loader (Depth Estimation)
|
|
74
|
+
from simpmnct.dataset.depth_dataset import DepthDataset
|
|
75
|
+
dataset = DepthDataset(img_dir="images",depth_dir="depth")
|
|
76
|
+
img,depth = dataset[0]
|
|
77
|
+
Output:
|
|
78
|
+
image -> Tensor (3,H,W)
|
|
79
|
+
depth -> Tensor (1,H,W)
|
|
80
|
+
|
|
81
|
+
lưu ý : model này là do thằng sinh viên năm 2 viết ko dùng cho dự án lớn hay dẫn đường tên lửa , có thể sai số hoặc nhiều bug tiềm ẩn , chỉ sử dụng để học hoặc làm dự án nhỏ
|
|
82
|
+
|
|
83
|
+
Please note: this model was written by a second-year student and is not intended for large projects or missile guidance. It may contain errors or potential bugs; it is only for learning or small projects.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
setup.py
|
|
4
|
+
simpmnct/__init__.py
|
|
5
|
+
simpmnct.egg-info/PKG-INFO
|
|
6
|
+
simpmnct.egg-info/SOURCES.txt
|
|
7
|
+
simpmnct.egg-info/dependency_links.txt
|
|
8
|
+
simpmnct.egg-info/requires.txt
|
|
9
|
+
simpmnct.egg-info/top_level.txt
|
|
10
|
+
simpmnct/dataset/__init__.py
|
|
11
|
+
simpmnct/dataset/loader.py
|
|
12
|
+
simpmnct/models/__init__.py
|
|
13
|
+
simpmnct/models/base_model.py
|
|
14
|
+
simpmnct/models/linear.py
|
|
15
|
+
simpmnct/models/logistic.py
|
|
16
|
+
simpmnct/utils/__init__.py
|
|
17
|
+
simpmnct/utils/metrics.py
|
|
18
|
+
simpmnct/utils/normalize.py
|
|
19
|
+
simpmnct/utils/train_test_split.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
simpmnct
|