Demo entry 6758306

zhouwenqing

   

Submitted by anonymous on Aug 10, 2018 at 19:23
Language: Matlab. Code size: 1.0 kB.

import argparse
import os
import time

import numpy as np
from sklearn.datasets import fetch_mldata
from sklearn.model_selection import train_test_split
from sklearn.model_selection import StratifiedKFold
from sklearn.metrics import accuracy_score
from sklearn.utils import shuffle
from skorch import NeuralNetClassifier
from skorch.callbacks import EpochScoring
import torch
from torch import nn


BATCH_SIZE = 128
DATA_HOME = os.path.join(os.getcwd(), 'examples', 'datasets')
LEARNING_RATE = 0.1
MAX_EPOCHS = 12


def get_data(num_samples, data_home):
    mnist = fetch_mldata('MNIST original', data_home=data_home)
    torch.manual_seed(0)
    X = mnist.data.astype('float32').reshape(-1, 1, 28, 28)
    y = mnist.target.astype('int64')
    X, y = shuffle(X, y)
    X, y = X[:num_samples], y[:num_samples]
    X_train, X_test, y_train, y_test = train_test_split(X, y, stratify=y, random_state=0)
    X_train /= 255
    X_test /= 255
    return X_train, X_test, y_train, y_test

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).