Janet Matsen
Code notes:
RidgeRegression
, defined in rige_regression.py
.RidgeRegression
gets some methods from ClassificationBase
, defined in classification_base.py
.HyperparameterExplorer
in hyperparameter_explorer
is used to tune hyperparameters on training data.
In [1]:
import numpy as np
import matplotlib as mpl
%matplotlib inline
import time
import pandas as pd
import seaborn as sns
from mnist import MNIST # public package for making arrays out of MINST data.
In [2]:
import sys
sys.path.append('../code/')
In [3]:
from ridge_regression import RidgeMulti
from hyperparameter_explorer import HyperparameterExplorer
In [4]:
from mnist_helpers import mnist_training, mnist_testing
In [5]:
import matplotlib.pyplot as plt
from pylab import rcParams
rcParams['figure.figsize'] = 4, 3
In [6]:
train_X, train_y = mnist_training()
test_X, test_y = mnist_testing()
In [7]:
hyper_explorer = HyperparameterExplorer(X=train_X, y=train_y,
model=RidgeMulti,
validation_split=0.1, score_name = 'training RMSE',
use_prev_best_weights=False,
test_X=test_X, test_y=test_y)
In [ ]:
hyper_explorer.train_model(lam=1e10, verbose=False)
In [ ]:
hyper_explorer.train_model(lam=1e+08, verbose=False)
hyper_explorer.train_model(lam=1e+07, verbose=False)
In [8]:
hyper_explorer.train_model(lam=1e+06, verbose=False)
In [ ]:
hyper_explorer.train_model(lam=1e5, verbose=False)
hyper_explorer.train_model(lam=1e4, verbose=False)
hyper_explorer.train_model(lam=1e03, verbose=False)
hyper_explorer.train_model(lam=1e2, verbose=False)
In [9]:
hyper_explorer.train_model(lam=1e1, verbose=False)
In [ ]:
hyper_explorer.train_model(lam=1e0, verbose=False)
hyper_explorer.train_model(lam=1e-1, verbose=False)
hyper_explorer.train_model(lam=1e-2, verbose=False)
hyper_explorer.train_model(lam=1e-3, verbose=False)
hyper_explorer.train_model(lam=1e-4, verbose=False)
hyper_explorer.train_model(lam=1e-5, verbose=False)
In [10]:
hyper_explorer.summary
Out[10]:
In [11]:
hyper_explorer.plot_fits()
In [ ]:
t = time.localtime(time.time())
hyper_explorer.plot_fits(filename = "Q-1-1-3_val_and_train_RMSE_{}-{}".format(t.tm_mon, t.tm_mday))
In [ ]:
hyper_explorer.plot_fits(ylim=(.6,.7),
filename = "Q-1-1-3_val_and_train_RMSE_zoomed_in{}-{}".format(t.tm_mon, t.tm_mday))
In [ ]:
hyper_explorer.best('score')
In [ ]:
hyper_explorer.best('summary')
In [ ]:
hyper_explorer.best('best score')
In [13]:
hyper_explorer.train_on_whole_training_set()
In [14]:
hyper_explorer.final_model.results_row()
Out[14]:
In [15]:
hyper_explorer.evaluate_test_data()
In [ ]:
In [ ]: