Get Data Table from iml FeatureEffect Object

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Get Data Table from iml FeatureEffect Object

Sparks, John James
Hi R-Helpers,

I have recently started working with the iml package (Interpretable Machine Learning)  and its associated material, which I generally find very helpful.

I want to recover some values out of the FeatureEffect Object created by this library, but the form of the object is completely foreign to me.

As a reproducible example:


set.seed(42)​
library("iml")​
library("randomForest")​
data("Boston", package  = "MASS")​
rf = randomForest(medv ~ ., data = Boston, ntree = 50)​

X = Boston[which(names(Boston) != "medv")]​
predictor = Predictor$new(rf, data = X, y = Boston$medv)​
imp = FeatureImp$new(predictor, loss = "mae")​
eff = FeatureEffect$new(predictor, feature = "rm") ​
eff


Interpretation method:  FeatureEffect
features: rm[numerical]
grid size: 20

Analysed predictor:
Prediction task: unknown


Analysed data:
Sampling from data.frame with 506 rows and 13 columns.

Head of results:
       .ale .type    rm
1 -2.150574   ale 3.561
2 -2.610528   ale 5.304
3 -2.338677   ale 5.593
4 -2.265673   ale 5.709
5 -2.142912   ale 5.837
6 -2.085899   ale 5.885

How can I refer to and get ahold of the table of 6 records above?

I tried str(eff) and class(eff), but I am not familiar with the structure of the object(s).

Would someone please tell me how to get inside the eff object, or point me to a reference as to what the class or structure of the object is?

Thanks.
--John Sparks

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Get Data Table from iml FeatureEffect Object

Bert Gunter-2
?str

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Tue, Mar 17, 2020 at 12:19 PM Sparks, John <[hidden email]> wrote:

> Hi R-Helpers,
>
> I have recently started working with the iml package (Interpretable
> Machine Learning)  and its associated material, which I generally find very
> helpful.
>
> I want to recover some values out of the FeatureEffect Object created by
> this library, but the form of the object is completely foreign to me.
>
> As a reproducible example:
>
>
> set.seed(42)​
> library("iml")​
> library("randomForest")​
> data("Boston", package  = "MASS")​
> rf = randomForest(medv ~ ., data = Boston, ntree = 50)​
> ​
> X = Boston[which(names(Boston) != "medv")]​
> predictor = Predictor$new(rf, data = X, y = Boston$medv)​
> imp = FeatureImp$new(predictor, loss = "mae")​
> eff = FeatureEffect$new(predictor, feature = "rm") ​
> eff
>
>
> Interpretation method:  FeatureEffect
> features: rm[numerical]
> grid size: 20
>
> Analysed predictor:
> Prediction task: unknown
>
>
> Analysed data:
> Sampling from data.frame with 506 rows and 13 columns.
>
> Head of results:
>        .ale .type    rm
> 1 -2.150574   ale 3.561
> 2 -2.610528   ale 5.304
> 3 -2.338677   ale 5.593
> 4 -2.265673   ale 5.709
> 5 -2.142912   ale 5.837
> 6 -2.085899   ale 5.885
>
> How can I refer to and get ahold of the table of 6 records above?
>
> I tried str(eff) and class(eff), but I am not familiar with the structure
> of the object(s).
>
> Would someone please tell me how to get inside the eff object, or point me
> to a reference as to what the class or structure of the object is?
>
> Thanks.
> --John Sparks
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Get Data Table from iml FeatureEffect Object

Sparks, John James
From my previous email:

"I tried str(eff) and class(eff), but I am not familiar with the structure of the object(s)."

--JJS

________________________________
From: Bert Gunter <[hidden email]>
Sent: Tuesday, March 17, 2020 2:22 PM
To: Sparks, John <[hidden email]>
Cc: [hidden email] <[hidden email]>; [hidden email] <[hidden email]>
Subject: Re: [R] Get Data Table from iml FeatureEffect Object

?str

Bert Gunter

"The trouble with having an open mind is that people keep coming along and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Tue, Mar 17, 2020 at 12:19 PM Sparks, John <[hidden email]<mailto:[hidden email]>> wrote:
Hi R-Helpers,

I have recently started working with the iml package (Interpretable Machine Learning)  and its associated material, which I generally find very helpful.

I want to recover some values out of the FeatureEffect Object created by this library, but the form of the object is completely foreign to me.

As a reproducible example:


set.seed(42)​
library("iml")​
library("randomForest")​
data("Boston", package  = "MASS")​
rf = randomForest(medv ~ ., data = Boston, ntree = 50)​

X = Boston[which(names(Boston) != "medv")]​
predictor = Predictor$new(rf, data = X, y = Boston$medv)​
imp = FeatureImp$new(predictor, loss = "mae")​
eff = FeatureEffect$new(predictor, feature = "rm") ​
eff


Interpretation method:  FeatureEffect
features: rm[numerical]
grid size: 20

Analysed predictor:
Prediction task: unknown


Analysed data:
Sampling from data.frame with 506 rows and 13 columns.

Head of results:
       .ale .type    rm
1 -2.150574   ale 3.561
2 -2.610528   ale 5.304
3 -2.338677   ale 5.593
4 -2.265673   ale 5.709
5 -2.142912   ale 5.837
6 -2.085899   ale 5.885

How can I refer to and get ahold of the table of 6 records above?

I tried str(eff) and class(eff), but I am not familiar with the structure of the object(s).

Would someone please tell me how to get inside the eff object, or point me to a reference as to what the class or structure of the object is?

Thanks.
--John Sparks

        [[alternative HTML version deleted]]

______________________________________________
[hidden email]<mailto:[hidden email]> mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Get Data Table from iml FeatureEffect Object

Bert Gunter-2
In reply to this post by Bert Gunter-2
that is, read ?str carefully.

data structures are fundamental to any programming language, so if you
really aren't getting it, that's a signal that you need to spend some time
with R tutorials. The R language Definition manual is a more comprehensive
but of course more difficult resource to learn about such matters. I find
it readable, however. Others may not.

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Tue, Mar 17, 2020 at 12:22 PM Bert Gunter <[hidden email]> wrote:

> ?str
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along and
> sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
> On Tue, Mar 17, 2020 at 12:19 PM Sparks, John <[hidden email]> wrote:
>
>> Hi R-Helpers,
>>
>> I have recently started working with the iml package (Interpretable
>> Machine Learning)  and its associated material, which I generally find very
>> helpful.
>>
>> I want to recover some values out of the FeatureEffect Object created by
>> this library, but the form of the object is completely foreign to me.
>>
>> As a reproducible example:
>>
>>
>> set.seed(42)​
>> library("iml")​
>> library("randomForest")​
>> data("Boston", package  = "MASS")​
>> rf = randomForest(medv ~ ., data = Boston, ntree = 50)​
>> ​
>> X = Boston[which(names(Boston) != "medv")]​
>> predictor = Predictor$new(rf, data = X, y = Boston$medv)​
>> imp = FeatureImp$new(predictor, loss = "mae")​
>> eff = FeatureEffect$new(predictor, feature = "rm") ​
>> eff
>>
>>
>> Interpretation method:  FeatureEffect
>> features: rm[numerical]
>> grid size: 20
>>
>> Analysed predictor:
>> Prediction task: unknown
>>
>>
>> Analysed data:
>> Sampling from data.frame with 506 rows and 13 columns.
>>
>> Head of results:
>>        .ale .type    rm
>> 1 -2.150574   ale 3.561
>> 2 -2.610528   ale 5.304
>> 3 -2.338677   ale 5.593
>> 4 -2.265673   ale 5.709
>> 5 -2.142912   ale 5.837
>> 6 -2.085899   ale 5.885
>>
>> How can I refer to and get ahold of the table of 6 records above?
>>
>> I tried str(eff) and class(eff), but I am not familiar with the structure
>> of the object(s).
>>
>> Would someone please tell me how to get inside the eff object, or point
>> me to a reference as to what the class or structure of the object is?
>>
>> Thanks.
>> --John Sparks
>>
>>         [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Get Data Table from iml FeatureEffect Object

Jeff Newmiller
OP may find the help page [1] informative as to which fields are which. I have never used the imp package. Note that the DESCRIPTION file indicates that this package uses the R6 object system rather than the more typical S3 or S4.

[1] https://rdrr.io/cran/iml/man/FeatureEffect.html

On March 17, 2020 12:26:33 PM PDT, Bert Gunter <[hidden email]> wrote:

>that is, read ?str carefully.
>
>data structures are fundamental to any programming language, so if you
>really aren't getting it, that's a signal that you need to spend some
>time
>with R tutorials. The R language Definition manual is a more
>comprehensive
>but of course more difficult resource to learn about such matters. I
>find
>it readable, however. Others may not.
>
>Bert Gunter
>
>"The trouble with having an open mind is that people keep coming along
>and
>sticking things into it."
>-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
>On Tue, Mar 17, 2020 at 12:22 PM Bert Gunter <[hidden email]>
>wrote:
>
>> ?str
>>
>> Bert Gunter
>>
>> "The trouble with having an open mind is that people keep coming
>along and
>> sticking things into it."
>> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>>
>>
>> On Tue, Mar 17, 2020 at 12:19 PM Sparks, John <[hidden email]>
>wrote:
>>
>>> Hi R-Helpers,
>>>
>>> I have recently started working with the iml package (Interpretable
>>> Machine Learning)  and its associated material, which I generally
>find very
>>> helpful.
>>>
>>> I want to recover some values out of the FeatureEffect Object
>created by
>>> this library, but the form of the object is completely foreign to
>me.
>>>
>>> As a reproducible example:
>>>
>>>
>>> set.seed(42)​
>>> library("iml")​
>>> library("randomForest")​
>>> data("Boston", package  = "MASS")​
>>> rf = randomForest(medv ~ ., data = Boston, ntree = 50)​
>>> ​
>>> X = Boston[which(names(Boston) != "medv")]​
>>> predictor = Predictor$new(rf, data = X, y = Boston$medv)​
>>> imp = FeatureImp$new(predictor, loss = "mae")​
>>> eff = FeatureEffect$new(predictor, feature = "rm") ​
>>> eff
>>>
>>>
>>> Interpretation method:  FeatureEffect
>>> features: rm[numerical]
>>> grid size: 20
>>>
>>> Analysed predictor:
>>> Prediction task: unknown
>>>
>>>
>>> Analysed data:
>>> Sampling from data.frame with 506 rows and 13 columns.
>>>
>>> Head of results:
>>>        .ale .type    rm
>>> 1 -2.150574   ale 3.561
>>> 2 -2.610528   ale 5.304
>>> 3 -2.338677   ale 5.593
>>> 4 -2.265673   ale 5.709
>>> 5 -2.142912   ale 5.837
>>> 6 -2.085899   ale 5.885
>>>
>>> How can I refer to and get ahold of the table of 6 records above?
>>>
>>> I tried str(eff) and class(eff), but I am not familiar with the
>structure
>>> of the object(s).
>>>
>>> Would someone please tell me how to get inside the eff object, or
>point
>>> me to a reference as to what the class or structure of the object
>is?
>>>
>>> Thanks.
>>> --John Sparks
>>>
>>>         [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>
>
> [[alternative HTML version deleted]]
>
>______________________________________________
>[hidden email] mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

--
Sent from my phone. Please excuse my brevity.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Get Data Table from iml FeatureEffect Object

Jeff Newmiller
Also, R6 is based on R environments... you can access the methods and fields like S3 (eff$field) and you can list what methods and fields the object has (ls(envir=eff)).

On March 17, 2020 3:13:22 PM PDT, Jeff Newmiller <[hidden email]> wrote:

>OP may find the help page [1] informative as to which fields are which.
>I have never used the imp package. Note that the DESCRIPTION file
>indicates that this package uses the R6 object system rather than the
>more typical S3 or S4.
>
>[1] https://rdrr.io/cran/iml/man/FeatureEffect.html
>
>On March 17, 2020 12:26:33 PM PDT, Bert Gunter <[hidden email]>
>wrote:
>>that is, read ?str carefully.
>>
>>data structures are fundamental to any programming language, so if you
>>really aren't getting it, that's a signal that you need to spend some
>>time
>>with R tutorials. The R language Definition manual is a more
>>comprehensive
>>but of course more difficult resource to learn about such matters. I
>>find
>>it readable, however. Others may not.
>>
>>Bert Gunter
>>
>>"The trouble with having an open mind is that people keep coming along
>>and
>>sticking things into it."
>>-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>>
>>
>>On Tue, Mar 17, 2020 at 12:22 PM Bert Gunter <[hidden email]>
>>wrote:
>>
>>> ?str
>>>
>>> Bert Gunter
>>>
>>> "The trouble with having an open mind is that people keep coming
>>along and
>>> sticking things into it."
>>> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>>>
>>>
>>> On Tue, Mar 17, 2020 at 12:19 PM Sparks, John <[hidden email]>
>>wrote:
>>>
>>>> Hi R-Helpers,
>>>>
>>>> I have recently started working with the iml package (Interpretable
>>>> Machine Learning)  and its associated material, which I generally
>>find very
>>>> helpful.
>>>>
>>>> I want to recover some values out of the FeatureEffect Object
>>created by
>>>> this library, but the form of the object is completely foreign to
>>me.
>>>>
>>>> As a reproducible example:
>>>>
>>>>
>>>> set.seed(42)​
>>>> library("iml")​
>>>> library("randomForest")​
>>>> data("Boston", package  = "MASS")​
>>>> rf = randomForest(medv ~ ., data = Boston, ntree = 50)​
>>>> ​
>>>> X = Boston[which(names(Boston) != "medv")]​
>>>> predictor = Predictor$new(rf, data = X, y = Boston$medv)​
>>>> imp = FeatureImp$new(predictor, loss = "mae")​
>>>> eff = FeatureEffect$new(predictor, feature = "rm") ​
>>>> eff
>>>>
>>>>
>>>> Interpretation method:  FeatureEffect
>>>> features: rm[numerical]
>>>> grid size: 20
>>>>
>>>> Analysed predictor:
>>>> Prediction task: unknown
>>>>
>>>>
>>>> Analysed data:
>>>> Sampling from data.frame with 506 rows and 13 columns.
>>>>
>>>> Head of results:
>>>>        .ale .type    rm
>>>> 1 -2.150574   ale 3.561
>>>> 2 -2.610528   ale 5.304
>>>> 3 -2.338677   ale 5.593
>>>> 4 -2.265673   ale 5.709
>>>> 5 -2.142912   ale 5.837
>>>> 6 -2.085899   ale 5.885
>>>>
>>>> How can I refer to and get ahold of the table of 6 records above?
>>>>
>>>> I tried str(eff) and class(eff), but I am not familiar with the
>>structure
>>>> of the object(s).
>>>>
>>>> Would someone please tell me how to get inside the eff object, or
>>point
>>>> me to a reference as to what the class or structure of the object
>>is?
>>>>
>>>> Thanks.
>>>> --John Sparks
>>>>
>>>>         [[alternative HTML version deleted]]
>>>>
>>>> ______________________________________________
>>>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>>> PLEASE do read the posting guide
>>>> http://www.R-project.org/posting-guide.html
>>>> and provide commented, minimal, self-contained, reproducible code.
>>>>
>>>
>>
>> [[alternative HTML version deleted]]
>>
>>______________________________________________
>>[hidden email] mailing list -- To UNSUBSCRIBE and more, see
>>https://stat.ethz.ch/mailman/listinfo/r-help
>>PLEASE do read the posting guide
>>http://www.R-project.org/posting-guide.html
>>and provide commented, minimal, self-contained, reproducible code.

--
Sent from my phone. Please excuse my brevity.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.