diff --git a/mkl.py b/mkl.py index 6e81012..f0e801d 100755 --- a/mkl.py +++ b/mkl.py @@ -20,9 +20,9 @@ from modshogun import MKLClassification from modshogun import LibSVM except ImportError: - print "ImportError:" - print "Importing the large-scale machine learning toolbox SHOGUN failed." - print "Refer to instructions on http://www.shogun-toolbox.org/ for installing SHOGUN with the python_modular interface." + print("ImportError:") + print("Importing the large-scale machine learning toolbox SHOGUN failed.") + print("Refer to instructions on http://www.shogun-toolbox.org/ for installing SHOGUN with the python_modular interface.") raise @@ -46,7 +46,7 @@ parser.add_option("-L", "--testlabelsFilename", type="str", action="store", default = "kernels/testlabels.txt", dest="testlabelsFilename", help="Name of the file providing the testlabels [default: %default]") parser.add_option("-I", "--imbalance", type="float", action="store", default = "1.0", - dest="Imbalance", help="Imbalance, multiplied with cost parameter for SVM negative class [default: %default]") + dest="Imbalance", help="Imbalance, multiplied with cost parameter for SVM minority class [default: %default]") parser.add_option("-t", "--whetherPerformTest", type="int", action="store", default = 1, dest="performTest", help="Specify 1 if performTest, else 0.[default: %default]") @@ -66,7 +66,7 @@ trainkernel = CombinedKernel() for k in range(0, len(kernelFilenames)): thisFname = kernelFilenames[k] - print thisFname + print(thisFname) if os.path.exists(thisFname): trainkernel.append_kernel(CustomKernel(numpy.loadtxt(thisFname, delimiter=','))) else: @@ -80,7 +80,7 @@ mkl.set_mkl_norm(options.MKLNorm) #2,3 # set cost (neg, pos) -mkl.set_C(options.C*options.Imbalance, options.C) +mkl.set_C(options.C, options.C*options.Imbalance) mkl.set_C_mkl(options.C) # set kernel and labels mkl.set_kernel(trainkernel) @@ -94,20 +94,20 @@ mkl.set_epsilon(1e-5) mkl.parallel.set_num_threads(10) mkl.io.disable_progress() -print "Before SVM train with MKL" +print("Before SVM train with MKL") try: mkl.train() except: - print "Train error caught here" + print("Train error caught here") raise -print "Training done" +print("Training done") alphas = mkl.get_alphas() bias = mkl.get_bias() sv = mkl.get_support_vectors() -print str(bias) +print(str(bias)) kw = trainkernel.get_subkernel_weights() -print kw +print(kw) head, tail = os.path.split(options.subkernelWeightsFilename) biasFilename = head+'/biasValue.txt' alphasFilename = head+'/alphas.txt' @@ -121,7 +121,7 @@ numpy.savetxt(svIndicesFilename, sv, fmt='%d', delimiter=',') # write the subkernel weights to file numpy.savetxt(options.subkernelWeightsFilename, kw, fmt='%.10f', delimiter=',') -print "Subkernel weights, bias and alphas written to individual files" +print("Subkernel weights, bias and alphas written to individual files") # separately for test, one will have to @@ -146,9 +146,9 @@ predictions = mkl.apply().get_values() numpy.savetxt(options.predictedlabelsFilename, predictions, fmt='%.10f', delimiter=',') - print "Predicted labels written to file" + print("Predicted labels written to file") else: predictions = mkl.apply().get_values() numpy.savetxt(options.predictedlabelsFilename, predictions, fmt='%.10f', delimiter=',') - print "Training prediction labels written to file" + print("Training prediction labels written to file")