Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ MODULES = emlearn_trees \
emlearn_iir_q15 \
emlearn_arrayutils \
emlearn_linreg \
emlearn_logreg \
emlearn_cnn_int8 \
emlearn_cnn_fp32

Expand Down Expand Up @@ -83,7 +84,7 @@ webassembly: $(WEBASSEMBLY_MICROPYTHON)


check_unix: $(UNIX_MICROPYTHON)
$(UNIX_MICROPYTHON) tests/test_all.py test_iir,test_fft,test_arrayutils,test_linreg
$(UNIX_MICROPYTHON) tests/test_all.py test_iir,test_fft,test_arrayutils,test_linreg,test_logreg
# TODO: enable more modules

rp2: $(PORT_DIR)
Expand All @@ -105,6 +106,7 @@ clean:
make -C src/emlearn_trees/ ARCH=$(ARCH) MPY_DIR=$(MPY_DIR_ABS) V=1 clean
make -C src/emlearn_neighbors/ ARCH=$(ARCH) MPY_DIR=$(MPY_DIR_ABS) V=1 clean
make -C src/emlearn_iir/ ARCH=$(ARCH) MPY_DIR=$(MPY_DIR_ABS) V=1 clean
make -C src/emlearn_logreg/ ARCH=$(ARCH) MPY_DIR=$(MPY_DIR_ABS) V=1 clean
rm -rf ./dist

RELEASE_NAME = emlearn-micropython-$(VERSION)
Expand Down
Binary file added examples/datasets/cancer/X_test.npy
Binary file not shown.
Binary file added examples/datasets/cancer/X_train.npy
Binary file not shown.
52 changes: 52 additions & 0 deletions examples/datasets/cancer/prepare.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env python3
"""Download and preprocess the Breast Cancer Wisconsin dataset."""

from pathlib import Path
import os

import numpy as np
from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler

def main():

here = os.path.dirname(__file__)

OUTPUT_DIR = Path(here)
OUTPUT_DIR.mkdir(exist_ok=True)

FILENAMES = {
'X_train': OUTPUT_DIR / 'X_train.npy',
'X_test': OUTPUT_DIR / 'X_test.npy',
'y_train': OUTPUT_DIR / 'y_train.npy',
'y_test': OUTPUT_DIR / 'y_test.npy',
}

X, y = load_breast_cancer(return_X_y=True)
scaler = StandardScaler()
X = scaler.fit_transform(X).astype('float32')
y = y.astype('float32')

X_train, X_test, y_train, y_test = train_test_split(
X,
y,
test_size=0.25,
random_state=42,
stratify=y,
)

np.save(FILENAMES['X_train'], X_train)
np.save(FILENAMES['X_test'], X_test)
np.save(FILENAMES['y_train'], y_train)
np.save(FILENAMES['y_test'], y_test)

print('Saved datasets:')
print(f" X_train: {X_train.shape} -> {FILENAMES['X_train']}")
print(f" X_test : {X_test.shape} -> {FILENAMES['X_test']}")
print(f" y_train: {y_train.shape} -> {FILENAMES['y_train']}")
print(f" y_test : {y_test.shape} -> {FILENAMES['y_test']}")


if __name__ == '__main__':
main()
Binary file added examples/datasets/cancer/y_test.npy
Binary file not shown.
Binary file added examples/datasets/cancer/y_train.npy
Binary file not shown.
Binary file added examples/datasets/wine/X_test.npy
Binary file not shown.
Binary file added examples/datasets/wine/X_train.npy
Binary file not shown.
33 changes: 33 additions & 0 deletions examples/datasets/wine/prepare.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

import os.path

import numpy as np
from sklearn.datasets import load_wine
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler

def main():

here = os.path.dirname(__file__)
out_dir = here

wine = load_wine()
X = wine.data.astype(np.float32)
y = wine.target.astype(np.float32)

scaler = StandardScaler()
X = scaler.fit_transform(X).astype(np.float32)

X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.25, random_state=42, stratify=y
)

np.save(os.path.join(out_dir, 'X_train.npy'), X_train)
np.save(os.path.join(out_dir, 'X_test.npy'), X_test)
np.save(os.path.join(out_dir, 'y_train.npy'), y_train)
np.save(os.path.join(out_dir, 'y_test.npy'), y_test)

print('Wrote to', out_dir)

if __name__ == '__main__':
main()
Binary file added examples/datasets/wine/y_test.npy
Binary file not shown.
Binary file added examples/datasets/wine/y_train.npy
Binary file not shown.
37 changes: 37 additions & 0 deletions src/emlearn_logreg/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Location of top-level MicroPython directory
MPY_DIR ?= ../../micropython

# Architecture to build for (x86, x64, armv6m, armv7m, xtensa, xtensawin)
ARCH = x64

# The ABI version for .mpy files
MPY_ABI_VERSION := 6.3

# Location of emlearn library
EMLEARN_DIR := $(shell python3 -c "import emlearn; print(emlearn.includedir)")

# enable linking of libm etc
LINK_RUNTIME=1

DIST_DIR := ../../dist/$(ARCH)_$(MPY_ABI_VERSION)

# Name of module
MOD = emlearn_logreg

# Source files (.c or .py)
SRC = logreg.c emlearn_logreg.py

# Include to get the rules for compiling and linking the module
include $(MPY_DIR)/py/dynruntime.mk

# Releases
DIST_FILE = $(DIST_DIR)/$(MOD).mpy
$(DIST_DIR):
mkdir -p $@

$(DIST_FILE): $(MOD).mpy $(DIST_DIR)
cp $< $@

CFLAGS += -I$(EMLEARN_DIR) -Wno-unused-function

dist: $(DIST_FILE)
Loading
Loading