Skip to content

Instantly share code, notes, and snippets.

@hqucms
hqucms / xgboost2tmva.py
Last active March 21, 2024 17:25
Convert xgboost model to TMVA xml format. Not fully tested...
import re
import xml.etree.cElementTree as ET
regex_float_pattern = r'[-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?'
def build_tree(xgtree, base_xml_element, var_indices):
parent_element_dict = {'0':base_xml_element}
pos_dict = {'0':'s'}
for line in xgtree.split('\n'):
if not line: continue
if ':leaf=' in line: