Git Product home page Git Product logo

Comments (5)

OperaMagistris avatar OperaMagistris commented on May 22, 2024 1

Oh you are fast...! Your proposition is not far from a solution that i was trying since a few hours.

But the plot part seems to not work (the neural network model is flat as the variably "Y" is missing in ex_nn):

set.seed(13)
N <- 250
X1 <- runif(N)
X2 <- runif(N)
X3 <- runif(N)
X4 <- runif(N)
X5 <- runif(N)

f <- function(x1, x2, x3, x4, x5) {
((x1-0.5)2)^2-0.5 + sin(x210) + x3^6 + (x4-0.5)2 + abs(2x5-1)
}
y <- f(X1, X2, X3, X4, X5)

library(randomForest)
library(DALEX)
library(e1071)
library(rms)
library(neuralnet)

df <- data.frame(y, X1, X2, X3, X4, X5)

model_rf<-randomForest(y~., df)
model_svm<-svm(y~., df)
model_lm<-lm(y~., df)
model_nn<-neuralnet(y~X1+X2+X3+X4+X5,df,hidden=1)

dd <- datadist(df)
options(datadist="dd")
model_rms <- ols(y ~ rcs(X1) + rcs(X2) + rcs(X3) + rcs(X4) + rcs(X5), df)

ex_rf<-explain(model_rf)
ex_svm<-explain(model_svm)
ex_lm<-explain(model_lm)
ex_nn<-explain(model_nn,data = df[, -1],y = df[, 1],predict_function = function(x, y) compute(x, y)$net.result)
ex_rms<-explain(model_rms, label = "rms", data = df[, -1], y = df$y)
ex_tr<-explain(model_lm, data = df[,-1],
predict_function = function(m, x) f(x[,1], x[,2], x[,3], x[,4], x[,5]),
label = "True Model")

library(ggplot2)
plot(single_variable(ex_rf, "X1"),
single_variable(ex_svm, "X1"),
single_variable(ex_lm, "X1"),
single_variable(ex_nn, "X1"),
single_variable(ex_rms, "X1"),
single_variable(ex_tr, "X1")) +
ggtitle("Responses for X1. Truth: y ~ (2*x1 - 1)^2")

from dalex.

mstaniak avatar mstaniak commented on May 22, 2024

Try this code:

ex_nn<-explain(model_nn,
               data = df[, -1],
               y = df[, 1],
               predict_function = function(x, y) compute(x, y)$net.result)

Is this okay?

from dalex.

OperaMagistris avatar OperaMagistris commented on May 22, 2024

Problem solved... my last post was fucking stupid! Everything works great!

from dalex.

mstaniak avatar mstaniak commented on May 22, 2024

So, what was the problem?

from dalex.

OperaMagistris avatar OperaMagistris commented on May 22, 2024

The code you give me made the trick. I was just biased by the result! Stupid human brain!

from dalex.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.