if (FALSE) {
#Regression example
#generate Friedman data
set.seed(11)
n = 200
p = 5
X = data.frame(matrix(runif(n * p), ncol = p))
y = 10 * sin(pi* X[ ,1] * X[,2]) +20 * (X[,3] -.5)^2 + 10 * X[ ,4] + 5 * X[,5] + rnorm(n)
##build BART regression model
bart_machine = bartMachine(X, y)
#partial dependence plot for quadratic term
pd_plot(bart_machine, "X3")
#Classification example
#get data and only use 2 factors
data(iris)
iris2 = iris[51:150,]
iris2$Species = factor(iris2$Species)
#build BART classification model
bart_machine = bartMachine(iris2[ ,1:4], iris2$Species)
#partial dependence plot
pd_plot(bart_machine, "Petal.Width")
}
Run the code above in your browser using DataLab