Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This code doesn't print graph as expacted , how can I fix it ? See athachedset.seed ( 6 5 2 2 0 4 8 )

This code doesn't print graph as expacted , how can I fix it? See athachedset.seed(6522048)
library (randomForest)
# Root mean squared error
RMSE = function(pred, obs){
return(sqrt( sum((pred - obs)^2)/length(pred)))
}
# checking
train =c()
test =c()
trees =c()
for (i in seq(from=1, to =150, by=1)){
trees - c(trees, i)
model_rf7- randomForest(target age + sex + cp + trestbps + chol + restecg + exang + ca, data = heart_data, ntree = i)
pred - predict(model_rf7, newdata=train.data, type='response')
rmse_train - RMSE (pred, train.data$target)
train - c(train, rmse_train)
pred - predict(model_rf7, newdata=test.data, type='response')
rmse_test - RMSE (pred, test.data$target)
test - c(test, rmse_test)
}
plot(trees, train,type ="l",ylim=c(20,130), col = "red", xlab = "Number of Trees", ylab = "Root Mean Squared Error")
lines(test, type ="l", col = "blue")
legend('topright', legend ('training set','testing set'), col =c(red,blue),lwd=2
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

How has your firm responded to these trends?

Answered: 1 week ago