In [ ]:
import matplotlib as mpl
mpl.use('Agg')
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import os
import pandas as pd
import seaborn as sns
import sys
In [ ]:
sys.path.append('../code')
In [ ]:
from NeuralNet import NeuralNet
from TransferFunctions import TanhTF, LinearTF
In [ ]:
from sklearn.datasets import make_classification
X, y = make_classification(n_samples=2000, n_features=10,
n_informative=10, n_redundant=0, n_repeated=0,
n_classes=2, n_clusters_per_class=1,
weights=None, flip_y=0.0001, class_sep=1.0,
hypercube=True, shift=0.0, scale=1.0,
shuffle=True, random_state=None)
X=X.T
split_frac = 0.25
N = X.shape[1]
split_index = int(N*(1-split_frac))
print("{} of {} points from training are reserved for "
"validation".format(N - split_index, N))
test_X = X[:, split_index:]
test_y = y[split_index:]
X = X[:, 0:split_index]
y = y[0:split_index]
print('shape of X: {}. (Columns are rows; rows are features)'.format(X.shape))
In [ ]:
y.shape
In [ ]:
# columns are data points and rows are features
d, N = np.shape(X)
C = np.unique(y).shape[0]
In [ ]:
n = NeuralNet(X=X, y=y, hidden_nodes=20,
hiddenTF=TanhTF, outputTF=TanhTF,
#hiddenTF=LinearTF, outputTF=LinearTF,
minibatch_size=10,
eta0 = 0.001,
X_test = test_X, y_test = test_y
)
In [ ]:
n.N
In [ ]:
n.run(epochs=20)
In [ ]:
n.C
In [ ]:
n.results.tail()
In [ ]:
sl = n.plot_square_loss()
In [ ]:
l01 = n.plot_01_loss()
In [ ]:
p = n.plot_weight_evolution()
In [ ]:
p1 = n.plot_sum_of_weights('W1')
p2 = n.plot_sum_of_weights('W2')
In [ ]:
p1 = n.plot_norm_of_gradient('W1')
p2 = n.plot_norm_of_gradient('W2')
In [ ]:
n.W1_dot_prod_checking.head()
In [ ]:
n.W2_dot_prod_checking.head()
In [ ]:
p = n.plot_sample_dot_prods() #figsize=(8,3))
In [ ]:
np.linalg.norm(np.array([[1, 2]]))
In [ ]:
n.predict_y(n.X)
In [ ]:
dW1, dW2 = n.gradients(n.X, n.Y, rounded=True)
In [ ]:
dW1_num, dW2_num = n.numerical_derivatives()
In [ ]:
np.max(dW1 - dW1_num)
In [ ]:
np.sum(np.abs(dW1 - dW1_num))
In [ ]:
np.sum(np.abs(dW2 - dW2_num))
In [ ]:
n.results.tail(1).T
In [ ]: