easy_model
A tiny, dependency-free, sklearn-style neural network classifier in pure Python,
backed by the fast C++ engine neuralnetwork-cpp,
plus pandas-like CSV reading, train_test_split, and six bundled classic datasets.
from easy_model import NeuralNetworkCPPClassifier, train_test_split, load_iris
Features
- NeuralNetworkCPPClassifier - a scikit-learn compatible classifier
(
fit/predict/predict_proba/score,get_params/set_params). - read_csv - read CSV files (including
.gz) with pandas-like behavior. - train_test_split - split data into train/test, with shuffle, random seeding, and stratification, just like sklearn.
- Bundled datasets - iris, wine, breast cancer, diabetes, digits, and
linnerud, loaded the sklearn way with
return_X_ysupport. - No pandas or numpy required - everything is plain Python lists.
Installation
Install from PyPI (this pulls in the only dependency automatically):
pip install nn-easy-model
Or clone the repository and run it directly:
git clone https://github.com/Mohamedboukerche22/easy_model.git
cd easy_model
pip install . # optional: install the package
python main.py # runs the demos
Quickstart
from easy_model import NeuralNetworkCPPClassifier, train_test_split, load_iris
# 1. Load a dataset
X, y = load_iris(return_X_y=True)
# 2. Split into train / test
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.3, random_state=42, stratify=y,
)
# 3. Train
clf = NeuralNetworkCPPClassifier(
hidden_layer_sizes=(16, 8),
learning_rate=0.01,
max_iter=200,
batch_size=8,
random_state=42,
)
clf.fit(X_train, y_train)
# 4. Evaluate and predict
print('train accuracy:', clf.score(X_train, y_train))
print('test accuracy:', clf.score(X_test, y_test))
print('predicted:', clf.predict(X_test[:3]))
API
NeuralNetworkCPPClassifier
Main parameters:
| Parameter | Description |
|---|---|
hidden_layer_sizes |
tuple of hidden layer sizes, e.g. (128, 64) |
activation |
'relu', 'tanh', 'sigmoid', 'leaky_relu', 'linear' |
learning_rate |
optimizer learning rate |
max_iter |
number of training epochs |
batch_size |
mini-batch size |
optimizer |
'adam', 'sgd', 'momentum' |
loss |
'cross_entropy', 'binary_cross_entropy', 'mse' |
shuffle |
shuffle samples each epoch (bool) |
random_state |
seed for reproducibility |
verbose |
1 to print training loss per epoch |
Methods: fit(X, y), predict(X), predict_proba(X), score(X, y),
get_params(), set_params(**params).
Fitted attributes: classes_, n_features_in_, n_classes_, loss_curve_,
history_, fit_time_seconds_.
read_csv
from easy_model import read_csv, DATA_DIR
header, rows = read_csv(f'{DATA_DIR}/iris.csv')
# header -> [150, 4, 'setosa', 'versicolor', 'virginica']
# rows -> [[5.1, 3.5, 1.4, 0.2, 0], ...]
read_csv(path, sep=',', header=0) auto-decompresses .gz files, converts
numeric cells to int/float, and keeps strings as strings. Pass
header=None to treat every line as data.
train_test_split
X_train, X_test, y_train, y_test = train_test_split(
X, y,
test_size=0.3, # fraction, or an int number of samples
train_size=None, # mutually exclusive with test_size
random_state=42, # reproducibility
shuffle=True,
stratify=y, # keep class proportions in both splits
)
Bundled datasets
| Loader | Samples | Features | Target |
|---|---|---|---|
load_iris() |
150 | 4 | 3-class species |
load_wine() |
178 | 13 | 3-class wine cultivar |
load_breast_cancer() |
569 | 30 | binary (malignant/benign) |
load_diabetes() |
442 | 10 | regression target |
load_digits() |
1797 | 64 | 10-class digits (0-9) |
load_linnerud() |
20 | 3 | multi-output exercise counts |
Each loader returns a Bunch (sklearn-style attributes) or, with
return_X_y=True, a (X, y) tuple:
bunch = load_wine()
bunch.data, bunch.target, bunch.target_names, bunch.feature_names
X, y = load_wine(return_X_y=True)
Full example
from easy_model import NeuralNetworkCPPClassifier, train_test_split, load_digits
X, y = load_digits(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.25, random_state=0, stratify=y,
)
clf = NeuralNetworkCPPClassifier(
hidden_layer_sizes=(128, 64), learning_rate=0.003,
max_iter=10, batch_size=64, random_state=123,
)
clf.fit(X_train, y_train)
print('accuracy:', clf.score(X_test, y_test))
Requirements
- Python 3.8+
neuralnetwork-cpp(the C++ backend; the only dependency)
License
MIT
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nn_easy_model-0.1.2.tar.gz.
File metadata
- Download URL: nn_easy_model-0.1.2.tar.gz
- Upload date:
- Size: 136.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f2330ce29f3a3be69ede68ac39c7377dba16c380dd7727cf311c5fff153e2b3
|
|
| MD5 |
10acf65f33d377c96c8bb2041af266b0
|
|
| BLAKE2b-256 |
c9ddc4099dd67fe4e1d9808aedb447f996277e3206ffccd72ad40881fa2ce8ee
|
File details
Details for the file nn_easy_model-0.1.2-py3-none-any.whl.
File metadata
- Download URL: nn_easy_model-0.1.2-py3-none-any.whl
- Upload date:
- Size: 133.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
012c429e2a0af322deaabdfaecfd4761e0a6e3dd3516f6f65958ab441b5fda22
|
|
| MD5 |
56c9e4f540695d9308af74fa22b8a6c1
|
|
| BLAKE2b-256 |
cc4261d7b9072512658251c1dc1b9dedf4e13292fc222fbf7a21c46fb871955c
|