r predict type = prob

# Step 1: Load the required library
library(randomForest)

# Step 2: Load or create your dataset
# Replace 'your_dataset.csv' with the actual file path or dataset name
your_data <- read.csv('your_dataset.csv')

# Step 3: Split the dataset into training and testing sets
set.seed(123)  # Set seed for reproducibility
train_indices <- sample(1:nrow(your_data), 0.7 * nrow(your_data))
train_data <- your_data[train_indices, ]
test_data <- your_data[-train_indices, ]

# Step 4: Create a random forest model
# Replace 'target_variable' with the name of your target variable
rf_model <- randomForest(target_variable ~ ., data = train_data)

# Step 5: Make predictions on the test set
# Replace 'target_variable' with the name of your target variable
predictions <- predict(rf_model, test_data, type = 'response', predict.all = TRUE)

# Step 6: Extract class probabilities
# Replace 'class_of_interest' with the specific class for which you want probabilities
class_probabilities <- predictions$individual[, "class_of_interest"]

# Step 7: View the predicted class probabilities
print(class_probabilities)