Metadata-Version: 2.4
Name: pysimpml
Version: 0.0.3
Summary: Educational Machine Learning library focusing on understanding models step-by-step
Author: Nguyễn Chín Thanh
License: MIT
Keywords: machine learning,education,numpy,from scratch,ml
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Operating System :: OS Independent
Classifier: Intended Audience :: Education
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Requires-Dist: numpy

pysimpml là thư viện dành cho người mới học Machine Learning, tập trung vào việc giúp bạn hiểu bản chất mô hình thay vì chỉ gọi hàm có sẵn.

Thư viện xử lý được hầu hết các trường hợp cơ bản trong Machine Learning, nhưng nhiều bước được giữ lại để người học tự thao tác bằng tay, giúp hiểu rõ cách mô hình hoạt động thay vì phụ thuộc hoàn toàn vào các thư viện lớn.

Thư viện được xây dựng dựa trên:
numpy — tính toán ma trận và vector
pickle — lưu model
torch / torchvision — hỗ trợ mở rộng deep learning
pillow — xử lý ảnh
csv — lưu log quá trình train (NEW)

Một điểm đặc biệt của simpmnct là khả năng in chi tiết quá trình học của mô hình, bao gồm:

Các tham số out_* có thể hiển thị:
Loss theo từng epoch (out_loss)
Gradient của mô hình (out_gradient)
Quá trình cập nhật weight và bias (out_update)
Thông tin từng epoch (out_epoch)
Công thức mô hình (out_formula)
Thống kê dữ liệu (out_stat)
Dữ liệu trước và sau xử lý (out_data)
Quá trình chia train/test (out_split)
Kích thước dữ liệu (out_shape)
Index train/test (out_index)
Giải thích quá trình dự đoán (explain=True)

Ngoài ra hỗ trợ lưu log:
Loss theo từng epoch ra file CSV (loss_csv=True)
Có thể dùng để vẽ biểu đồ hoặc debug quá trình học

Người học có thể bật hoặc tắt từng phần để quan sát cách mô hình học từng bước.

Loss qua từng epoch
Gradient (dw, db)
Cập nhật weight và bias
Công thức mô hình
Quá trình predict từng bước
Log loss ra file CSV để phân tích

pysimpml is a library for beginners in Machine Learning, focusing on helping you understand the fundamentals of the model rather than simply calling built-in functions.

The library handles most basic Machine Learning scenarios, but many steps are left to allow learners to manipulate them manually, helping them understand how the model works instead of relying entirely on large libraries.

The library is built on:
numpy — matrix and vector computation
pickle — model storage
torch / torchvision — support for deep learning extensions
pillow — image processing
csv — training log storage (New)

A unique feature of simpmnct is its ability to print detailed model learning progress, including:

The out_* parameters can display:
Loss per epoch (out_loss)
Model gradient (out_gradient)
Weight and bias update process (out_update)
Information per epoch (out_epoch)
Model formula (out_formula)
Data statistics (out_stat)
Data before and after processing (out_data)
Train/test splitting process (out_split)
Data size (out_shape)
Train/test index (out_index)
Prediction process explanation (explain=True)

Additionally supports logging:
Saving loss per epoch to CSV file (loss_csv=True)
Useful for plotting learning curves and debugging

Learners can turn each part on or off to observe how the model learns step by step.

Loss at each epoch
Gradient (dw, db)
Update weights and biases
Model formulas
Step-by-step prediction process
Export training logs to CSV for analysis

Thư viện hỗ trợ:
Linear Regression
Logistic Regression
Neural Network (Multi-Layer Perceptron) ← NEW 
Train/Test Split
Normalize dữ liệu (data)
Metrics cơ bản
Save/Load model (.best)
Export training logs (.csv) ← NEW 

Example 1 — Linear Regression

import numpy as np
from simpmnct.models.linear import Linear
from simpmnct.utils.train_test_split import train_test_split

X = np.random.rand(100,1)
y = 3*X + 2

X_train, X_test, y_train, y_test = train_test_split(X,y)

model = Linear(
    lr=0.01,
    epochs=1000,
    out_loss=True,
    out_gradient=True,
    out_update=True,
    out_epoch=True,
    loss_step=10,
    loss_csv=True   # lưu log CSV
)

model.fit(X_train,y_train)

pred = model.predict(X_test)
print(pred[:5])

Example 2 — Logistic Regression

import numpy as np
from simpmnct.models.logistic import Logistic

X = np.random.rand(100,2)
y = (X[:,0] + X[:,1] > 1).astype(int)

model = Logistic(
    lr=0.1,
    epochs=1000,
    out_loss=True,
    out_gradient=True,
    out_update=False,
    out_epoch=True,
    loss_step=10,
    loss_csv=True   # lưu log CSV
)

model.fit(X,y)

print(model.predict(X[:5]))
Train/Test Split
from simpmnct.utils.train_test_split import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X,y)
Normalize Data
from simpmnct.utils.normalize import normalize
X_norm = normalize(X)
Metrics
from simpmnct.metrics.metrics import accuracy
from simpmnct.metrics.metrics import mse

print(accuracy(y_true,y_pred))
print(mse(y_true,y_pred))
Save Model:
model.save("model.best")
Load Model
from simpmnct.models.linear import Linear
model = Linear.load("model.best")
Dataset Loader (Depth Estimation):
from simpmnct.dataset.depth_dataset import DepthDataset

dataset = DepthDataset(img_dir="images",depth_dir="depth")
img, depth = dataset[0]

Output:
image -> Tensor (3, H, W)
depth -> Tensor (1, H, W)

Example 3 — Neural Network (MLP)

import numpy as np
from simpmnct.models.neural_network import NeuralNetwork

X = np.array([[0,0],[0,1],[1,0],[1,1]])
y = np.array([0, 1, 1, 0])

model = NeuralNetwork(
    layers=[2, 16, 8, 1],
    activation="relu",
    lr=0.05,
    epochs=3000,
    task="classification",
    out_loss=True,
    out_epoch=True,
    loss_step=500,
    loss_csv=True   # lưu log CSV
)

model.fit(X, y)

print(model.predict(X, explain=True))

model.score(X, y, explain=True)

model.save("neural.best")

from simpmnct.models.neural_network import NeuralNetwork
model = NeuralNetwork.load("neural.best")

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ỏ 

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
