<jupyter_start><jupyter_text>load data<jupyter_code>import sys
sys.path.append('../../')
import json
import pandas as pd
from mlinterpreter.util import preprocess_data
# 读入数据 和 schema
data_path = "../../demo_data/adult.data"
schema_path = "../../demo_data/schema.json"
df = pd.read_csv(data_path, header=None)
df.columns = ["age","workclass","fnlwgt","education","education-num","marital-status","occupation","relationship","race","sex",
                 "capital-gain","capital-loss","hours-per-week","native-country","income"]
with open(schema_path, "r") as f:
    schema = json.load(f)<jupyter_output><empty_output><jupyter_text>preprocess data<jupyter_code># 预处理数据
preprocess_df, preprocess_dict = preprocess_data(df=df, schema=schema, process_label=True)<jupyter_output><empty_output><jupyter_text>build  LGBMClassifier<jupyter_code>from mlinterpreter.model.builder import  build_lgb
import lightgbm
# 构建 lgb模型
# 通过 params 参数修改模型超参数
lgbmodel = build_lgb(df=preprocess_df, schema=schema)<jupyter_output>/home/caihengxing/anaconda3/lib/python3.7/site-packages/lightgbm/basic.py:1551: UserWarning: Using categorical_feature in Dataset.
  warnings.warn('Using categorical_feature in Dataset.')
/home/caihengxing/anaconda3/lib/python3.7/site-packages/lightgbm/basic.py:1555: UserWarning: categorical_feature in Dataset is overridden.
New categorical_feature is ['education', 'marital-status', 'native-country', 'occupation', 'race', 'relationship', 'sex', 'workclass']
  'New categorical_feature is {}'.format(sorted(list(categorical_feature))))<jupyter_text>Global surrogate tree<jupyter_code>from mlinterpreter.surrogate.global_model import SurrogateTree
# 申明 SurrogateTree
tree = SurrogateTree(params={"max_depth":3})
# fit the SurrogateTree with the model
# return with the R2 value
tree.surrogate(model=lgbmodel, df=df, schema=schema, preprocess_dict=preprocess_dict)
# plot the SurrogateTree
tree.plot_tree()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13477366255144033, 'fraction_numerical': 0.00823045267489712, 'mean_word_length': 7.606194690265487, 'pattern_counts': {'":': 1, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '445418', 'license': 'Apache-2.0', 'n_tokens_mistral': 702, 'n_tokens_neox': 679, 'n_words': 114, 'path': 'autox/autox_interpreter/interpreter_demo/global_interpretation/global_surrogate_tree_demo.ipynb', 'repo_name': 'fanghy06/AutoX', 'size': '1944'}