def classifier_ssk_modular(fm_train_dna=traindat, fm_test_dna=testdat, label_train_dna=label_traindat, C=1, maxlen=1, decay=1): from modshogun import StringCharFeatures, BinaryLabels from modshogun import LibSVM, StringSubsequenceKernel, DNA from modshogun import ErrorRateMeasure feats_train = StringCharFeatures(fm_train_dna, DNA) feats_test = StringCharFeatures(fm_test_dna, DNA) labels = BinaryLabels(label_train_dna) kernel = StringSubsequenceKernel(feats_train, feats_train, maxlen, decay) svm = LibSVM(C, kernel, labels) svm.train() out = svm.apply(feats_train) evaluator = ErrorRateMeasure() trainerr = evaluator.evaluate(out, labels) # print(trainerr) kernel.init(feats_train, feats_test) predicted_labels = svm.apply(feats_test).get_labels() # print predicted_labels return predicted_labels
def classifier_libsvm_minimal_modular (train_fname=traindat,test_fname=testdat,label_fname=label_traindat,width=2.1,C=1): from modshogun import RealFeatures, BinaryLabels from modshogun import LibSVM, GaussianKernel, CSVFile from modshogun import ErrorRateMeasure feats_train=RealFeatures(CSVFile(train_fname)) feats_test=RealFeatures(CSVFile(test_fname)) labels=BinaryLabels(CSVFile(label_fname)) kernel=GaussianKernel(feats_train, feats_train, width); svm=LibSVM(C, kernel, labels); svm.train(); out=svm.apply(feats_train); evaluator = ErrorRateMeasure() testerr = evaluator.evaluate(out,labels)
def classifier_libsvm_minimal_modular(train_fname=traindat, test_fname=testdat, label_fname=label_traindat, width=2.1, C=1): from modshogun import RealFeatures, BinaryLabels from modshogun import LibSVM, GaussianKernel, CSVFile from modshogun import ErrorRateMeasure feats_train = RealFeatures(CSVFile(train_fname)) feats_test = RealFeatures(CSVFile(test_fname)) labels = BinaryLabels(CSVFile(label_fname)) kernel = GaussianKernel(feats_train, feats_train, width) svm = LibSVM(C, kernel, labels) svm.train() out = svm.apply(feats_train) evaluator = ErrorRateMeasure() testerr = evaluator.evaluate(out, labels)
def classifier_ssk_modular (fm_train_dna=traindat,fm_test_dna=testdat, label_train_dna=label_traindat,C=1,maxlen=1,decay=1): from modshogun import StringCharFeatures, BinaryLabels from modshogun import LibSVM, StringSubsequenceKernel, DNA from modshogun import ErrorRateMeasure feats_train=StringCharFeatures(fm_train_dna, DNA) feats_test=StringCharFeatures(fm_test_dna, DNA) labels=BinaryLabels(label_train_dna) kernel=StringSubsequenceKernel(feats_train, feats_train, maxlen, decay); svm=LibSVM(C, kernel, labels); svm.train(); out=svm.apply(feats_train); evaluator = ErrorRateMeasure() trainerr = evaluator.evaluate(out,labels) # print(trainerr) kernel.init(feats_train, feats_test) predicted_labels=svm.apply(feats_test).get_labels() # print predicted_labels return predicted_labels
def evaluation_contingencytableevaluation_modular(ground_truth, predicted): from modshogun import BinaryLabels from modshogun import ContingencyTableEvaluation from modshogun import AccuracyMeasure, ErrorRateMeasure, BALMeasure from modshogun import WRACCMeasure, F1Measure, CrossCorrelationMeasure from modshogun import RecallMeasure, PrecisionMeasure, SpecificityMeasure ground_truth_labels = BinaryLabels(ground_truth) predicted_labels = BinaryLabels(predicted) base_evaluator = ContingencyTableEvaluation() base_evaluator.evaluate(predicted_labels, ground_truth_labels) evaluator = AccuracyMeasure() accuracy = evaluator.evaluate(predicted_labels, ground_truth_labels) evaluator = ErrorRateMeasure() errorrate = evaluator.evaluate(predicted_labels, ground_truth_labels) evaluator = BALMeasure() bal = evaluator.evaluate(predicted_labels, ground_truth_labels) evaluator = WRACCMeasure() wracc = evaluator.evaluate(predicted_labels, ground_truth_labels) evaluator = F1Measure() f1 = evaluator.evaluate(predicted_labels, ground_truth_labels) evaluator = CrossCorrelationMeasure() crosscorrelation = evaluator.evaluate(predicted_labels, ground_truth_labels) evaluator = RecallMeasure() recall = evaluator.evaluate(predicted_labels, ground_truth_labels) evaluator = PrecisionMeasure() precision = evaluator.evaluate(predicted_labels, ground_truth_labels) evaluator = SpecificityMeasure() specificity = evaluator.evaluate(predicted_labels, ground_truth_labels) return accuracy, errorrate, bal, wracc, f1, crosscorrelation, recall, precision, specificity