fit_lin <- lm(Sepal.Length ~ ., data = iris)
fl_lin <- flashlight(model = fit_lin, label = "lin", data = iris, y = "Sepal.Length")
# PDP by Species
plot(light_profile(fl_lin, v = "Petal.Length", by = "Species"))
# Average predicted
plot(light_profile(fl_lin, v = "Petal.Length", type = "pred"))
# Second model with non-linear Petal.Length effect
fit_nonlin <- lm(Sepal.Length ~ . + I(Petal.Length^2), data = iris)
fl_nonlin <- flashlight(
model = fit_nonlin, label = "nonlin", data = iris, y = "Sepal.Length"
)
fls <- multiflashlight(list(fl_lin, fl_nonlin))
# PDP by Species
plot(light_profile(fls, v = "Petal.Length", by = "Species"))
plot(light_profile(fls, v = "Petal.Length", by = "Species"), swap_dim = TRUE)
# Average residuals (calibration)
plot(light_profile(fls, v = "Petal.Length", type = "residual"))
Run the code above in your browser using DataLab