Skip to content

Commit

Permalink
Merge pull request #6 from christophM/cleanup
Browse files Browse the repository at this point in the history
Rework API and prepare CRAN release
  • Loading branch information
christophM authored Mar 4, 2018
2 parents 1b84567 + 66c5222 commit 971530a
Show file tree
Hide file tree
Showing 94 changed files with 3,671 additions and 3,489 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
^\.Rproj\.user$
README.*
README_files
cran-comments.md
framework.jpg
.travis.yml
Makefile
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
*.swp
iml.Rcheck
..Rcheck
README.html
notes.md

19 changes: 8 additions & 11 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
Package: iml
Type: Package
Title: Methods for interpretable machine learning
Version: 0.1
Date: 2017-11-30
Author: Christoph Molnar
Title: Interpretable Machine Learning
Version: 0.2
Date: 2018-03-04
Authors@R: c(person(given = "Christoph", family = "Molnar",
role = c("aut", "cre"), email = "[email protected]"))
Maintainer: Christoph Molnar <[email protected]>
Description: Model-agnostic interpretability methods for machine learning models.
The iml package provides you with tools to analyse and explain the behaviour and prediction of black box machine learning models.
Implemented tools are: partial dependence plots, local models (LIME), feature importance measure and many more.
Description:The iml package provides model-agnostic interpretability methods to
analyse and explain the behaviour and predictions of any black box machine learning model.
Imports: R6,
checkmate,
dplyr,
Expand All @@ -18,16 +16,15 @@ Imports: R6,
partykit,
glmnet,
Metrics,
data.table,
mlr
data.table
Suggests: randomForest,
gower,
testthat,
rpart,
MASS,
caret,
e1071,
lime
lime,
mlr
License: MIT + file LICENSE
Roxygen: list(wrap = FALSE)
RoxygenNote: 6.0.1
23 changes: 2 additions & 21 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,2 @@
MIT License

Copyright (c) [year] [fullname]

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
YEAR: 2018
COPYRIGHT HOLDER: Christoph Molnar
21 changes: 10 additions & 11 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# Generated by roxygen2: do not edit by hand

S3method(plot,Importance)
S3method(predict,LIME)
S3method(plot,FeatureImp)
S3method(predict,LocalModel)
S3method(predict,TreeSurrogate)
export(feature.imp)
export(ice)
export(lime)
export(pdp)
export(shapley)
export(tree.surrogate)
export(FeatureImp)
export(Ice)
export(LocalModel)
export(PartialDependence)
export(Predictor)
export(Shapley)
export(TreeSurrogate)
import(Metrics)
import(R6)
import(checkmate)
Expand All @@ -21,9 +22,7 @@ importFrom(dplyr,left_join)
importFrom(dplyr,one_of)
importFrom(dplyr,summarise)
importFrom(glmnet,glmnet)
importFrom(mlr,getPredictionProbabilities)
importFrom(mlr,getPredictionResponse)
importFrom(mlr,getTaskType)
importFrom(stats,model.matrix)
importFrom(stats,predict)
importFrom(tidyr,gather)
importFrom(utils,methods)
11 changes: 11 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# iml 0.2
* The API has been reworked:
* User directly interacts with R6 classes (`pdp()` is now `PartialDependence$new()`).
* User has to wrap the machine learning model with `Predictor$new()`.
* New data points in `Shapley` and `LocalModel` can be set with `$explain()`.
* `Lime` has been renamed to `LocalModel`.
* Plots have been improved.
* Documentation has been improved.

# iml 0.1
Initial release
34 changes: 21 additions & 13 deletions R/DataSampler.R → R/Data.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
DataSampler = R6::R6Class('DataSampler',
Data = R6::R6Class("Data",
public = list(
X = NULL,
y = NULL,
Expand All @@ -8,36 +8,44 @@ DataSampler = R6::R6Class('DataSampler',
n.features = NULL,
prob = NULL,
sample = function(n=100, replace = TRUE, prob = NULL, get.y=FALSE) {
if(is.null(prob) & !is.null(self$prob)) {
if (is.null(prob) & !is.null(self$prob)) {
prob = self$prob
}
indices = sample.int(private$nrows, size = n,
replace = replace, prob = prob)
if(get.y){
if (get.y) {
cbind(self$X[indices,], self$y[indices,])
} else {
self$X[indices, ]
}
},
get.x = function(...){
get.x = function(...) {
self$X
},
get.xy = function(...){
get.xy = function(...) {
cbind(self$X, self$y)
},
print = function(){
print = function() {
cat("Sampling from data.frame with", nrow(self$X), "rows and", ncol(self$X), "columns.")
},
initialize = function(X, y = NULL, prob = NULL){
initialize = function(X, y = NULL, prob = NULL) {
assertDataFrame(X, all.missing = FALSE)
assert_named(X)
assertDataFrame(y, all.missing = FALSE, null.ok = TRUE)
assertNamed(X)
self$X = X
if(!missing(y)){
if (length(y) == 1 & is.character(y)) {
assert_true(y %in% names(X))
self$y = X[y]
self$y.names = y
self$X = self$X[setdiff(colnames(X), self$y.names)]
} else if (inherits(y, "data.frame")) {
assertDataFrame(y, all.missing = FALSE, null.ok = TRUE, nrows = nrow(X))
self$y = y
self$y.names = names(y)
assert_true(nrow(X)==nrow(y))
}
self$y.names = colnames(self$y)
} else if (is.vector(y) | is.factor(y)) {
assert_vector(y, any.missing = FALSE, null.ok = TRUE, len = nrow(X))
self$y = data.frame(..y = y)
self$y.names = colnames(self$y)
}
self$prob = prob
self$feature.types = get.feature.type(unlist(lapply(X, class)))
self$feature.names = colnames(X)
Expand Down
130 changes: 0 additions & 130 deletions R/Experiment.R

This file was deleted.

Loading

0 comments on commit 971530a

Please sign in to comment.