def predict(model): X, patientIds = loadTestData() predictions = model.predict(X).flatten() predictions_df = pd.DataFrame({ 'Patient Id': patientIds, 'Expected': predictions }).drop_duplicates('Patient Id') return predictions_df
def main(): k = utils.numOfClasses columns = int(((k * k) * (k - 1)) / 4) ecoc_matrix = np.zeros((k, columns), dtype=float) classifiers = [] trainset = utils.fetchData() print("total train set data len: {}".format(str(len(trainset)))) testset = utils.loadTestData() lambda_p = 1 epoch_number = 15 pair_index = 0 # Train All-Pair Classifiers for i in range(utils.numOfClasses): # add all other classes that are not the positive class oppsiteClasses = [c for c in range(utils.numOfClasses) if c != i] for y0, y1 in get_all_pairs(oppsiteClasses): update_ecoc_matrix(ecoc_matrix, pair_index, i, (y0, y1)) print("working on {} vs {},{}".format(i, y0, y1)) pair_index = pair_index + 1 filtered_data = filter_data(trainset, (i, y0, y1)) print("relevant data: {}".format(str(len(filtered_data)))) binary_data = utils.transformToBinaryClasses(filtered_data, positiveClass=i) model = utils.SVM(utils.inputDim, utils.eta, lambda_p, epoch_number) model.train(binary_data) classifiers.append(model) print("finished with #{} model".format(pair_index)) # Evaluate Test Data by Hamming Distance utils.evaluation(testset, utils.HammingDistance, ecoc_matrix, 'test.random2.ham.pred', classifiers, distanceMetric="Hamming") # Evaluate Test Data by Loss Base Decoding utils.evaluation(testset, utils.lossBaseDecoding, ecoc_matrix, 'test.random2.loss.pred', classifiers, distanceMetric="LBD")
def main(): classifiers = [] trainset = utils.fetchData() devset = utils.loadDevData() testset = utils.loadTestData() # train OvA classifiers for i in range(utils.numOfClasses): binData = utils.transformToBinaryClasses(trainset, positiveClass=[i]) model = utils.SVM(utils.inputDim, utils.eta, 1, 50) model.train(binData) classifiers.append(model) print("finished with #{} model".format(i)) # Validation - Evaluate Test Data by Hamming Distance utils.validate(devset, utils.HammingDistance, ecocMat, 'test.onevall.ham.pred', classifiers, distanceMetric="Hamming") # Validation - Evaluate Test Data by Loss Base Decoding utils.validate(devset, utils.lossBaseDecoding, ecocMat, 'test.onevall.ham.pred', classifiers, distanceMetric="LBD") # Test - Evaluate test data by Hamming Distance utils.evaluate(testset, utils.HammingDistance, ecocMat, 'test.onevall.ham.pred', classifiers, distanceMetric="Hamming") # Test - Evaluate test data by Loss Base Decoding utils.evaluate(testset, utils.lossBaseDecoding, ecocMat, 'test.onevall.loss.pred', classifiers, distanceMetric="LBD")
def main(): k = utils.numOfClasses columns = int(k * (k - 1) / 2) ecoc_matrix = np.zeros((k, columns), dtype=int) classifiers = [] trainset = utils.fetchData() devset = utils.loadDevData() print("total train set data len: {}".format(str(len(trainset)))) testset = utils.loadTestData() lambda_p = 1 epoch_number = 20 pair_index = 0 # Train All-Pair Classifiers for y0, y1 in get_all_pairs(utils.numOfClasses): update_ecoc_matrix(ecoc_matrix, pair_index, y0, y1) print("working on pair {},{}".format(y0, y1)) pair_index = pair_index + 1 filtered_data = filter_data(trainset, (y0, y1)) print("pair relevant data: {}".format(str(len(filtered_data)))) binary_data = utils.transformToBinaryClasses(filtered_data, positiveClass=[y0]) model = utils.SVM(utils.inputDim, utils.eta, lambda_p, epoch_number) model.train(binary_data) classifiers.append(model) print("finished with #{} model".format(pair_index)) print(ecoc_matrix) # Evaluate Test Data by Hamming Distance utils.validate(devset, utils.HammingDistance, ecoc_matrix, 'test.allpairs.ham.pred', classifiers, distanceMetric="Hamming") # Evaluate Test Data by Loss Base Decoding utils.validate(devset, utils.lossBaseDecoding, ecoc_matrix, 'test.allpairs.loss.pred', classifiers, distanceMetric="LBD") # Evaluate Test Data by Hamming Distance utils.evaluate(testset, utils.HammingDistance, ecoc_matrix, 'test.allpairs.ham.pred', classifiers, distanceMetric="Hamming") # Evaluate Test Data by Loss Base Decoding utils.evaluate(testset, utils.lossBaseDecoding, ecoc_matrix, 'test.allpairs.loss.pred', classifiers, distanceMetric="LBD")
def main(): train_data = loadTrainData(train_file) test_data = loadTestData(test_file) RNNTrain(train_data)
def main(): rows = utils.numOfClasses columns = random.randint(4, 8) ecoc_matrix = create_ecoc_matrix(rows, columns) classifiers = [] trainset = utils.fetchData() print("total train set data len: {}".format(str(len(trainset)))) devset = utils.loadDevData() testset = utils.loadTestData() lambda_p = 1 epoch_number = 20 print(ecoc_matrix) print(len(devset), len(testset)) for j in range(columns): positive = [] negetive = [] for i in range(rows): if ecoc_matrix[i][j] == 1: positive.append(i) elif ecoc_matrix[i][j] == -1: negetive.append(i) print(j, " positive: ", positive, "negetive:", negetive) filtered_data = filter_data(trainset, negetive + positive) print("filtered data", len(filtered_data)) # need to change this function to support list binary_data = utils.transformToBinaryClasses(filtered_data, positiveClass=positive) model = utils.SVM(utils.inputDim, utils.eta, lambda_p, epoch_number) model.train(binary_data) classifiers.append(model) # Validation - Evaluate Test Data by Hamming Distance utils.validate(devset, utils.HammingDistance, ecoc_matrix, 'test.random.ham.pred', classifiers, distanceMetric="Hamming") # Validation - Evaluate Test Data by Loss Base Decoding utils.validate(devset, utils.lossBaseDecoding, ecoc_matrix, 'test.random.loss.pred', classifiers, distanceMetric="LBD") # Test - Evaluate Test Data by Hamming Distance utils.evaluate(testset, utils.HammingDistance, ecoc_matrix, 'test.random.ham.pred', classifiers, distanceMetric="Hamming") # Test - Evaluate Test Data by Loss Base Decoding utils.evaluate(testset, utils.lossBaseDecoding, ecoc_matrix, 'test.random.loss.pred', classifiers, distanceMetric="LBD")