如何在python中解释sklearn的descision树结果

时间:2017-08-03 01:58:28

标签: python scikit-learn decision-tree

  1. 环境: win10,python3,sklearn-0.18.2
  2. 问题描述: 我使用一个变量'province_area'来预测一个人的好坏。考虑变量'province_area'是分类特征,所以使用'DictVectorizer''fit_transform'来处理它。但是在生成树之后,标签“'province_area = **'< = 0.5”中有一个小红色方块。请点击链接获取图表。你能帮我告诉我如何知道红场的实际价值吗?
  3. 以下代码

    from pandas import Series,DataFrame
    from sklearn.feature_extraction import DictVectorizer
    vec = DictVectorizer()
    dict_X_train = x.to_dict(orient='records')
    x_train =vec.fit_transform(dict_X_train).toarray()
    X_train, X_test, y_train, y_test = train_test_split(x_train, y, test_size = 0.3, random_state = 100)
    clf = clf.fit(X_train, y_train)
    
    import pydotplus
    from IPython.display import Image  
    
    dot_data = tree.export_graphviz(clf, out_file=None,
                         feature_names=vec.get_feature_names(),  
                         filled=True, rounded=True, proportion=True,   
                         special_characters=False)  
    graph = pydotplus.graph_from_dot_data(dot_data)  
    Image(graph.create_png())
    

    the decision tree graph

0 个答案:

没有答案