In [1]:
from time import time
import numpy as np
from sklearn.cross_validation import train_test_split
from sklearn.datasets import fetch_mldata
from sklearn.metrics import classification_report
from sklearn.metrics import accuracy_score
from sklearn.metrics import confusion_matrix
from sknn.mlp import Classifier, Layer
In [2]:
mnist = fetch_mldata('mnist-original')
X_train, X_test, y_train, y_test = train_test_split(
(mnist.data / 255.0).astype(np.float32),
mnist.target.astype(np.int32),
test_size=0.33, random_state=1234)
In [3]:
clf = Classifier(
layers=[Layer("Rectifier", units=300), Layer("Softmax")],
learning_rate=0.02,
batch_size=100,
n_iter=2,
verbose=1,
valid_size=0.5
)
clf.fit(X_train, y_train)
Out[3]:
In [4]:
print "the dim of train set : %s, %s" %(X_train.shape[0], (X_train.shape[1]))
print "the dim of validation set : %s, %s" %(clf.valid_set[0].shape[0], clf.valid_set[0].shape[1])
In [8]:
print y_test.shape
y_test_reshape = y_test.reshape((y_test.shape[0], 1))
print y_test_reshape.shape
In [10]:
clf1 = Classifier(
layers=[Layer("Rectifier", units=300), Layer("Softmax")],
learning_rate=0.02,
batch_size=100,
n_iter=2,
verbose=1,
valid_set=(X_test, y_test_reshape)
)
clf1.fit(X_train, y_test.reshape((y_test.shape[0], 1)))