def linear_objective(space): model = get_model(args.model, nfeat=feat_dict["train"].size(1), nclass=nclass, nhid=0, dropout=0, cuda=args.cuda) val_acc, _, _ = train_linear(model, feat_dict, space['weight_decay'], args.dataset=="mr") print( 'weight decay ' + str(space['weight_decay']) + '\n' + \ 'overall accuracy: ' + str(val_acc)) return {'loss': -val_acc, 'status': STATUS_OK}
def run_model(config, fold, fold_base=None): if config['model'] == 'LSTM': return train_lstm(config, fold) if config['model'] == 'BiLSTM': return train_bilstm(config, fold) if config['model'] == 'NN': return train_net(config, fold) if config['model'] == 'linear': return train_linear(config, fold) if config['model'] == 'svm': return train_svm(config, fold) if config['model'] == 'random_forest': return train_random_forrest(config, fold) if config['model'] == 'baseline': return train_baseline(config, fold, fold_base)
# Get training and validation sets (train_fea, test_fea) = getTrainValidSets(feature, 2) (train_tar, test_tar) = getTrainValidSets(target, 2) train_fea = feature train_tar = target # Feature normalization (train_fea, m, s) = normalize(train_fea, axis=0) print(m.shape) test_fea = normalizePara(test_fea, m, s) # print ('Training') # Training beta = train_linear(train_fea, train_tar, test_fea, test_tar, eta=1e-5, lamb=0, maxIter=1000000, debug=0) # Write beta modFile = open(sys.argv[2], 'w') beta = beta.tolist() m = m.tolist() s = s.tolist() modFile.write(','.join(str(b[0]) for b in beta) + '\n') modFile.write(','.join(str(a) for a in m) + '\n') modFile.write(','.join(str(a) for a in s) + '\n')
from train import train_linear from parseData import parseData, parseData_sliding from eva import evaluate from util import getTrainValidSets, normalize import numpy as np import sys [history, target, factors, trainLen] = parseData_sliding('./data/train.csv') # Get training and validation sets (trainData, testTrain) = getTrainValidSets(history, 1.1) (gndData, testGnd) = getTrainValidSets(target, 1.1) # trainData = history gndData = target # Feature normalization # trainData = normalize(trainData, axis=0) # testTrain = normalize(testTrain, axis=0) # trainData = np.divide(trainData, 2) # testTrain = np.divide(testTrain, 2) beta = train_linear(trainData, gndData, testTrain, testGnd, 5e-9, 1e-10, 1e-6, 500000, 0) print(factors) evaluate('./data/test_X.csv', beta, factors, trainLen, sys.argv[1])