-
-
Notifications
You must be signed in to change notification settings - Fork 166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
single_variable with neuralnet( ) model #26
Comments
Try this code:
Is this okay? |
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) f <- function(x1, x2, x3, x4, x5) { library(randomForest) df <- data.frame(y, X1, X2, X3, X4, X5) model_rf<-randomForest(y~., df) dd <- datadist(df) ex_rf<-explain(model_rf) library(ggplot2) |
Problem solved... my last post was fucking stupid! Everything works great! |
So, what was the problem? |
The code you give me made the trick. I was just biased by the result! Stupid human brain! |
The package is great for teaching purposes. Sadly it seems (a priori!) that the function single_variable() doesn't work with neuralnet( ) model.
Here a reproducible example taken from the vignette adding a neuralnet( ) model:
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)
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")
The text was updated successfully, but these errors were encountered: