您可以使用 Python 随机森林包sklearn.ensemble,如下所示:
# Import the random forest package
from sklearn.ensemble import RandomForestClassifier
# create a random forest object with 100 trees
forest = RandomForestClassifier(n_estimators = 100)
predictors = [[0, 0], [1, 1]]
response = [0, 1]
# fit the model to the training data
forest = forest.fit(predictors, response)
# you can reuse the forest model you built to make predictions
# on other data sets
test_data = [[0, 1], [1, 0]]
output = forest.predict(test_data)
请注意,我在此处导入,但如果您想在回归模式下运行随机森林,RandomForestClassifier您也可以使用。RandomForestRegressor