zoukankan      html  css  js  c++  java
  • 如何统计随机森林节点数

    from sklearn.ensemble import RandomForestClassifier
    from sklearn.datasets import make_classification
    X, y = make_classification(n_samples=1000, n_features=4,
                                n_informative=2, n_redundant=0,
                                random_state=0, shuffle=False)
    rf = RandomForestClassifier(max_depth=2, random_state=0)
    rf.fit(X, y)
    print(rf.predict([[0, 0, 0, 0]]))
    print(rf.get_params())
    
    
    # Import tools needed for visualization
    from sklearn.tree import export_graphviz
    import pydot
    # Pull out one tree from the forest
    tree = rf.estimators_[5]
    # Import tools needed for visualization
    from sklearn.tree import export_graphviz
    import pydot
    # Pull out one tree from the forest
    tree = rf.estimators_[5]
    feature_list = ["feature1", "feature2", "feature3", "feature4"]
    # Export the image to a dot file
    export_graphviz(tree, out_file = 'tree.dot', feature_names = feature_list, rounded = True, precision = 1)
    # Use dot file to create a graph
    (graph, ) = pydot.graph_from_dot_file('tree.dot')
    # Write graph to a png file
    graph.write_png('tree.png')
    

      

  • 相关阅读:
    C#几个经常用到的字符串的截取
    写入Log错误日志
    AES 加密与解密
    支付宝小额免密支付和代扣区别:原来如此
    Sql server --触发器
    yum、ip、等命令无法不全子命令解决
    3、VNC
    6、DHCP
    2、OpenSsh
    VIM的使用
  • 原文地址:https://www.cnblogs.com/bonelee/p/13720965.html
Copyright © 2011-2022 走看看