def run_optunity(self):
        cv_decorator = optunity.cross_validated(
            x=self.X,
            y=self.Y,
        )

        svm_tuned_auroc = cv_decorator(self.svm_tuned_auroc)

        optimal_svm_pars, info, _ = optunity.maximize_structured(
            svm_tuned_auroc, self.space, num_evals=150, pmap=optunity.pmap)
        print("Optimal parameters" + str(optimal_svm_pars))
        print("AUROC of tuned SVM: %1.3f" % info.optimum)

        df = optunity.call_log2dataframe(info.call_log)
        print(df.sort_values('value', ascending=False))
name = sys.argv[1]

budget = 150
search = {'logC': [-8, 1], 'logGamma': [-8, 1]}

objfun = executable.unpickled['objfun']


def quacking_objfun(**kwargs):
    result = objfun(**kwargs)
    print(str(kwargs) + ' --> %f' % result)
    return result


if __name__ == '__main__':

    pars, info, _ = optunity.maximize(quacking_objfun,
                                      num_evals=budget,
                                      pmap=optunity.pmap,
                                      **search)
    df = optunity.call_log2dataframe(info.call_log)

    with open('results/%s-optunity.pkl' % name, 'w') as f:
        log = {
            'results': df['value'],
            'logC': df['logC'],
            'logGamma': df['logGamma']
        }
        pickle.dump(log, f)
Beispiel #3
0
@optunity.cross_validated(x=data, y=labels, num_folds=5, regenerate_folds=True)
def svm_rbf_tuned_auroc(x_train, y_train, x_test, y_test, logC, logGamma):
    model = sklearn.svm.SVC(C=10 ** logC, gamma=10 ** logGamma).fit(x_train, y_train)
    decision_values = model.decision_function(x_test)
    auc = optunity.metrics.roc_auc(y_test, decision_values)
    return auc

optimal_rbf_pars, info, _ = optunity.maximize(svm_rbf_tuned_auroc, num_evals=300, logC=[-4, 2], logGamma=[-5, 0])
# when running this outside of IPython we can parallelize via optunity.pmap
# optimal_rbf_pars, _, _ = optunity.maximize(svm_rbf_tuned_auroc, 150, C=[0, 10], gamma=[0, 0.1], pmap=optunity.pmap)

print('**********************************************')
print("Optimal parameters: " + str(optimal_rbf_pars))
print("AUROC of tuned SVM with RBF kernel: %1.3f" % info.optimum)

df = optunity.call_log2dataframe(info.call_log)

################################
cutoff = 0.1
fig3 = plt.figure()
ax3 = fig3.add_subplot(111, projection='3d')
ax3.scatter(xs=df[df.value > cutoff]['logC'],
           ys=df[df.value > cutoff]['logGamma'],
           zs=df[df.value > cutoff]['value'])
ax3.set_xlabel('logC')
ax3.set_ylabel('logGamma')
ax3.set_zlabel('AUROC')
ax3.set_title('Show all values of AUROC.')
fig3.savefig('AUROCcutoff01')

################################