Skip to content

Instantly share code, notes, and snippets.

@lisitsyn
Created July 8, 2012 17:03
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 lisitsyn/3071792 to your computer and use it in GitHub Desktop.
Save lisitsyn/3071792 to your computer and use it in GitHub Desktop.
from modshogun import *
from numpy import *
import random
tree_adj = genfromtxt('tree.tsv', skiprows=1)[:,1:]
features = genfromtxt('features.tsv',skiprows=1)[:,1:]
labels = genfromtxt('labels.tsv',dtype=float)[:,1:].flatten()
n_dims, n_vecs = features.shape
norm = NormOne()
features = RealFeatures(log(features))
norm.apply_to_feature_matrix(features)
labels = BinaryLabels(labels)
ibt = IndexBlockTree(tree_adj)
lr = FeatureBlockLogisticRegression(0.1,features,labels,ibt)
# use ratio
lr.set_regularization(1)
lr.set_tolerance(1e-3)
lr.set_max_iter(500)
param_tree_root = ModelSelectionParameters()
z = ModelSelectionParameters("z")
z.build_values(0.0,0.5, R_LINEAR, 0.05)
param_tree_root.append_child(z)
splitting_strategy = StratifiedCrossValidationSplitting(labels, 10)
evaluation_criterium = ROCEvaluation()
cross_validation = CrossValidation(lr, features, labels, splitting_strategy, evaluation_criterium)
model_selection = GridSearchModelSelection(param_tree_root, cross_validation)
#model_selection.io.set_loglevel(MSG_DEBUG)
best_parameters = model_selection.select_model()
cross_validation.evaluate().print_result()
best_parameters.apply_to_machine(lr)
print lr.get_z()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment