Skip to content

Commit 757c063

Browse files
authored
Merge pull request #68 from emlearn/logistic-regression
Add logistic regression
2 parents 3f78a9b + 74a375b commit 757c063

23 files changed

Lines changed: 1892 additions & 1 deletion

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ MODULES = emlearn_trees \
3737
emlearn_iir_q15 \
3838
emlearn_arrayutils \
3939
emlearn_linreg \
40+
emlearn_logreg \
4041
emlearn_cnn_int8 \
4142
emlearn_cnn_fp32
4243

@@ -83,7 +84,7 @@ webassembly: $(WEBASSEMBLY_MICROPYTHON)
8384

8485

8586
check_unix: $(UNIX_MICROPYTHON)
86-
$(UNIX_MICROPYTHON) tests/test_all.py test_iir,test_fft,test_arrayutils,test_linreg
87+
$(UNIX_MICROPYTHON) tests/test_all.py test_iir,test_fft,test_arrayutils,test_linreg,test_logreg
8788
# TODO: enable more modules
8889

8990
rp2: $(PORT_DIR)
@@ -105,6 +106,7 @@ clean:
105106
make -C src/emlearn_trees/ ARCH=$(ARCH) MPY_DIR=$(MPY_DIR_ABS) V=1 clean
106107
make -C src/emlearn_neighbors/ ARCH=$(ARCH) MPY_DIR=$(MPY_DIR_ABS) V=1 clean
107108
make -C src/emlearn_iir/ ARCH=$(ARCH) MPY_DIR=$(MPY_DIR_ABS) V=1 clean
109+
make -C src/emlearn_logreg/ ARCH=$(ARCH) MPY_DIR=$(MPY_DIR_ABS) V=1 clean
108110
rm -rf ./dist
109111

110112
RELEASE_NAME = emlearn-micropython-$(VERSION)
16.9 KB
Binary file not shown.
50 KB
Binary file not shown.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env python3
2+
"""Download and preprocess the Breast Cancer Wisconsin dataset."""
3+
4+
from pathlib import Path
5+
import os
6+
7+
import numpy as np
8+
from sklearn.datasets import load_breast_cancer
9+
from sklearn.model_selection import train_test_split
10+
from sklearn.preprocessing import StandardScaler
11+
12+
def main():
13+
14+
here = os.path.dirname(__file__)
15+
16+
OUTPUT_DIR = Path(here)
17+
OUTPUT_DIR.mkdir(exist_ok=True)
18+
19+
FILENAMES = {
20+
'X_train': OUTPUT_DIR / 'X_train.npy',
21+
'X_test': OUTPUT_DIR / 'X_test.npy',
22+
'y_train': OUTPUT_DIR / 'y_train.npy',
23+
'y_test': OUTPUT_DIR / 'y_test.npy',
24+
}
25+
26+
X, y = load_breast_cancer(return_X_y=True)
27+
scaler = StandardScaler()
28+
X = scaler.fit_transform(X).astype('float32')
29+
y = y.astype('float32')
30+
31+
X_train, X_test, y_train, y_test = train_test_split(
32+
X,
33+
y,
34+
test_size=0.25,
35+
random_state=42,
36+
stratify=y,
37+
)
38+
39+
np.save(FILENAMES['X_train'], X_train)
40+
np.save(FILENAMES['X_test'], X_test)
41+
np.save(FILENAMES['y_train'], y_train)
42+
np.save(FILENAMES['y_test'], y_test)
43+
44+
print('Saved datasets:')
45+
print(f" X_train: {X_train.shape} -> {FILENAMES['X_train']}")
46+
print(f" X_test : {X_test.shape} -> {FILENAMES['X_test']}")
47+
print(f" y_train: {y_train.shape} -> {FILENAMES['y_train']}")
48+
print(f" y_test : {y_test.shape} -> {FILENAMES['y_test']}")
49+
50+
51+
if __name__ == '__main__':
52+
main()
700 Bytes
Binary file not shown.
1.79 KB
Binary file not shown.

examples/datasets/wine/X_test.npy

2.41 KB
Binary file not shown.

examples/datasets/wine/X_train.npy

6.88 KB
Binary file not shown.

examples/datasets/wine/prepare.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
import os.path
3+
4+
import numpy as np
5+
from sklearn.datasets import load_wine
6+
from sklearn.model_selection import train_test_split
7+
from sklearn.preprocessing import StandardScaler
8+
9+
def main():
10+
11+
here = os.path.dirname(__file__)
12+
out_dir = here
13+
14+
wine = load_wine()
15+
X = wine.data.astype(np.float32)
16+
y = wine.target.astype(np.float32)
17+
18+
scaler = StandardScaler()
19+
X = scaler.fit_transform(X).astype(np.float32)
20+
21+
X_train, X_test, y_train, y_test = train_test_split(
22+
X, y, test_size=0.25, random_state=42, stratify=y
23+
)
24+
25+
np.save(os.path.join(out_dir, 'X_train.npy'), X_train)
26+
np.save(os.path.join(out_dir, 'X_test.npy'), X_test)
27+
np.save(os.path.join(out_dir, 'y_train.npy'), y_train)
28+
np.save(os.path.join(out_dir, 'y_test.npy'), y_test)
29+
30+
print('Wrote to', out_dir)
31+
32+
if __name__ == '__main__':
33+
main()

examples/datasets/wine/y_test.npy

308 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)