Skip to content
Snippets Groups Projects
Commit 9206be84 authored by oscarchaufour's avatar oscarchaufour
Browse files

knn and read cifar

knn creation and cread_cifar three functions ok
parent 781f0b13
No related branches found
No related tags found
No related merge requests found
knn.py 0 → 100644
# -*- coding: utf-8 -*-
"""
Created on Fri Oct 20 17:39:37 2023
@author: oscar
"""
......@@ -18,7 +18,6 @@ def read_cifar_batch(batch_path):
data = np.array(batch.get(b'data'))
labels = np.array(batch.get(b'labels'))
return data, labels
def read_cifar (batch_dir) :
......@@ -43,6 +42,22 @@ def read_cifar (batch_dir) :
return data, labels
def split_dataset(data, labels, split) :
number_total = data.shape[0]
number_train = int(number_total * split)
indices = np.arange(number_total)
np.random.shuffle(indices)
indices_train = indices[:number_train]
indices_test = indices[number_train:]
data_train = data[indices_train]
labels_train = labels[indices_train]
data_test = data[indices_test]
labels_test = labels[indices_test]
return(data_train, labels_train, data_test, labels_test)
if __name__ == "__main__":
file = "./data/cifar-10-python/data_batch_1"
read_cifar_batch(file)
file = "./data/cifar-10-python/"
data, labels = read_cifar(file)
res = split_dataset(data, labels, 0.8)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment