Skip to content

Instantly share code, notes, and snippets.

@betatim
Created January 30, 2015 13:47
Show Gist options
  • Save betatim/fe991eead446875f07e3 to your computer and use it in GitHub Desktop.
Save betatim/fe991eead446875f07e3 to your computer and use it in GitHub Desktop.
Basic sklearn with ROOT file input
import numpy as np
from sklearn.ensemble import RandomForestClassifier
from sklearn.cross_calidation import train_test_split
from root_numpy import root2array
signal = root2array("MySignalFile.root",
"MyDecayTree",
["names", "of", "branches", "to", "use",
"for", "classifying"])
backgr = root2array("MyBackgrondFile.root",
"MyDecayTree",
["names", "of", "branches", "to", "use",
"for", "classifying"])
X = np.concatenate((signal, backgr))
y = np.concatenate((np.ones(signal.shape[1]), np.zeros(backgr.shape[1])))
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42)
tree = RandomForestClassifier()
tree.fit(X_train, y_train)
# do what ever you have to do
# for some plotting see: http://betatim.github.io/posts/matching-machine-learning/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment