import hw_utils from datetime import datetime X_train, Y_train, X_test, Y_test = hw_utils.loaddata("MiniBooNE_PID.txt") X_train_norm, X_test_norm = hw_utils.normalize(X_train, X_test) # # Part d linear activations # print "Linear Activations" # linear_arch1 = [[50, 2],[50, 50, 2],[50, 50, 50, 2],[50, 50, 50, 50, 2]] # start = datetime.now() # hw_utils.testmodels(X_train_norm, Y_train, X_test_norm, Y_test, # linear_arch1, 'linear', 'softmax',[0.0], 30, 1000, 0.001, [0.0], [0.0], False, False, 1) # end = datetime.now() # print "Time taken in Linear activations part 1 : " + str((end - start).total_seconds()) # # linear_arch2 = [[50, 50, 2], [50, 500, 2], [50, 500, 300, 2], [50, 800, 500, 300, 2], [50, 800, 800, 500, 300, 2]] # start = datetime.now() # hw_utils.testmodels(X_train_norm, Y_train, X_test_norm, Y_test, # linear_arch2, 'linear', 'softmax',[0.0], 30, 1000, 0.001, [0.0], [0.0], False, False, 1) # end = datetime.now() # print "Time taken in Linear activations part 2 : " + str((end - start).total_seconds()) # # arch = [[50, 50, 2], [50, 500, 2], [50, 500, 300, 2], [50, 800, 500, 300, 2], [50, 800, 800, 500, 300, 2]] # # # Part e sigmoid activation # print "\n\nSigmoid activation" # start = datetime.now() # hw_utils.testmodels(X_train_norm, Y_train, X_test_norm, Y_test, # arch, 'sigmoid', 'softmax',[0.0], 30, 1000, 0.001, [0.0], [0.0], False, False, 1) # end = datetime.now() # print "Time taken in Sigmoid activation : " + str((end - start).total_seconds())
import hw_utils as hw from timeit import default_timer xTrain, yTrain, xTest, yTest = hw.loaddata('MiniBooNE_PID.txt') xTrainNorm, xTestNorm = hw.normalize(xTrain, xTest) dIn = 50 dOut = 2 xTrain = xTrainNorm yTrain = yTrain xTest = xTestNorm yTest = yTest print "\nLinear Activations" print "-------------------" print "Architecture 1" print "---------------" architectures = [[dIn, dOut], [dIn, 50, dOut], [dIn, 50, 50, dOut], [dIn, 50, 50, 50, dOut]] startTime = default_timer() hw.testmodels(xTrain, yTrain, xTest, yTest, architectures, 'linear', 'softmax', [0.0], 30, 1000, 0.001, [0.0], [0.0], False, False, 0) timeTaken = default_timer() - startTime print "Training time = " + str(timeTaken) + " s" print "Architecture 2" print "---------------" architectures = [[dIn, 50, dOut], [dIn, 500, dOut], [dIn, 500, 300, dOut], [dIn, 800, 500, 300, dOut], [dIn, 800, 800, 500, 300, dOut]] startTime = default_timer()
test.drop(test.columns[[0, 1, 2]], axis=1, inplace=True) #remove extra col label ''' validate_rows=test.shape[0] test[test.shape[1]]=np.random.randint(2, size=validate_rows) print test.shape,test.columns.tolist() y_te = validate[[test.shape[1]-1]].copy() test.drop(test.columns[test.shape[1]-1],1,inplace=True) ''' #y_values=pd.DataFrame(y_values) y_te = np.random.randint(2, size=test.shape[0]) print y_te.shape X_te = test.copy() test.to_csv("test.csv", sep=',') X_tr, X_te = hw_utils.normalize(X_tr.values, X_te.values) # to handle categorical represenatation y_tr = to_categorical(y_tr.values) y_te = to_categorical(y_te) print X_tr.shape, X_te.shape, y_tr.shape, y_te.shape din = X_tr.shape[1] dout = 2 del train,test,questions,users,invited\ #,validate print 'Try Neural Network' print din, dout time_e = hw_utils.start_time()
print test.shape, test.columns.tolist() test.drop(test.columns[[0, 1, 2]], axis=1, inplace=True) ''' validate_rows=test.shape[0] test[test.shape[1]]=np.random.randint(2, size=validate_rows) print test.shape,test.columns.tolist() y_te = validate[[test.shape[1]-1]].copy() test.drop(test.columns[test.shape[1]-1],1,inplace=True) ''' #y_values=pd.DataFrame(y_values) y_te = np.random.randint(2, size=test.shape[0]) print y_te.shape X_te = test.copy() test.to_csv("test.csv", sep=',') X_tr, X_te = hw_utils.normalize(X_tr, X_te) # to handle categorical represenatation y_tr = to_categorical(y_tr.values) y_te = to_categorical(y_te) print X_tr.shape, X_te.shape, y_tr.shape, y_te.shape din = X_tr.shape[1] dout = 2 del train, test, questions, users, invited, validate print 'Try Neural Network' print din, dout time_e = hw_utils.start_time() arch_list_e = [[din, din, dout], [din, din * 10, dout],
sgd_Nesterov=True, EStop=True, verbose=0) print " Time Taken = ", time.time() - start_time displayJson(results) if __name__ == "__main__": #Part A) Load and normalize start_time = time.time() X_tr, y_tr, X_te, y_te = hw.loaddata(FILENAME) print "Time taken to load data = ", time.time() - start_time start_time = time.time() X_tr, X_te = hw.normalize(X_tr, X_te) print "Time taken to normalize data = ", time.time() - start_time #Part D) #partd_a(X_tr,y_tr,X_te,y_te) #partd_b(X_tr,y_tr,X_te,y_te) #parte(X_tr,y_tr,X_te,y_te) #partf(X_tr,y_tr,X_te,y_te) #partg(X_tr,y_tr,X_te,y_te) #parth(X_tr,y_tr,X_te,y_te) #parti(X_tr,y_tr,X_te,y_te)