In [1]:
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
%matplotlib inline
import time
import pandas as pd
import seaborn as sns
In [2]:
import sys
sys.path.append('../code/')
In [3]:
!pwd
In [4]:
from logistic_regression import LogisticRegression
from logistic_regression_batch import LogisticRegressionBatch
from hyperparameter_explorer import HyperparameterExplorer
In [5]:
from mnist_helpers import mnist_training, mnist_testing
In [6]:
import matplotlib.pyplot as plt
from pylab import rcParams
rcParams['figure.figsize'] = 4, 3
In [7]:
train_X, train_y = mnist_training(shuffled=True)
test_X, test_y = mnist_testing(shuffled=True)
In [8]:
hyper_explorer_sgd = HyperparameterExplorer(X=train_X, y=train_y,
model=LogisticRegression,
validation_split=0.1,
score_name = '-(log loss)/N, training',
use_prev_best_weights=True,
test_X=test_X, test_y=test_y) # need test_X, test_y for loss w/ fit plot
In [9]:
eta0=0.1
batchs = 1000
hyper_explorer_sgd.train_model(lam=0, eta0=eta0, max_iter=10**3, #10**2,
batch_size=batchs, progress_monitoring_freq=batchs*10,
delta_percent=.001, verbose=True)
In [10]:
hyper_explorer_sgd.train_on_whole_training_set()
In [ ]:
hyper_explorer_sgd.e()
In [ ]:
eta0=0.1
batchs = 1000
hyper_explorer_sgd.train_model(lam=1, eta0=eta0, max_iter=8*10**3, #10**2,
batch_size=batchs, progress_monitoring_freq=batchs*10,
delta_percent=.001, verbose=False)
In [ ]:
eta0=0.1
batchs = 1000
hyper_explorer_sgd.train_model(lam=2, eta0=eta0, max_iter=5*10**3, #10**2,
batch_size=batchs, progress_monitoring_freq=batchs*10,
delta_percent=.001, verbose=False)
In [ ]:
eta0=0.1
batchs = 1000
hyper_explorer_sgd.train_model(lam=3, eta0=eta0, max_iter=5*10**3, #10**2,
batch_size=batchs, progress_monitoring_freq=batchs*10,
delta_percent=.001, verbose=False)
In [ ]:
eta0=0.1
batchs = 1000
hyper_explorer_sgd.train_model(lam=5, eta0=eta0, max_iter=5*10**3, #10**2,
batch_size=batchs, progress_monitoring_freq=batchs*10,
delta_percent=.001, verbose=False)
In [ ]:
eta0=0.1
batchs = 1000
hyper_explorer_sgd.train_model(lam=10, eta0=eta0, max_iter=5*10**3, #10**2,
batch_size=batchs, progress_monitoring_freq=batchs*10,
delta_percent=.001, verbose=False)
In [ ]:
hyper_explorer_sgd.plot_best_fits(logx=False)
In [ ]:
hyper_explorer_sgd.models[1].plot_test_and_train_log_loss_during_fitting()
In [ ]:
10**5
In [ ]:
hyper_explorer_sgd.summary.tail(3)
In [ ]:
hyper_explorer_sgd.best('model').results.tail(3)
In [ ]:
fig, ax = plt.subplots(1, 1, figsize=(4, 3))
plot_data = hyper_explorer_sgd.best('model').results
print(plot_data.columns)
xval = '# of passes through N pts'
colors=['b', 'g']
plt.plot(plot_data[xval], plot_data['-(log loss)/N, training'], linestyle='--', marker='o', color=colors[0])
plt.plot(plot_data[xval], plot_data['-(log loss)/N, testing'], linestyle='--', marker='o', color=colors[1])
plt.legend(loc='best')
plt.xlabel(xval)
plt.ylabel('-(log loss)/N')
ax.axhline(y=0, color='k')
plt.tight_layout()
#fig.savefig("161031_Q-2-1_norm_log_loss_during_fit--no_starting_weights.pdf")
In [ ]:
hyper_explorer_sgd.train_on_whole_training_set(max_iter=10**3)
In [ ]:
hyper_explorer_sgd.evaluate_test_data()
In [ ]: