best_softmax = None ''' batch_sizes = [100, 200] learning_rates = [1e-7, 5e-7] regularization_strengths = [5e4, 1e5] ''' regularization_strengths = [5e4, 1e5, 5e5, 1e8] ################################################################################ # TODO: # # Use the validation set to set the learning rate and regularization strength. # # Save the best trained softmax classifer in best_softmax. # # Hint: about 10 lines of code expected ################################################################################ ns=SoftmaxClassifier() max_iters=8000 for rs in regularization_strengths: ns.train_fmin(X_train,y_train,rs,max_iters) ta=np.mean(y_train == ns.predict(X_train)) va=np.mean(y_val == ns.predict(X_val)) results[rs]=(ta,va) if va>best_val: best_val=va best_reg = rs best_softmax=ns print '\t---- FINISHED fmin with reg: %e------' %rs ################################################################################ # END OF YOUR CODE # ################################################################################
""" batch_sizes = [400] learning_rates = [5e-6] regularization_strengths = [1e5] """ batch_sizes = [100, 200, 400, 800, 1600, 3200, 6400] learning_rates = [1e-7, 5e-7, 1e-6, 5e-6] regularization_strengths = [5e4, 1e5, 5e5, 1e6, 5e6] ################################################################################ # TODO: # # Use the validation set to set the learning rate and regularization strength. # # Save the best trained softmax classifer in best_softmax. # ################################################################################ ns = SoftmaxClassifier() max_iters = 8000 tol = 1e-4 for bs in batch_sizes: for lr in learning_rates: for rs in regularization_strengths: iterations = ns.train(X_train, y_train, lr, rs, max_iters, bs, tol, verbose=True)[0] ta = np.mean(y_train == ns.predict(X_train)) va = np.mean(y_val == ns.predict(X_val)) results[bs, lr, rs] = (iterations, ta, va) if va > best_val: best_val = va best_bs = bs best_it = iterations best_lr = lr best_reg = rs