| 23 | |
| 24 | |
| 25 | def get_mnist(limit=None): |
| 26 | if not os.path.exists('../large_files'): |
| 27 | print("You must create a folder called large_files adjacent to the class folder first.") |
| 28 | if not os.path.exists('../large_files/train.csv'): |
| 29 | print("Looks like you haven't downloaded the data or it's not in the right spot.") |
| 30 | print("Please get train.csv from https://www.kaggle.com/c/digit-recognizer") |
| 31 | print("and place it in the large_files folder.") |
| 32 | |
| 33 | print("Reading in and transforming data...") |
| 34 | df = pd.read_csv('../large_files/train.csv') |
| 35 | data = df.values |
| 36 | np.random.shuffle(data) |
| 37 | X = data[:, 1:].reshape(-1, 28, 28) / 255.0 # data is from 0..255 |
| 38 | Y = data[:, 0] |
| 39 | if limit is not None: |
| 40 | X, Y = X[:limit], Y[:limit] |
| 41 | return X, Y |
| 42 | |
| 43 | |
| 44 | |