-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata.py
More file actions
35 lines (27 loc) · 971 Bytes
/
Copy pathdata.py
File metadata and controls
35 lines (27 loc) · 971 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import numpy as np
import pandas as pd
import os
import urllib.request
train_url = "https://python-course.eu/data/mnist/mnist_train.csv"
test_url = "https://python-course.eu/data/mnist/mnist_test.csv"
train_path = "data/mnist_train.csv"
test_path = "data/mnist_test.csv"
def download_data():
os.makedirs("data", exist_ok=True)
if not os.path.exists(train_path):
print("grabbing train data...")
urllib.request.urlretrieve(train_url, train_path)
if not os.path.exists(test_path):
print("grabbing test data...")
urllib.request.urlretrieve(test_url, test_path)
def load_data():
download_data()
train_data = pd.read_csv(train_path).to_numpy()
np.random.shuffle(train_data)
train_X = train_data[:, 1:].T / 255.0
train_y = train_data[:, 0]
test_data = pd.read_csv(test_path).to_numpy()
np.random.shuffle(test_data)
test_X = test_data[:, 1:].T / 255.0
test_y = test_data[:, 0]
return train_X, train_y, test_X, test_y