如何为多类分类提取随机森林树规则?

时间:2019-06-27 12:46:00

标签: python machine-learning scikit-learn random-forest

嗨,如果要进行多类分类,我想从一棵树中提取规则

Content-Type


enter image description here

1 个答案:

答案 0 :(得分:0)

请检查以下代码。它似乎有效。只有一个小变化

cat screen.py

def screen_print(string_to_term):
    #get the tty of the parent process using shell commands , how to do it using python
    cmd="ps -eaf |awk -v pid=$$ '$2==pid{print \"/dev/\"$6}'"
    output,error = subprocess.Popen(cmd, shell=True, executable="/bin/bash", stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
    with open(output.rstrip()) as fd:
        tty = os.ttyname(fd.fileno())

    with open(tty, 'wb') as terminal:
        terminal.write(string_to_term)



screen_print('This message is coming from python code\n')