You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi all. I need your help. I'm trying to setup an evaluation framework for MKL by using different types of kernels. However while I try to train MKL weights for multiple Chi2 basis, the program hung at the weight learning stage [1] (See at the bottom). This is my code:
from modshogun import *
from tools.load import LoadMatrix
# Loading toy data from files
def load_Toy(dataRoute, fileTrain, fileLabels):
lm = LoadMatrix()
dataSet = lm.load_numbers(dataRoute + fileTrain)
labels = lm.load_labels(dataRoute + fileLabels)
return (dataSet.T[0:3*len(dataSet.T)/4].T, # Return the training set, 3/4 * dataSet
dataSet.T[(3*len(dataSet.T)/4):].T, # Return the test set, 1/4 * dataSet
labels[0:3*len(labels)/4], # Return corresponding train and test labels
labels[(3*len(labels)/4):])
# Data importation
[traindata, testdata, trainlab, testlab] = load_Toy('../shogun-data/toy/', # Data rute
'fm_train_multiclass_digits500.dat', # Multiclass dataSet examples file name
'label_train_multiclass_digits500.dat') # Multiclass Labels file name
feats_train = RealFeatures(traindata) # train examples
labelsTr = MulticlassLabels(trainlab) # train multiclass labels
feats_test = RealFeatures(testdata) # test examples
labelsTs = MulticlassLabels(testlab) # test multiclass labels
# Parameters
weightNorm = 2
regParam = 2
epsilon = 1e-5
threads = 2
mkl_epsilon = 0.001
# Setting up the MKL machine
mkl = MKLMulticlass() # MKL object
mkl.set_C(regParam) # Setting multiclass regularization parameter
mkl.set_mkl_norm(weightNorm) # Setting the weight vector norm
mkl.set_epsilon(epsilon) # setting the transducer epsilon
mkl.set_mkl_epsilon(mkl_epsilon)
kernels = []
kernels.append(Chi2Kernel(l = feats_train, r = feats_train, width = 5))
kernels.append(Chi2Kernel(l = feats_train, r = feats_train, width = 25))
kernels.append(Chi2Kernel(l = feats_train, r = feats_train, width = 105))
combKer = CombinedKernel()
for k in kernels:
combKer.append_kernel(k)
combKer.init(feats_train, feats_train)
print '[0] Kernel fitted...'
mkl.set_kernel(combKer)
mkl.set_labels(labelsTr)
print '[1] Going to train the mkl machine...'
# Train the weights to return the learnt kernel
mkl.train()
print '[2] Kernel trained... Weights: ', combKer.get_subkernel_weights()
# Now with test samples.
combKer.init(feats_train, feats_test) # The inner product between training
mkl.set_kernel(combKer) # and test examples generates the corresponding Gramm Matrix.
out = mkl.apply() # Applying the obtained Gramm Matrix
# Evaluating the test performance
evalua = MulticlassAccuracy()
testerr = evalua.evaluate(out, labelsTs)
print '[3] Kernel evaluation ready. The precision was: ', testerr*100, '%'
Any help would be very appreciated. Thank you in advance.
The text was updated successfully, but these errors were encountered:
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Hi all. I need your help. I'm trying to setup an evaluation framework for MKL by using different types of kernels. However while I try to train MKL weights for multiple Chi2 basis, the program hung at the weight learning stage
[1]
(See at the bottom). This is my code:Any help would be very appreciated. Thank you in advance.
The text was updated successfully, but these errors were encountered: