Predict using randomForest package in R

前端 未结 2 1626
灰色年华
灰色年华 2021-01-24 07:19

How can I use result of randomForrest call in R to predict labels on some unlabled data (e.g. real world input to be classified)?
Code:

train_data = read.csv         


        
2条回答
  •  难免孤独
    2021-01-24 08:02

    Let me know if this is what you are getting at.

    You train your randomforest with your training data:

    # Training dataset
    train_data <- read.csv("train.csv")
    #Train randomForest
    forest_model <- randomForest(label ~ ., data=train_data)
    

    Now that the randomforest is trained, you want to give it new data so it can predict what the labels are.

    input_data$predictedlabel <- predict(forest_model, newdata=input_data)
    

    The above code adds a new column to your input_data showing the predicted label.

提交回复
热议问题