A random forest is a meta estimator that fits a number of decision tree classifiers on various sub-samples of the dataset and use averaging to improve the predictive accuracy and control over-fitting.
A simple usage example:
Import:
from sklearn.ensemble import RandomForestClassifier
Define train data and target data:
train = [[1,2,3],[2,5,1],[2,1,7]]
target = [0,1,0]
The values in target
represent the label you want to predict.
Initiate a RandomForest object and perform learn (fit):
rf = RandomForestClassifier(n_estimators=100)
rf.fit(train, target)
Predict:
test = [2,2,3]
predicted = rf.predict(test)