Skip to content

Commit

Permalink
Added ReadMe. Fixed typo in partial_dependence.
Browse files Browse the repository at this point in the history
And added more docstring
  • Loading branch information
mmahrouss committed Oct 28, 2019
1 parent 21aac18 commit b080cd2
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 25 deletions.
4 changes: 1 addition & 3 deletions Project.toml
Expand Up @@ -11,11 +11,9 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
julia = "1"

[extras]
# Conda = "8f4d0f93-b110-5947-807f-2305c1781a2d"
RDatasets = "ce6b1742-4840-55fa-b093-852dadbb1d8b"
ScikitLearn = "3646fa90-6ef7-5e7e-9f22-8aca16db6324"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
# PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"

[targets]
test = ["Test", "ScikitLearn", "RDatasets"]#, "Conda", "PyCall"
test = ["Test", "ScikitLearn", "RDatasets"]
54 changes: 50 additions & 4 deletions README.md
@@ -1,6 +1,52 @@
# InterpretMe

[![Build Status](https://travis-ci.com/mmahrouss/InterpretMe.jl.svg?branch=master)](https://travis-ci.com/mmahrouss/InterpretMe.jl)
[![Build Status](https://ci.appveyor.com/api/projects/status/github/mmahrouss/InterpretMe.jl?svg=true)](https://ci.appveyor.com/project/mmahrouss/InterpretMe-jl)
[![Codecov](https://codecov.io/gh/mmahrouss/InterpretMe.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/mmahrouss/InterpretMe.jl)
[![Coveralls](https://coveralls.io/repos/github/mmahrouss/InterpretMe.jl/badge.svg?branch=master)](https://coveralls.io/github/mmahrouss/InterpretMe.jl?branch=master)
[![Build Status](https://travis-ci.com/mmahrouss/InterpretMe.jl.svg?branch=master)](https://travis-ci.com/mmahrouss/InterpretMe.jl) [![Build Status](https://ci.appveyor.com/api/projects/status/github/mmahrouss/InterpretMe.jl?svg=true)](https://ci.appveyor.com/project/mmahrouss/InterpretMe-jl) [![Codecov](https://codecov.io/gh/mmahrouss/InterpretMe.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/mmahrouss/InterpretMe.jl) [![Coveralls](https://coveralls.io/repos/github/mmahrouss/InterpretMe.jl/badge.svg?branch=master)](https://coveralls.io/github/mmahrouss/InterpretMe.jl?branch=master)

InterpretMe is Julia Package aimed at providing interpret-ability tools for Machine Learning models in Julia.

## Installation

```julia
julia>]
pkg> add InterpretMe
```

Please note that the package is still a Work In Progress and has not been registered yet. Thus, for now you should install it as follows:

```julia
julia>]
pkg> add https://github.com/mmahrouss/InterpretMe.jl
```

## Example

First import the package:

```julia
Using InterpretMe
```

Then train a model from [ScikitLearn.jl](https://github.com/cstjean/ScikitLearn.jl)'s examples. We are going to use the [Iris Example](https://github.com/cstjean/ScikitLearn.jl/blob/master/notebooks/Iris.ipynb)

Load the packages and train the model:

```julia
import ScikitLearn
import RDatasets

ScikitLearn.@sk_import linear_model: LogisticRegression

iris = RDatasets.dataset("datasets", "iris")

X = convert(Array, iris[[:SepalLength, :SepalWidth, :PetalLength, :PetalWidth]])
y = convert(Array, iris[:Species])

model = ScikitLearn.fit!(LogisticRegression(), X, y)
```

Now we can calculate the partial_dependance function from InterpretMe.

```julia
pd, vals = partial_dependence(x, [1], x -> ScikitLearn.predict_proba(model,x),
100, false)
```
3 changes: 1 addition & 2 deletions src/InterpretMe.jl
@@ -1,6 +1,5 @@
module InterpretMe

# greet() = print("Hello World!")
include("pdp.jl")
export partial_dependance
export partial_dependence
end # module
13 changes: 8 additions & 5 deletions src/pdp.jl
@@ -1,17 +1,20 @@
using LinearAlgebra
using Statistics
"""
InterpretMe.partial_dependance(data::Array{Any,2},
features::Vector{<:Integer}
,feature::T, estimate_fn, grid_size::Int, return_ice::Bool)
where {T<:AbstractString}
InterpretMe.partial_dependence(data::Array{<:Any,2},
features::Union{<:Integer,Vector{<:Integer}},
estimate_fn, grid_size::Int,
return_ice::Bool)
Calculate the partial dependance of a machine learning model.
`estimate_fn` is a function from the model that generates a vector of predictions from a matrix of inputs.
`feature_names` should be the feature names corresponding to the features in `data`
`return_ice` whether to return the ICE lines.
Returns
`pd` the partial dependancy results
`grid_values` the grid values for all the selected features
"""
function partial_dependance(data::Array{<:Any,2},
function partial_dependence(data::Array{<:Any,2},
features::Union{<:Integer,Vector{<:Integer}},
estimate_fn, grid_size::Int, return_ice::Bool)
# Mainly inspired by Sk-learn's function.
Expand Down
20 changes: 9 additions & 11 deletions test/runtests.jl
@@ -1,14 +1,10 @@
using InterpretMe
# using Conda
using ScikitLearn
using RDatasets
using Test
# import PyCall
# PyCall.pyimport_conda("sklearn", "scikit-learn")
# Conda.add("scikit-learn")
import ScikitLearn
import RDatasets

@sk_import linear_model: LogisticRegression
@sk_import inspection: partial_dependence
ScikitLearn.@sk_import linear_model: LogisticRegression
ScikitLearn.@sk_import inspection: partial_dependence

@testset "InterpretMe.jl" begin
# Write your own tests here.
Expand All @@ -17,11 +13,13 @@ using Test
x = convert(Matrix, iris[!,[:SepalLength,:SepalWidth,
:PetalLength,:PetalWidth ]])
y = convert(Array, iris.Species)
model = fit!(LogisticRegression(), x, y)
model = ScikitLearn.fit!(LogisticRegression(), x, y)
averaged_predictions, values = partial_dependence(model, x, [0],
grid_resolution=100)
pd, vals = partial_dependance(x, [1], x -> predict_proba(model,x),
100, false)
pd, vals = InterpretMe.partial_dependence(x, [1],
x -> ScikitLearn.predict_proba(
model,x),
100, false)
@test all(pd .≈ transpose(averaged_predictions))
end
end

0 comments on commit b080cd2

Please sign in to comment.