How to extract sklearn decision tree rules to pandas boolean conditions?

前端 未结 3 1549
栀梦
栀梦 2020-12-28 17:16

There are so many posts like this about how to extract sklearn decision tree rules but I could not find any about using pandas.

Take this data and model for example,

3条回答
  •  春和景丽
    2020-12-28 17:17

    I figured out a further solution to this problem (a second part to the one posted by vlemaistre) which allows the user to run through any node and subset the data based on the pandas boolean condition.

    node_id = 3
    
    def datatree_path_summarystats(node_id):
        for k, v in paths.items():
            if node_id in v:
                d = k,v
    
        ruleskey = d[0]
        numberofsteps = sum(map(lambda x : x

    This function runs through the paths that contain the node id you are looking for. It will then split the rule based on that number of nodes creating the logic to subset the dataframe based on that one specific node.

提交回复
热议问题