dataprofessor / rshiny_freecodecamp

48 stars 45 forks source link

Error :- Warning in randomForest.default(m, y, ...) : #4

Open sarrthac opened 1 year ago

sarrthac commented 1 year ago

Error message displayed -

Warning in randomForest.default(m, y, ...) : The response has five or fewer unique values. Are you sure you want to do regression? Warning in mean.default(y) : argument is not numeric or logical: returning NA Error in y - ymean : non-numeric argument to binary operator

Screenshot of error -

image

Where the Problem is -

read.csv no longer automatically converts characters to factors

Solution

Edit the line no.19 in the code which is

image model <- randomForest(play ~ ., data = weather, ntree = 500, mtry = 4, importance = TRUE)

to Correct one -

image model <- randomForest(as.factor(play)~., data = weather, ntree = 500, mtry = 4, importance = TRUE) This will fix the issue.

For further info please refer - https://blog.r-project.org/2020/02/16/stringsasfactors/

Tip form my side for beginners

If you are cloning this repo and using the file Play-Glof/app.R you may also come across some of errors like -

Error in library(data.table) : there is no package called ‘data.table’ Error in library(RCurl) : there is no package called ‘RCurl’ Error in library(randomForest) : there is no package called ‘randomForest’

Solution You need to install the library manually in your R-Studio environment as some libraries are not preinstalled. You can use the below command to install it. install.packages("randomForest") , install.packages("RCurl") , install.packages("data.table") This will fix the issue.