def runShogunSVMDNASubsequenceStringKernel(train_xt, train_lt, test_xt):
	"""
	run svm with spectrum kernel
	"""

    ##################################################
    # set up svm
	feats_train = StringCharFeatures(train_xt, DNA)
	feats_test = StringCharFeatures(test_xt, DNA)
	
	kernel=SubsequenceStringKernel(feats_train, feats_train, MAXLEN, DECAY)
	kernel.io.set_loglevel(MSG_DEBUG)
	kernel.init(feats_train, feats_train)

    # init kernel
	labels = BinaryLabels(train_lt)
	
	# run svm model
	print "Ready to train!"
	svm=LibSVM(SVMC, kernel, labels)
	svm.io.set_loglevel(MSG_DEBUG)
	svm.train()

	# predictions
	print "Making predictions!"
	out1DecisionValues = svm.apply(feats_train)
	out1=out1DecisionValues.get_labels()
	kernel.init(feats_train, feats_test)
	out2DecisionValues = svm.apply(feats_test)
	out2=out2DecisionValues.get_labels()

	return out1,out2,out1DecisionValues,out2DecisionValues
コード例 #2
0
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, SubsequenceStringKernel, 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 = SubsequenceStringKernel(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
コード例 #3
0
def kernel_ssk_string_modular (fm_train_dna=traindat, fm_test_dna=testdat, maxlen=1, decay=1):
	from modshogun import SubsequenceStringKernel
	from modshogun import StringCharFeatures, DNA

	feats_train=StringCharFeatures(fm_train_dna, DNA)
	feats_test=StringCharFeatures(fm_test_dna, DNA)

	kernel=SubsequenceStringKernel(feats_train, feats_train, maxlen, decay)

	km_train=kernel.get_kernel_matrix()
	# print(km_train)
	kernel.init(feats_train, feats_test)
	km_test=kernel.get_kernel_matrix()
	# print(km_test)
	return km_train,km_test,kernel
def runShogunSVMDNASubsequenceStringKernel(train_xt, train_lt, test_xt):
    """
	run svm with spectrum kernel
	"""

    ##################################################
    # set up svm
    feats_train = StringCharFeatures(train_xt, DNA)
    feats_test = StringCharFeatures(test_xt, DNA)

    kernel = SubsequenceStringKernel(feats_train, feats_train, MAXLEN, DECAY)
    kernel.io.set_loglevel(MSG_DEBUG)
    kernel.init(feats_train, feats_train)

    # init kernel
    labels = BinaryLabels(train_lt)

    # run svm model
    print "Ready to train!"
    svm = LibSVM(SVMC, kernel, labels)
    svm.io.set_loglevel(MSG_DEBUG)
    svm.train()

    # predictions
    print "Making predictions!"
    out1DecisionValues = svm.apply(feats_train)
    out1 = out1DecisionValues.get_labels()
    kernel.init(feats_train, feats_test)
    out2DecisionValues = svm.apply(feats_test)
    out2 = out2DecisionValues.get_labels()

    return out1, out2, out1DecisionValues, out2DecisionValues
コード例 #5
0
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, SubsequenceStringKernel, 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=SubsequenceStringKernel(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
コード例 #6
0
def kernel_ssk_string_modular(fm_train_dna=traindat,
                              fm_test_dna=testdat,
                              maxlen=1,
                              decay=1):
    from modshogun import SubsequenceStringKernel
    from modshogun import StringCharFeatures, DNA

    feats_train = StringCharFeatures(fm_train_dna, DNA)
    feats_test = StringCharFeatures(fm_test_dna, DNA)

    kernel = SubsequenceStringKernel(feats_train, feats_train, maxlen, decay)

    km_train = kernel.get_kernel_matrix()
    # print(km_train)
    kernel.init(feats_train, feats_test)
    km_test = kernel.get_kernel_matrix()
    # print(km_test)
    return km_train, km_test, kernel