[scikit-learn] tree visualization with class names in leaves
Piotr Bialecki
piotr.bialecki at hotmail.de
Tue Oct 25 05:32:21 EDT 2016
Hi Sanant,
the values represent the thresholds at the current feature (node), which are used to classify the next sample.
You can see an example here:
http://scikit-learn.org/stable/modules/tree.html
The first node uses the feature "petal length (cm)" with a threshold of 2.45.
If your future sample as a petal length <= 2.45cm it will be pushed into the left branch and therefore will be classifies as class = setosa.
However, if the petal length is > 2.45cm, it will be pushed into the right branch and the next node (feature) is evalueted.
I hope I understood your question correct.
Best regards,
Piotr
On 25.10.2016 08:41, Startup Hire wrote:
Hi all,
Thanks for the suggestion.
I have a related question on tree visualization
I have 2 classes to predict: 0 and 1 (it comes up as a numeric field when I load the dataset)
I have given the class_names as "NotPresent" and "Ispresent" which I believe it will map to 0 and 1. is that correct?
How do I interpret the nodes and value present in each nodes in the accompanying diagram?
Regards,
Sanant
On Mon, Oct 24, 2016 at 9:17 PM, Sebastian Raschka <<mailto:se.raschka at gmail.com>se.raschka at gmail.com<mailto:se.raschka at gmail.com>> wrote:
Hi, Greg,
if you provide the `class_names` argument, a “class” label of the majority class will be added at the bottom of each node. For instance, if you have the Iris dataset, with class labels 0, 1, 2, you can provide the `class_names` as ['setosa', 'versicolor', 'virginica’], where 0 -> ‘setosa’, 1 -> ‘versicolor’, 2 -> ‘virginica’.
Best,
Sebastian
> On Oct 24, 2016, at 10:18 AM, greg g <<mailto:greg315 at hotmail.fr>greg315 at hotmail.fr<mailto:greg315 at hotmail.fr>> wrote:
>
> bLaf1ox-forefront-antispam-report: EFV:NLI; SFV:NSPM; SFS:(10019020)(98900003);
> DIR:OUT; SFP:1102; SCL:1; SRVR:DB5EUR03HT168;
> H:DB3PR04MB0780.eurprd04.prod.outlook.com<http://DB3PR04MB0780.eurprd04.prod.outlook.com>; FPR:; SPF:None; LANG:en;
> x-ms-office365-filtering-correlation-id: 319900b9-973c-49bb-8e9a-08d3fc1895c4
> x-microsoft-antispam: UriScan:; BCL:0; PCL:0;
> RULEID:(1601124038)(1603103081)(1601125047); SRVR:DB5EUR03HT168;
> x-exchange-antispam-report-cfa-test: BCL:0; PCL:0;
> RULEID:(432015012)(82015046); SRVR:DB5EUR03HT168; BCL:0; PCL:0; RULEID:;
> SRVR:DB5EUR03HT168;
> x-forefront-prvs: 0105DAA385
> X-OriginatorOrg: outlook.com<http://outlook.com>
> X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Oct 2016 14:18:11.0102 (UTC)
> X-MS-Exchange-CrossTenant-fromentityheader: Internet
> X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa
> X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB5EUR03HT168
>
>
> Hi,
> I just begin with scikit-learn and would like to visualize a classification tree with class names displayed in the leaves as shown in the SCIKITLEARN.TREE documentation http://scikit-learn.org/stable/modules/tree.html where we find class=’virginica’ etc…
> I made a tree providing a 2D array X (n1 samples , n2 features) and 1D array Y (n1 corresponding classes ) such that Y(i) is the class of the sample X(i, …)
> After that I have correct predictions using predict()
> Then I use the function
> export_graphviz(clf, out_file=dot_data,feature_names=FEATURES)
> with FEATURES being the array of my n2 features names in the same order as in X
> I obtain the tree .png but can’t find a way to have the correct class names in the leaves…
> In export_graphviz() should I use the class_names optional parameter and how ?
> Thanks for any help
>
> Gregory, Toulouse FRANCE
>
>
>
> _______________________________________________
> scikit-learn mailing list
> scikit-learn at python.org<mailto:scikit-learn at python.org>
> https://mail.python.org/mailman/listinfo/scikit-learn
_______________________________________________
scikit-learn mailing list
scikit-learn at python.org<mailto:scikit-learn at python.org>
https://mail.python.org/mailman/listinfo/scikit-learn
_______________________________________________
scikit-learn mailing list
scikit-learn at python.org<mailto:scikit-learn at python.org>
https://mail.python.org/mailman/listinfo/scikit-learn
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scikit-learn/attachments/20161025/e8657ada/attachment-0001.html>
More information about the scikit-learn
mailing list