Very nice! Thanks to both of you, Jacob and Andreas!

Andreas, yes, I'm interested in all leafs. The additional Pandas query done
on each leaf node is a further check to inspect whether this leaf node can
be of interest or not.

Binary classification for example, fraud detection to be more specific, we
can set up sample_weight based on the order amount in the first run, to
find those large-sale segments. But we don't want a rule that decline too
many good orders in the meantime. That means, we want to minimize both the
number and amount of good samples in each leaf node. This job seems cannot
be done in the current decisionTree implementation. That's why we need to
fire a further Pandas query to do this job.

Any comments?

Best,
Rex


On Tue, Aug 18, 2015 at 9:23 AM, Jacob Schreiber <jmschreibe...@gmail.com>
wrote:

> There is no code to do it automatically, but you can use the following to
> get array of thresholds:
>
> ```
> clf = DecisionTreeClassifier()
> clf.fit( datums, targets )
> clf.tree_.thresholds
> ```
>
> The full list of attributes you can call are (feature, threshold,
> impurity, n_node_samples, weighted_n_node_samples, value (the prediction),
> children_left, children_right).
>
> Does this help?
>
>
>
> On Tue, Aug 18, 2015 at 7:53 AM, Andreas Mueller <t3k...@gmail.com> wrote:
>
>> I'm not aware of any ready-made code. But you can just get the boolean
>> matrix by using ``apply`` and a one-hot encoder.
>> Why are you interested in a single leave? the query seems to be able to
>> return "only" a single boolean.
>> It is probably more efficient to traverse the full tree for each data
>> point if you are interested in all the leafs.
>>
>>
>> On 08/18/2015 11:39 AM, Rex X wrote:
>>
>> Hi everyone,
>>
>> Is it possible to extract the decision tree rule associated with each
>> leaf node into a Pandas Dataframe query
>> <http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.query.html>?
>> So that one can view the corresponding Dataframe content by feeding in the
>> decision rule.
>>
>> Best,
>> Rex
>>
>>
>> ------------------------------------------------------------------------------
>>
>>
>>
>> _______________________________________________
>> Scikit-learn-general mailing 
>> listScikit-learn-general@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/scikit-learn-general
>>
>>
>>
>>
>> ------------------------------------------------------------------------------
>>
>> _______________________________________________
>> Scikit-learn-general mailing list
>> Scikit-learn-general@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/scikit-learn-general
>>
>>
>
>
> ------------------------------------------------------------------------------
>
> _______________________________________________
> Scikit-learn-general mailing list
> Scikit-learn-general@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/scikit-learn-general
>
>
------------------------------------------------------------------------------
_______________________________________________
Scikit-learn-general mailing list
Scikit-learn-general@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/scikit-learn-general

Reply via email to