Skip to content
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

Solved error in the Random Forest Model for ( code/shiny/004-iris-predictor/model.R ) #8

Open
jzambrano-xyz opened this issue Apr 7, 2021 · 0 comments

Comments

@jzambrano-xyz
Copy link

@dataprofessor
If the code is run as is, it will display an error when building the Random Forest Model:

"Error in y - ymean : non-numeric argument to binary operator
In addition: Warning messages:..
."

That is because the "Species" column in the TrainSet is passed as char

Therefore, the model cannot be created and the app can't be run.

To solve it, we just need to pass the "Species" column to the TrainSet as factor after line 24:

TrainSet <- read.csv("training.csv", header = TRUE)
str(TrainSet)
#Since here "Species" is a char column,
#we convert it to a factor
TrainSet[,"Species"] <- as.factor(TrainSet[,"Species"])
TrainSet <- TrainSet[,-1]
str(TrainSet)
#Now "Species" is a factor with three levels ;)

This will keep the Sepal and Petal Length and Width as num, but turn the Species into a 3 - level factor.

Thanks for all of your lessons!
jzambrano-xyz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant