Comments (3)
Hmmmm...when I run the following I reproduce the left plot in Figure 4.12. If you run this code in a fresh R session do you still get that error?
# packages required
library(ranger)
library(rsample)
library(pdp)
# data
attrition <- rsample::attrition %>%
mutate_if(is.ordered, factor, ordered = FALSE) %>%
mutate(Attrition = relevel(Attrition, ref = "Yes"))
# Create training and testing sets
set.seed(123)
split <- initial_split(attrition, prop = .8, strata = "Attrition")
attrit_train <- training(split)
attrit_test <- testing(split)
# probability model
m3_ranger_prob <- ranger(
formula = Attrition ~ .,
data = attrit_train,
num.trees = 250,
mtry = 25,
respect.unordered.factors = 'order',
verbose = FALSE,
seed = 123,
min.node.size = 1,
sample.fraction = .80,
probability = TRUE,
importance = 'impurity'
)
# custom ICE prediction function
custom_pred <- function(object, newdata) {
pred <- predict(object, newdata)
avg <- pred$predictions[, 1]
return(avg)
}
# compute and plot ICE curves
m3_ranger_prob %>%
partial(pred.var = "OverTime", ice = TRUE, center = TRUE, pred.fun = custom_pred, train = attrit_train) %>%
autoplot(rug = TRUE, train = attrit_train, alpha = 0.2)
from homlr.
My bad, sorry! Although, I suggest changing the # description and maybe function names..;)
I just assumed it was the same function since both the description and function names were the same.
# custom prediction function
custom_pred <- function(object, newdata) {
pred <- predict(object, newdata)
avg <- mean(pred$predictions[, 1])
return(avg)
}
# custom prediction function
custom_pred <- function(object, newdata) {
pred <- predict(object, newdata)
avg <- pred$predictions[, 1]
return(avg)
}
from homlr.
Good call out; I can see how that will likely confuse most readers. I'll update the functions to be more unique. Thanks.
from homlr.
Related Issues (20)
- Chapter 8 - KNN - Notebook - index selection is offset
- query about the "z" in the fastshap algorithm (7) HOT 1
- what is the meaning of "respect.unordered.factors = "order"? HOT 4
- Possible typo in Chapter 6 section 6.7 Final thoughts
- not found "inputs_currupted_gaussian" in the book "Hands-on machine learning with R" in page 391 HOT 2
- IF there was a small mistake parameter reference at the page 383 HOT 1
- Principal Component Analysis code error HOT 1
- the code at the page 411 cannot run
- h2o free to use HOT 1
- Figure 5.3 shows interaction model instead of main effect model
- Figure 5.7
- [Not reproducible] AmesHousing::make_ames doesn't show entire data cleaning process HOT 1
- Python port of recipes in the book
- `attrition` dataset no longer in `rsample` package
- step_<xxx>impute are deprecated
- lumping, prep, bake do not work as per example
- Unnecessary pattern in 3.8.3
- Section 4.5, broom::augment does not create .resid feature in the resulting data frame
- Section 5.7, Figure 5.7 graphs code
- Sec. 10.4, p. 107, bottom graph code
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from homlr.