An odd issue occurs in `mkl.fit` when training.
Dawntown opened this issue · 4 comments
I try to search for the best parameters of EasyMKL, so I build a module, which works well, to implement it.
def mkl_search(KL, y, param_grid, scoring='accuracy', seed=np.random.RandomState()):
'''
Search for best params of MKL classifier
Return best score, params and post-trained model
'''
best_params = {}
best_score = 0
for lam in param_grid['lam']:
for C in param_grid['C']:
svm = SVC(C=C)
mkl = EasyMKL(lam=lam, learner=svm)
scores = cross_val_score(KL, y, mkl, n_folds=5, scoring=scoring, random_state=seed)
if np.mean(scores) > best_score:
best_params['lam'] = lam
best_params['C'] = C
best_score = np.mean(scores)
best_model = EasyMKL(lam=best_params['lam'], learner=SVC(C=best_params['C']))
print('start training the best model of MKL...')
best_model.fit(KL, y)
print('training DONE!')
return best_score, best_params, best_model
It will return a fitted mkl model, and I can run the code below smoothly.
param_grid = {
'lam': np.linspace(0,1,11),
'C': np.logspace(-4,2,7)
}
best_score, best_params, best_model = mkl_search(KL_train, y_train, param_grid)
print("best param (MKL): {}\nbest score: {}".format(best_params, best_score))
y_pred = best_model.predict(KL_test)
y_score = best_model.decision_function(KL_test)
When I run the best_model.fit(KL_train, y_train)
in the command line instead of in the function, however, it will pop out an error like KeyError: 'verbose'
. The complete error info can be found in this link.
Hi again!
I tried the code you posted and it works on my machine.
I'm wondering if you're using an old version of MKLpy. Please be sure that you're using the latest version (0.5.x at the time of writing). This problem may also affect your previous issue.
Hi again!
I tried the code you posted and it works on my machine.
I'm wondering if you're using an old version of MKLpy. Please be sure that you're using the latest version (0.5.x at the time of writing). This problem may also affect your previous issue.
I am using the version of 0.5.2 installed in conda env. I tried the codes below in the command line, the former of which is OK, but the latter is not.
best_model = EasyMKL(lam=0.2, learner=SVC(C=1.)).fit(KL_train, y_train) # it is OK.
best_model = EasyMKL(lam=0.2, learner=SVC(C=1.))
best_model.fit(KL_train, y_train) # it will pop out the error of `KeyError: 'verbose'`
The error is really strange, because those two versions (i.e. in a row and split into two instr) are equivalent.
I just evaluated both the solutions and they work for me.
I tried by installing MKLpy from pip and from git repo, without any problem.
May the conda installation be the problem? Honestly, IDK.
I tried to install MKLpy
in python originally equipped by my Ubuntu, and the command of best_model.fit(KL_train, y_train)
works well. Therefore, that must be conda env
's fault!