You can do some regexes for the tree in string form directly to modify the
output, then write out the modified dotfile. As an example (from some code
I recently did):

def customize_graphviz(string, true="Output = True" , false="Output =
False"):
    import re
    string = re.sub(r'entropy = [0-9]+\.+[0-9]+\\n', '', string)
    #string = re.sub(r'(\s)?samples = [0-9]+(\\n)?', '', string)
    #Assumes array is [False True]
    string = re.sub(r'value = \[\s+0.*?\]', repr(true), string)
    string = re.sub(r'value = \[\s+[1-9].*?\]', repr(false), string)
    return string

import StringIO
from IPython.display import Image
from sklearn import tree
from pydot import graph_from_dot_data

dt.fit(X,y)
tree.export_graphviz(dt, close=True)
dot_data = StringIO.StringIO()
tree.export_graphviz(dt, out_file=dot_data, feature_names=list(X.columns))
dot_str = customize_graphviz(dot_data.getvalue(), true="Total failure",
false="Partial failure")
graph = graph_from_dot_data(dot_str)
Image(graph.create_png())



On Thu, Sep 12, 2013 at 7:32 PM, yegle <cnye...@gmail.com> wrote:

> Thank you Olivier, this does solves my problem. Although not very perfect.
>
> Now the node was marked with "humidity=high <= 0.5000". It'll be great if
> I can remove the "<=0.5000" part.
>
> --
> yegle
> http://about.me/yegle
>
> On Sep 12, 2013, at 3:16 AM, Olivier Grisel <olivier.gri...@ensta.org>
> wrote:
>
> You can pass a feature_names param to the tree export method. To get the
> vectorized feature names, use the  vectorizer.get_feature_names() method.
>
>
>
>
> ------------------------------------------------------------------------------
> How ServiceNow helps IT people transform IT departments:
> 1. Consolidate legacy IT systems to a single system of record for IT
> 2. Standardize and globalize service processes across IT
> 3. Implement zero-touch automation to replace manual, redundant tasks
> http://pubads.g.doubleclick.net/gampad/clk?id=51271111&iu=/4140/ostg.clktrk
> _______________________________________________
> Scikit-learn-general mailing list
> Scikit-learn-general@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/scikit-learn-general
>
>
------------------------------------------------------------------------------
How ServiceNow helps IT people transform IT departments:
1. Consolidate legacy IT systems to a single system of record for IT
2. Standardize and globalize service processes across IT
3. Implement zero-touch automation to replace manual, redundant tasks
http://pubads.g.doubleclick.net/gampad/clk?id=51271111&iu=/4140/ostg.clktrk
_______________________________________________
Scikit-learn-general mailing list
Scikit-learn-general@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/scikit-learn-general

Reply via email to