Skip to content

Instantly share code, notes, and snippets.

@gf712
Created April 5, 2019 11:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gf712/c6a98704bae6fa22026f1e03148173ab to your computer and use it in GitHub Desktop.
Save gf712/c6a98704bae6fa22026f1e03148173ab to your computer and use it in GitHub Desktop.
import numpy as np
import shogun as sg
from sklearn import datasets
X, y = datasets.load_breast_cancer(True)
y[y==0] = -1
feat = sg.features(X.T)
kernel1 = sg.kernel("GaussianKernel")
kernel2 = sg.kernel("PolyKernel")
svm = sg.machine("LibSVM", epsilon=1, kernel=kernel1, labels=sg.BinaryLabels(y))
node = sg.GridSearch(svm)
node.attach("kernel::log_width", np.array([1., 2.]))
node.attach("C1", np.array([1., 2., 3.]))
node.attach("C2", np.array([1., 2., 3.]))
node2=sg.GridParameters(kernel2)
node2.attach("degree", np.array([1,2], np.int32))
node.attach("kernel", node2)
node.train(feat)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment