From 06fb753f6d8a3f0c5a4012044aed29378b13fb13 Mon Sep 17 00:00:00 2001
From: "MSI\\alber" <alberto.cavallo@synesthesia.it>
Date: Fri, 20 Oct 2023 16:49:57 +0200
Subject: [PATCH] First commit

---
 knn.py        | 16 ++++++++++++++++
 read_cifar.py | 14 ++++++++++++++
 2 files changed, 30 insertions(+)
 create mode 100644 read_cifar.py

diff --git a/knn.py b/knn.py
index e69de29..1865cae 100644
--- a/knn.py
+++ b/knn.py
@@ -0,0 +1,16 @@
+import numpy as np
+
+def distance_matrix(m1, m2):
+    if m1.shape != m2.shape:
+        raise ValueError("Dimensions must be identical")
+
+    x = (m1 - m2) ** 2
+    y = np.sum(x)
+    dist = np.sqrt(y)
+
+    return dist
+
+def knn_predict(dist, labels_train, k, ):
+    return
+def evaluate_knn(data_train , labels_train,data_test ,labels_test, k):
+    return
\ No newline at end of file
diff --git a/read_cifar.py b/read_cifar.py
new file mode 100644
index 0000000..388de81
--- /dev/null
+++ b/read_cifar.py
@@ -0,0 +1,14 @@
+import pickle
+import numpy as np
+
+def read_cifar_batch(batch):
+    with open(batch, 'rb') as fo:
+        dict = pickle.load(fo, encoding='bytes')
+        data = dict[b'data']
+        labels = dict[b'labels']
+    return data.astype(np.float32), np.array(labels, dtype=np.int64)
+
+
+
+batch='data/cifar-10-batches-py/data_batch_1'
+data, labels = read_cifar_batch(batch)
-- 
GitLab